Convert multiple lines of text to html tags by newline characters

How to convert multiple lines of text into html tags in Anqi CMS template?

linebreaksFilters can convert multiple lines of text into html tags according to line breaks. Each line starts and ends with<p>and</p>If there is a blank line in the middle, use it<br/>.

Can also be usedlinebreaksbrto process it. andlinebreaksThe difference is,linebreaksbrJust replace the newline with<br/>, and do not add p tags at the beginning and end.

Can also be usedlinenumbersTo mark each line of multiple lines of text, the symbol starts from 1. like1..

How to use

linebreaksHow to use filters:

{{ obj|linebreaks }}

linebreaksbrHow to use filters:

{{ obj|linebreaksbr }}

linenumbersHow to use filters:

{{ obj|linenumbers }}

For example, processing stringsthis is a text\nwith a new line in it, you can write it like this:

{{ "this is a text\nwith a new line in it"|linebreaks }}
# Show results
<p>this is a text<br />with a new line in it</p>

Sample Demo

linebreaksFilter

{{ ""|linebreaks|safe }}
{{ simple.newline_text|linebreaks|safe }}
{{ simple.long_text|linebreaks|safe }}
{{ "john doe"|linebreaks|safe }}
# 显示结果

<p>this is a text<br />with a new line in it</p>
<p>This is a simple text.</p><p>This too, as a paragraph.<br />Right?</p><p>Yep!</p>
<p>john doe</p>

linebreaksbrFilter

{{ ""|linebreaksbr|safe }}
{{ simple.newline_text|linebreaksbr|safe }}
{{ simple.long_text|linebreaksbr|safe }}
{{ "john doe"|linebreaksbr|safe }}
# 显示结果

this is a text<br />with a new line in it
This is a simple text.</p><p>This too, as a paragraph.<br />Right?</p><p>Yep!
john doe

linenumbersFilter

{{ simple.long_text|linebreaksbr }}
# 显示结果
1. This is a simple text.
2. This too, as a paragraph.
3. 
4. Right?
5. Yep!