且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

将新行/n 转换为有角度的换行符

更新时间:2023-12-03 21:05:40

这并不能代替它,但是可以使用 CSS 属性 white-space: pre-line; 来渲染\n在浏览器中:https://developer.mozilla.org/en-US/docs/Web/CSS/white-space

div {空白:前行;}

Foo酒吧巴兹富酒吧巴兹

I have a string which contain new line character /n. Trying to display

the string. Instead of taking the /n as new line, it displays '/n' as text.

   $scope.myOutput = " Hello /n"

    {{ myOutput | textFormat }}

Required -> Hello (on html page)

Tried :

 app.filter('textFormat', function() {
    return function(x) {
      return x.replace(/\\n/g, '<br/>');
   }

Tried css styles like white-space: pre;

This does not replace it, but you can use the CSS attribute white-space: pre-line; to render the \n in the browser: https://developer.mozilla.org/en-US/docs/Web/CSS/white-space

div {
  white-space: pre-line;
}

<div>Foo
   Bar
       Baz     Foo
     Bar
 


     
  Baz
</div>