I am using <pre> tags to preserve long strings of text that include user-entered line breaks.
When the input into the original form was exactly:
Paragraph 1
Paragraph 2
Paragraph 3
…the pre returns:
Paragraph 1 Paragraph 2 Paragraph 3
In the database, the string is stored:
"Paragraph 1\r\n\r\nParagraph 2\r\n\r\nParagraph 3."
- Why is this happening?
- If the best way to get around this to simply strip out all leading spaces from every newline, how can I accomplish this so it happens across the entire site?
Edit: I’m using Ruby on Rails – what would be the code in that case? A particular problem I’m having is with a HAML page.
%pre
- unless condition.blank?
%br
- unless @user.show_notes == false
:preserve
#{@user.notes}
You’re probably indenting your code, eg (PHP example)
Notice the space before the opening
<?phptag?