CSS 为 JSON 数据添加两行字符



我有一个 json 数据,其中包含存在的行字符,但是当我在 html 上呈现它时,它确实添加了具有style="white-space: pre-line"属性的新行字符,而是我想添加 2 个新行字符

我的 json 数据

[{"id":1,"title":"Israel’s desert city of Beersheba is turning into a cybertech oasis","description":"morphing into a tech oasis.rnThe military’s massive relocation of its prestigious technology units.rnBeersheba has all of the ingredients of a vibrant security technology ecosystem, rn“All in all, projections are that 20,000-30,000 rnThe commercial sector has teamed up  cyber attacks.","pub_date":"2016-03-20T10:48:19.394643Z"},{"id":2,"title":"These are testing times: mavericks vs. ice people","description":"One of my earliest engineering jobs, before I fled hardware in favor of the (relative). rnThe practice of engineering soon teaches one that, .rnSo what do we do? We practice defense in depth. We follow the robustness principle. We “always code as rn…Yeah, well, that’s the idea. For my day job at HappyFunCorp I do a lot of interviews, and almost every junior develope.rnI don’t necessarily blame them. You can make  go.","pub_date":"2016-03-20T10:50:07.965930Z"}]

更清楚的是,json 中的描述是这样的

morphing into a tech oasis.rnThe military’s massive relocation of its prestigious technology units.rnBeersheba has all of the ingredients of a vibrant security technology ecosystem, rn“All in all, projections are that 20,000-30,000 rnThe commercial sector has teamed up  cyber attacks.

如我们所见,存在\r,所以在这里我想再次插入新行以呈现2个新的行字符

我的控制器

<div class="blog-post">
 <p class="blog-post-title">{{ post.title }}</p>
 <p class="blog-post-meta"><i class="fa fa-clock-o">&nbsp {{ post.pub_date|date  }}</i> </p>
 <span style="white-space: pre-line">{{ post.description }}</span>

<小时 />

应该怎么做才能使用 2 个新的行字符来渲染输出{{ post.description }}

我期望的输出是这样的

morphing into a tech oasis.
The military’s massive relocation of its prestigious technology units.
Beersheba has all of the ingredients of a vibrant security technology ecosystem, 
“All in all, projections are that 20,000-30,000 
The commercial sector has teamed up  cyber attacks.

提前致谢

通过正则表达式从控制器中删除 JSON 中的所有/r/n:

 post.description.replace(/(?:\[rn]|[rn]+)+/g, "")

最新更新