admin管理员组文章数量:1392002
I am using Pug with Nodemailer in a NodeJS server to handle email templates.
In my case I have the following object in the locals
object
{
from: '[email protected]',
message: 'a\nb\nc\nd\ne',
}
Now in the Pug file I have the following line
p #{message}
The problem is that in the email I don't get the text with new lines.
The message filed ignores the \n
and puts everything on the same line a b c d e
I need to get the text in the page with the new lines as it is in the object.
a
b
c
d
e
What would be the solution for this issue?
I am using Pug with Nodemailer in a NodeJS server to handle email templates.
In my case I have the following object in the locals
object
{
from: '[email protected]',
message: 'a\nb\nc\nd\ne',
}
Now in the Pug file I have the following line
p #{message}
The problem is that in the email I don't get the text with new lines.
The message filed ignores the \n
and puts everything on the same line a b c d e
I need to get the text in the page with the new lines as it is in the object.
a
b
c
d
e
What would be the solution for this issue?
Share Improve this question edited Dec 6, 2022 at 16:29 Sean 8,2634 gold badges26 silver badges53 bronze badges asked Aug 6, 2019 at 14:09 SabbinSabbin 2,4652 gold badges21 silver badges37 bronze badges 1-
2
You're creating HTML, which ignores
\n
. You need to use<br>
instead. Or use<pre>
instead of<p>
. Or use white-space – user5734311 Commented Aug 6, 2019 at 14:10
2 Answers
Reset to default 5As far as I know, the <p>
tag ignores preformatting, maybe try using <pre>
instead?
pre #{message}
If you want to use a <p>
for each paragraph instead of a <pre>
you can convert each newline into a new paragraph in Pug:
section
each line in message.split('\n')
p #{line}
This will render:
<section>
<p>a</p>
<p>b</p>
<p>c</p>
<p>d</p>
<p>e</p>
</section>
This assumes a
, b
, c
, etc. in your example are actually blocks of text that you've shortened to create a quick example.
本文标签: javascriptInterpolate new line from string in PugStack Overflow
版权声明:本文标题:javascript - Interpolate new line from string in Pug - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744764658a2623966.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论