LoginSignup
2
1

More than 5 years have passed since last update.

pug (jade) で改行文字を br にする

Posted at
- var text = 'hoge\r\nfuga\r<script>alert("escape!")</script>\nyeah!' // 入力値

- var lines = text.split(/\r\n|\r|\n/)
- var lastLine = lines.pop()

.text
 each line in lines 
   = line
   br
 = lastLine

結果↓

<div class="text">hoge<br/>fuga<br/>&lt;script&gt;alert(&quot;escape!&quot;)&lt;/script&gt;<br/>yeah!
</div>

うーん、エスケープも考慮しながら書くとこんな感じかなぁ。これを mixin 登録か。もっと良いやり方ないですか?

2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1