Convert multiple lines of text to html tags by newline characters

How to convert multi-line text to HTML tags in the Anqi CMS template?

linebreaksThe filter can convert multi-line text into HTML tags, with each line enclosed in HTML tags.<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 no p tags are added at the beginning and end.

Can also be usedlinenumbersTo number each line of multi-line text, the symbol starts from 1. For example,1..

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 }}
# 显示结果
<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!