【问题标题】:Format a big bunch of text格式化一大堆文本
【发布时间】:2022-08-23 11:32:42
【问题描述】:

我正在使用 API,其中一个响应是一大堆文本,我想让它更“可读” 比方说,数据是这样的:

In a bowl, mash the banana with a fork until it resembles a thick purée. Stir in the eggs, baking powder and vanilla.\\r\\nHeat a large non-stick frying pan or pancake pan over a medium heat and brush with half the oil. Using half the batter, spoon two pancakes into the pan, cook for 1-2 mins each side, then tip onto a plate. Repeat the process with the remaining oil and batter. Top the pancakes with the pecans and raspberries.

在 Angular 中有没有办法让它更像这样:

In a bowl, mash the banana with a fork until it resembles a thick purée.
Stir in the eggs, baking powder and vanilla.
Heat a large non-stick frying pan or pancake pan over a medium heat and brush with half the oil.
Using half the batter, spoon two pancakes into the pan, cook for 1-2 mins each side, then tip onto a plate.
Repeat the process with the remaining oil and batter.
Top the pancakes with the pecans and raspberries.

基本上,在每个点 ( . )

谢谢你们

  • 参考here
  • 请更清楚地表达您的问题。请说明确切的目标是什么,您遇到的问题以及到目前为止您尝试过的内容read more

标签: angular


【解决方案1】:

答案来自这个answer 请支持这个答案!

html

<div [innerHTML]="name | readable"></div>

javascript

import { DomSanitizer } from '@angular/platform-browser';
import { PipeTransform, Pipe } from '@angular/core';

@Pipe({ name: 'readable' })
export class ReadablePipe implements PipeTransform {
  constructor(private sanitized: DomSanitizer) {}
  transform(value) {
    const newValue = value.split('.').join('.<br/>');
    return this.sanitized.bypassSecurityTrustHtml(newValue);
  }
}

Stackblitz Demo

【讨论】:

    【解决方案2】:
    1. 一种可能的解决方案是获取字符串并根据每个点(。)将其拆分并添加一个“\n”

    2. 另一种使其更具可读性的可行方法是将文本放在容器内的&lt;p&gt; 标记中,并使用CSS 属性设置text-align: justify

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-04-11
      • 1970-01-01
      • 2021-06-23
      相关资源
      最近更新 更多