admin管理员组文章数量:1023251
I have MySQL table with column PROJ_ABOUT which is type TEXT.
I inserted multiple rows into this column and now I am trying to diplay this entry in my Express.js app using ejs engine.
<h2>About project</h2>
<p><%= rows.PROJ_ABOUT %></p>
However, when the text is inserted into ejs file, all line breaks are lost.
**Instead of this:**
Line 1
Line 2
**I get this:**
Line1Line2
I tried getting around this by saving entry to database with <br />
instead of '\n'
but instead of getting line breaks I got text with br tags written as mon text.
**So i got this:**
Line1<br />Line2
Now, I saw the answers for PHP, but i am using Node.js with ejs templating engine and I am looking for a solution using JS.
I have MySQL table with column PROJ_ABOUT which is type TEXT.
I inserted multiple rows into this column and now I am trying to diplay this entry in my Express.js app using ejs engine.
<h2>About project</h2>
<p><%= rows.PROJ_ABOUT %></p>
However, when the text is inserted into ejs file, all line breaks are lost.
**Instead of this:**
Line 1
Line 2
**I get this:**
Line1Line2
I tried getting around this by saving entry to database with <br />
instead of '\n'
but instead of getting line breaks I got text with br tags written as mon text.
**So i got this:**
Line1<br />Line2
Now, I saw the answers for PHP, but i am using Node.js with ejs templating engine and I am looking for a solution using JS.
Share Improve this question asked Oct 12, 2016 at 20:55 Miha JamsekMiha Jamsek 1,2832 gold badges19 silver badges35 bronze badges3 Answers
Reset to default 3You need to use the proper EJS syntax for rendering unescaped HTML, otherwise you will get the escaped strings.
Short answer would be :
<!-- V You should use - instead of = -->
<p> <%- rows.PROJ_ABOUT %></p>
this will render your rows.PROJ_ABOUT
variable as unescaped HTML
Try this EJS tag <%- %>
instead of <%= %>
. The first EJS tag will not escape HTML.
So just wrap your text with <br>
to <%- rows.PROJ_ABOUT %>
To change line ends like \n
to <br>
in your text you can use nl2br package (on server-side).
use this
<p><%- rows.PROJ_ABOUT %></p>
I have MySQL table with column PROJ_ABOUT which is type TEXT.
I inserted multiple rows into this column and now I am trying to diplay this entry in my Express.js app using ejs engine.
<h2>About project</h2>
<p><%= rows.PROJ_ABOUT %></p>
However, when the text is inserted into ejs file, all line breaks are lost.
**Instead of this:**
Line 1
Line 2
**I get this:**
Line1Line2
I tried getting around this by saving entry to database with <br />
instead of '\n'
but instead of getting line breaks I got text with br tags written as mon text.
**So i got this:**
Line1<br />Line2
Now, I saw the answers for PHP, but i am using Node.js with ejs templating engine and I am looking for a solution using JS.
I have MySQL table with column PROJ_ABOUT which is type TEXT.
I inserted multiple rows into this column and now I am trying to diplay this entry in my Express.js app using ejs engine.
<h2>About project</h2>
<p><%= rows.PROJ_ABOUT %></p>
However, when the text is inserted into ejs file, all line breaks are lost.
**Instead of this:**
Line 1
Line 2
**I get this:**
Line1Line2
I tried getting around this by saving entry to database with <br />
instead of '\n'
but instead of getting line breaks I got text with br tags written as mon text.
**So i got this:**
Line1<br />Line2
Now, I saw the answers for PHP, but i am using Node.js with ejs templating engine and I am looking for a solution using JS.
Share Improve this question asked Oct 12, 2016 at 20:55 Miha JamsekMiha Jamsek 1,2832 gold badges19 silver badges35 bronze badges3 Answers
Reset to default 3You need to use the proper EJS syntax for rendering unescaped HTML, otherwise you will get the escaped strings.
Short answer would be :
<!-- V You should use - instead of = -->
<p> <%- rows.PROJ_ABOUT %></p>
this will render your rows.PROJ_ABOUT
variable as unescaped HTML
Try this EJS tag <%- %>
instead of <%= %>
. The first EJS tag will not escape HTML.
So just wrap your text with <br>
to <%- rows.PROJ_ABOUT %>
To change line ends like \n
to <br>
in your text you can use nl2br package (on server-side).
use this
<p><%- rows.PROJ_ABOUT %></p>
本文标签: javascriptDisplay line break from mysql text type to ejsStack Overflow
版权声明:本文标题:javascript - Display line break from mysql text type to ejs - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745541739a2155212.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论