Convert multi-line text to HTML tags with newline characters

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

linebreaksThe filter can convert multi-line text into HTML tags by line breaks. The beginning and end of each line are wrapped, and there is a blank line in the middle.<p>And</p>wrapped, and the middle is processed with a blank line.<br/>.

It can also be used.linebreaksbrdifferent is,linebreaksdifferent is,linebreaksbrJust directly replace the newline characters.<br/>And do not add p tags at the beginning and end.

It can also be used.linenumbersTo number each line of the multi-line text, the symbol starts from 1. For example1..

Usage Instructions

linebreaksHow to use the filter:

{{ obj|linebreaks }}

linebreaksbrHow to use the filter:

{{ obj|linebreaksbr }}

linenumbersHow to use the filter:

{{ obj|linenumbers }}

like processing stringsthis is a text\nwith a new line in itthen it can be written 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>

Here is an example demonstration

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!