Detecting Newline Character On User's Input (web2py)
Solution 1:
Assuming you are referring to the subsequent display of the user input in a view, you could use a <pre>
tag: http://www.w3schools.com/tags/tag_pre.asp. However, you might need some CSS to get the font/styling you like (by default, the browser will use alternative styling with a fixed-width font).
You could also replace the newlines with <br>
tags:
{{=XML(record.body.replace('\n', '<br>'), sanitize=True, permitted_tags=['br/'])}}
Because the text now contains <br>
HTML tags, it is necessary to wrap it in XML()
to prevent web2py from escaping the HTML -- but you also want to sanitize the text and allow only<br>
tags to prevent malicious code from being executed.
Solution 2:
Use pre tag to display the content in which you want to detect newline character.
The HTML pre element (or HTML Preformatted Text) represents preformatted text. Text within this element is typically displayed in a non-proportional ("monospace") font exactly as it is laid out in the file. Whitespace inside this element is displayed as typed.
{{for post in comments:}}
<pre>{{=post.body}}</pre>
{{pass}}
Post a Comment for "Detecting Newline Character On User's Input (web2py)"