Right now it just adds
\r\n\r\n
I'm trying to figure out how to convert
\r \n to <p> tags
The HTML gets posted to the DB via XHR, and post in firebug shows it like this:
html:
<html><head>\r\n<meta http-equiv=Content-Type content=text/html; charset=utf-8>\r\n</head>\r\n<body>\r\n<pre style=word-wrap:break-word; font-size:10.0pt; font-family:Tahoma; color:black>YADA YADA YADAYADA YADA YADAYADA YADA YADAYADA YADA YADA!\n\n YADA YADA YADAYADA YADA YADAYADA YADA YADAYADA YADA YADA.\n\nYADA YADA YADA\n\n< via mobile device >\n\nYADA YADA YADA <[email protected]> wrote:\n\n</pre>\r\n<div>\r\n<table cellpadding=0 cellspacing=0 border=0 width=700 style=padding:0;>\r\n<tbody>\r\n<tr>\r\n<td colspan=2 style=color:#000000;font-size:11px;font-family:'lucida grande', tahoma, verdana, arial, sans-serif valign=top>\r\n<div style=width:100%;font-size:12px;font-family:Helvetica;line-height:18px;>..... and it keeps going.
But when I use simple_format:
body = simple_format(@html)
I get this:
<p>\r\n\r\n\r\n\r\n<pre>YADA YADA YADAYAD........
Why isn't simple_format getting rid of the \r and \n and using paragraphs?
Thank you for your time.
You might be better off doing a string replace first:
@html.gsub!(/\r\n?/, "\n"); body = simple_format(@html)
This because simple_format only works on \n and \n\n, not \r\n:
From the API:
Returns text transformed into HTML using simple formatting rules. Two or more consecutive newlines(\n\n) are considered as a paragraph and wrapped in
tags. One newline (\n) is considered as a linebreak and a
tag is appended. This method does not remove the newlines from the text.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With