Show "Carry Return" or \n\r correctly

12 views
Skip to first unread message

Eric Ponce

unread,
Apr 23, 2013, 2:05:52 PM4/23/13
to ged...@googlegroups.com
Hi!

When I write a text into a text area with a some new lines or carry returns (i dont know wich is the correct word to describe \n\r) like this:

Example text:
----------------------------------
Hello
This is my text

With some carry returns
--------END--------------------

and later I save it into a mongodb, this saves for example "Hello\n\rThis is my test\n\r\n\rWith....."
But later with EJS when i try to print, the text is printed in plain text: "Hello This is my text With some...."

How can I print correctly?

Thanks!

Miguel Madero

unread,
Apr 23, 2013, 2:14:28 PM4/23/13
to ged...@googlegroups.com
Can you copy and paste the template code? 


Miguel


--
The official community discussion group.
website: geddyjs.org, source: https://github.com/mde/geddy, group: https://groups.google.com/d/forum/geddyjs?hl=en
---
You received this message because you are subscribed to the Google Groups "GeddyJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email to geddyjs+u...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Miguel Madero

unread,
Apr 23, 2013, 2:15:06 PM4/23/13
to ged...@googlegroups.com
Even better, can you show me the generated HTML? 

Miguel

Eric Ponce

unread,
Apr 23, 2013, 2:37:55 PM4/23/13
to ged...@googlegroups.com
Mongo db -> "description" : "Text1\r\nText2\r\n\r\nText3"

Template -> <p><%= some.description; %></p> or <p><%- some.description; %></p>

HTML Generated:

<p>Text1
Text2

Text3</p>

But I see: Text1 Text2 Text3

Miguel Madero

unread,
Apr 23, 2013, 2:59:12 PM4/23/13
to ged...@googlegroups.com
Within a p tag you would need <br> tags. You could use a <pre> tag instead of <p> or you could use an html encoder to change \r\n to <br> and \t to four spaces (&nbsp;&nbsp;) 

I was looking and I'm not sure geddy has something for this. I would expect EJS to have something. 

Miguel

Eric Ponce

unread,
Apr 23, 2013, 6:16:31 PM4/23/13
to ged...@googlegroups.com
Is this valid? <p><%- some.description.replace(/\r\n/g,"<br>"); %></p>
Reply all
Reply to author
Forward
0 new messages