When we manage content in Anqi CMSContentThe field is undoubtedly the core of our daily operations. For many content creators, the formatting of text is the key to expressing ideas.AnQi CMS provides traditional rich text editors and more modern Markdown editors, and they handle content in different ways.This raises a question that many people may be concerned about: whenContentAfter the field is enabled with the Markdown editor, we commonly uselinebreaksWill the filter still work?

To understand this, we first need to review the followinglinebreaksFilters and the basic functions of Markdown editor.

linebreaksFilter: A formatting assistant for plain text.

In the AnQi CMS template system,linebreaksA filter is a very practical tool, mainly used to process newline characters in plain text content. Its function is to convert the common newline characters in the text into...\nConvert to HTML paragraph tags<p>) and line break tags (<br/>In particular,linebreaksIt will convert a single newline character to<br/>While wrapping text between two or more consecutive newline characters in<p>in 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 only contain plain text but also want to present good paragraph structure on the web.

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, Anqi 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

**粗体文字**

It will render on the front end as:

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

It is obvious that the Markdown editor aims to provide a more advanced and semantically structured way of content structuring.

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

Now return to the core issue: whenContentAfter the field is opened with the Markdown editor,linebreaksWill the filter still work?

The answer is:In most cases, it will not work in the way you expect and usually does not require manual use.

This is because when the Markdown editor is enabled, you enterContentThe content of the field is initially in Markdown format. The AnQi CMS will process and output this content to the front-end page, andautomaticallyParse Markdown text and convert it to HTML.In other words, when the content reaches the template and is rendered, it is already an HTML string, rather than raw text and line breaks.

linebreaksThe filter is designed to handle the "raw" newline characters in plain text. Once Markdown content is converted to HTML, all paragraphs, line breaks, lists, etc. have clear HTML tags (such as<p>,<ul>,<li>,<br/>Define their structure by using the tag. At this point, if a string already contains HTML tagslinebreaksA filter that attempts to find newline characters within these HTML tags and convert them, which could lead to unexpected results and even damage the original HTML structure, as it is not designed for handling HTML.

From the document description of AnQi CMS, we can find clear evidence that: ContentThe field will automatically convert the content to html after enabling the Markdown editor. This means that when the Markdown editor is enabled, you will be able toarchiveDetailorpageDetailRetrieving from the labelContentField, its valueDefault has already been converted from Markdown to HTML.

How to use and understand correctly:

  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 a defined way of defining paragraphs and enforcing line breaks (by adding two spaces at the end of a line), which are correctly converted to HTML.
  2. renderThe parameter's function:AnQi CMS providesrenderThe parameter allows you to manually control whether toContentrender the field in Markdown. For example:{% archiveDetail archiveContent with name="Content" render=false %}. If you explicitly setrender=falsethenContentThe field will output the original Markdown text (in this context, it is equivalent to plain text). At this point, theoretically, you can apply this original Markdown text tolinebreaksFilter, but doing so 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. The application scenario of the filter: linebreaksThe filter still applies to those fields that store plain text and have not been processed with Markdown, or when you indeed need to perform a simple newline to HTML conversion on specific plain text fragments. But for those with the Markdown editor enabled,ContentIn terms of field, it is usually not necessary or recommended to use.

In short, when you turn on the Markdown editor in Anqi CMS, you can safely entrust the task of formatting content to Markdown itself.linebreaksThe filter will no longer beContentThe primary formatting tool, as the content has already been processed into HTML in a more advanced form.


Frequently Asked Questions (FAQ)

Q1: Do I still need to use Markdown manually in the content?<br/>Do you want to force a line break? 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.Markdown parser will convert it to<br/>Label. If it is just a simple return, Markdown will usually treat it as a text stream within the same paragraph, unless there is a blank line (which will start a new paragraph).

Q2: If my content includes both Markdown formatting and plain text,linebreaksHow will it be handled? A2:When the Markdown editor is turned on,ContentThe entire content of the field is 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.Once converted to HTML,linebreaksIt loses its main function of handling plain text line breaks. If the "plain text" part contains what you hopelinebreaksThe newline character is being processed, but it is not desired to be additionally formatted by Markdown. You may need to reconsider using a Markdown editor, or store this part of the content in another field that is not processed by Markdown.

Q3:archiveDetailandpageDetailin the labelrender=falseWhat is the use of the parameter, it andlinebreaksWhat is the relationship? A3: render=falseThe role of the parameter is to prevent the CMS from being safeContentThe Markdown text of the field is converted to HTML, so that the original Markdown text is directly output.In this case, the output will be a plain text formatted Markdown string.If you indeed need to apply simple line breaks to this original Markdown string, thenlinebreaksThe filter can take effect on this 'unrendered' plain text content.Please note that doing so will放弃了Markdown provided all advanced formatting, only simple paragraph and line break processing.