When we manage content in the safe CMS,ContentThe field is undoubtedly the core of our daily operations.For many content creators, the formatting of text is the key to expressing ideas.The company provides traditional rich text editors and more modern Markdown editors, which handle content in different ways.Contentafter the field is enabled with the Markdown editor, we commonly uselinebreakswill the filter still take effect?

To understand this, we first need to review.linebreaksThe basic functions of filters and Markdown editors.

linebreaksFilters: an assistant for formatting plain text.

In the template system of AnQi CMS,linebreaksFilter is a very practical tool, it is mainly used to process line breaks in plain text content. Its function is to convert common line breaks in the text.\n)Convert to HTML paragraph tags<p>)and newline tags<br/>)。In particular,linebreakswill convert a single newline character to<br/>,while wrapping text between two or more consecutive newline characters in<p>the tag.

For example, if you have a plain text like this:

第一行文字。
第二行文字。

第三行文字。
第四行文字。

AfterlinebreaksAfter filtering, it will become:

<p>第一行文字。<br />第二行文字。</p>
<p>第三行文字。<br />第四行文字。</p>

This filter is very effective for fields that contain only plain text but also want to display good paragraph structure on the web page.

Markdown editor: A powerful tool for structuring content

Markdown editor is a completely different content processing mechanism.It allows users to write structured and formatted content using a concise plain text syntax, such as headings, lists, links, images, code blocks, and emphasized text.When you use the Markdown editor in the background to write content and save it, the security CMS will automatically parse the Markdown syntax and convert it to the corresponding HTML structure when displaying these contents.

For example, you type in the Markdown editor:

# 这是一个标题

- 列表项1
- 列表项2

**粗体文字**

On the front end, it renders as:

<h1>这是一个标题</h1>
<ul>
  <li>列表项1</li>
  <li>列表项2</li>
</ul>
<p><strong>粗体文字</strong></p>

It is obvious that the Markdown editor is designed to provide a more advanced and semantic way of structuring content.

After the Markdown editor is turned on,linebreakswhat will be its fate?

Now back to the core issue: whenContentAfter the field is enabled with Markdown editor,linebreakswill the filter still take effect?

The answer is:In most cases, it will not take effect in the way you expect, and it is usually not necessary for you to use it manually.

This is because, when the Markdown editor is enabled, you writeContentThe content of the field is initially in Markdown format. AnQi CMS will handle and output this content to the front-end page whenautoParse Markdown text and convert it to HTML.In other words, when the content arrives at the template and is rendered, it is already an HTML string, not raw plain text and newline characters.

linebreaksThe filter is designed to handle the 'original' newline characters in plain text. Once Markdown content is converted to HTML, all paragraphs, line breaks, lists, etc. have explicit HTML tags (such as<p>,<ul>,<li>,<br/>using the term “auto” to define their structure. At this point, if you apply a string containing HTML tagslinebreaksFilter, it will try to find and convert newlines within these HTML tags, which is likely to lead to unexpected results, even破坏原有的HTML结构,因为它不是为处理HTML而设计的。

From the documentation of AnQi CMS, we can find clear evidence that:ContentField will be automatically converted to html when the Markdown editor is enabled. This means that when the Markdown editor is enabled, you fromarchiveDetailorpageDetailis obtained from the labelContentField, its valueThe default has already been converted from Markdown to HTML.

How to correctly use and understand:

  1. Trust Markdown's rendering ability:If you have enabled the Markdown editor, you should make full use of the syntax of Markdown itself to control the layout of the content, including paragraphs, lists, and line breaks.Markdown itself has its own way of defining paragraphs and enforcing line breaks (by adding two spaces at the end of a line), which will be correctly converted to HTML.
  2. renderParameter purpose:AnQi CMS providesrenderParameter, allows you to manually control whether toContentFields are rendered in Markdown. For example:{% archiveDetail archiveContent with name="Content" render=false %}. If you explicitly setrender=falseso thatContentThe field will output the original Markdown text (in this context, it is equivalent to plain text). At this point, theoretically, you can applylinebreaksFilter, but this will give up all the advanced formatting capabilities brought by Markdown, only performing simple line breaks, which is usually not the purpose of using a Markdown editor.
  3. Filter application scenarios: linebreaksThe filter still applies to fields that store plain text and have not been processed with Markdown, or when you actually need to perform a simple newline-to-HTML conversion on specific plain text segments. But for those who have enabled the Markdown editor,ContentAs for the field, it is usually not necessary and not recommended to use.

In short, when you turn on the Markdown editor in AnQi CMS, please rest assured to entrust the content formatting task to Markdown itself.linebreaksFilters will no longer beContentThe main formatting tool for fields, as the content has already been processed into HTML in a more advanced form.


Common Questions (FAQ)

Q1: Do I still need to use it manually in Markdown content?<br/>Is it to force line breaks? A1:Generally not required.In Markdown, if you need to force a line break without starting a new paragraph, you can add two or more spaces at the end of the line and then press Enter.<br/>Label. If it is just a return or line break, Markdown usually treats it as a continuous text stream within the same paragraph, unless there is a blank line (which will start a new paragraph).

Q2: If my content has both Markdown formatting and plain text,linebreakshow should it be handled? A2:when the Markdown editor is enabled,ContentThe entire content of the field will be treated as Markdown text for parsing.Even if the content you enter looks like plain text (without using any Markdown syntax), Anqi CMS will try to parse it as Markdown.linebreaksThis has lost its main function of handling plain text line breaks. If your "plain text" part contains text you wantlinebreaksProcessed newline characters, but do not want them to be additionally formatted by Markdown. You may need to reconsider whether to use a Markdown editor, or store this part of the content in another field that is not processed by Markdown.

Q3:archiveDetailandpageDetailthe tag inrender=falseWhat is the use of the parameter, andlinebreaksWhat is the relationship? A3: render=falseThe purpose of the parameter is to prevent security CMS fromContentConvert the Markdown text of the field to HTML, so that the original Markdown text is output directly.In this case, the output content will be plain text formatted as Markdown.linebreaksThe filter can take effect on this "unrendered" plain text content.Please note that this will give up all advanced formatting provided by Markdown, and only perform simple paragraph and line break processing.