When managing content in Anqi CMS, we often encounter the issue of multi-line text display on article detail pages. Traditionally, to ensure that content is displayed correctly segmented, many users may be accustomed to manually adding<p>Tags. However, AnQi CMS provides a more intelligent and efficient way, allowing your text content to be automatically segmented, greatly enhancing the convenience and maintainability of content creation.

To achieve automatic paragraph splitting of multi-line text content on the article detail page of the Anqi CMS, the core lies in utilizing its built-in Markdown editor and flexible template rendering mechanism.

Core Mechanism: Smart Handling of Markdown

The strength of AnQi CMS lies in its integrated Markdown editor.Markdown is a lightweight markup language that allows you to write documents using a simple plain-text format, and then convert it into structured HTML.Two consecutive newline characters (i.e., one blank line) represent a new paragraphThe Markdown will be automatically converted to HTML when rendering.<p>Tags, for automatic paragraph segmentation.

Enable Markdown editor: Start the journey of automatic paragraph segmentation.

Firstly, you need to make sure that the Markdown editor is enabled in the Anqi CMS backend.

  1. Log in to your Anqi CMS backend management interface.
  2. Navigate to the submenu under the “Content Settings" option.
  3. In the content settings page, find andEnable Markdown Editor.

Once enabled, when you publish or edit articles, the document content area will switch to Markdown editing mode.Here, you just need to follow the syntax conventions of Markdown, using blank lines to separate paragraphs, and the system will intelligently handle these section information when saved.

Content rendering in the template: Ensure correct display

Even if the backend content has been saved as plain text with paragraph logic through a Markdown editor, the frontend template still needs to render it correctly as HTML. In the template files of Anqi CMS, especially when usingarchiveDetailorpageDetailWhen calling tags to article or page content, you need to make sure that the content is correctly processed.

For example, in your article detail page template (usually,{模型table}/detail.htmlIn the brackets, you might see code like this to display the article content:

<div>
    {%- archiveDetail articleContent with name="Content" %}
    {{articleContent|safe}}
</div>

Or for a single page:

<div>
    {% pageDetail pageContent with name="Content" %}{{pageContent|safe}}
</div>

It is important to note here:{{articleContent|safe}}or{{pageContent|safe}}of|safeFilter.safeThe function of the filter is to inform the template engine that this part of the content is safe HTML and does not need to be escaped. When the Markdown editor is enabled, the system has already converted the Markdown-formatted text to include<p>The HTML code of the tag. If not|safefilters, these<p>the tag may be treated as plain text and outputted as is, leading to the content still not being segmented. Therefore,it is essential to use|safeFilterEnsure that the HTML code can be correctly parsed and displayed by the browser.

Flexible handling for specific scenarios: clever use of filters

Not all multiline text content comes from Markdown editors, or you might have some old content that has not been processed by Markdown. The template system of Anqi CMS also provides flexible filters to deal with these situations:

  • Processing automatic segmentation of plain text:linebreaksFilterIf you have a plain text field (such as a multi-line text custom field, or content entered before Markdown editing was enabled), where paragraphs are only separated by simple newline characters (return key), you can uselinebreaksConvert it to HTML segments using a filter.

    {# 假设myPlainTextContent是一个包含简单换行符的纯文本变量 #}
    <div>
        {{ myPlainTextContent|linebreaks|safe }}
    </div>
    

    linebreaksThe filter will convert single newline characters in the text to<br/>And two consecutive newline characters will be wrapped in<p>Tags are perfect for formatting simple plain text as HTML paragraphs. If you only need to replace<br/>,"linebreaksbrfilters, but for paragraph segmentation,linebreaksIt is the more suitable choice.

  • Render Markdown content in the custom field:renderFilterIf your content model defines a custom field of type "Multi-line text" and you want to use Markdown syntax for automatic paragraphing in this field as well, you can userenderFilter.

    For example, if your custom field name isintroductionand you want the Markdown content you write to be automatically segmented and rendered:

    {% archiveDetail introduction with name="introduction" %}
    <div>
        {{introduction|render|safe}}
    </div>
    

    Here,|renderThe filter will be responsible forintroductionConvert the Markdown text in the field to HTML, then|safethe filter ensures that this HTML is displayed correctly.

Summary

By enabling the Markdown editor of the Anqi CMS, combined with the template that containsContentfield usage|safefilters, and applying to plain text fields when necessary|linebreaks|safeOr apply to custom Markdown fields|render|safe, You can easily achieve automatic paragraph splitting of multi-line text content on article detail pages, and say goodbye to manual addition<p>The cumbersome work of labeling makes content creation more smooth and efficient.


Common Questions (FAQ)

  1. I enabled the Markdown editor, but the content on the article detail page is still crowded together without paragraphs, what's going on?This is usually because your template is missing|safeFilter. When Markdown content is converted to HTML (including tags) by the system, if the template does not use<p>the tag|safeThese HTML tags will be escaped into plain text, causing the page to appear without paragraphs. Please check your template code to ensure that content is output using{{您的内容变量|safe}}format.

  2. My certain multi-line text custom field also wants to be automatically segmented, how should I operate?If the content of the custom field is plain text and segmented by simple line breaks, you can use|linebreaks|safeFilter processing. For example:{{ archive.MyCustomField|linebreaks|safe }}. If the content of this custom field is written in Markdown syntax, it should use:|render|safefilter, such as:{{ archive.MyCustomField|render|safe }}This will convert Markdown to HTML.

  3. If I don't want to use the Markdown editor, can multiline text still be automatically segmented?It can. If your content is entered through a rich text editor (non-Markdown mode), it usually already contains HTML tags (such as<p>),no additional processing is required, only ensure that the template uses|safeFilter. If your content is plain text (such as copied and pasted from outside, or some legacy content), and is only segmented by simple line breaks, then in the template use|linebreaks|safeFilter it to include<p>the HTML tags for automatic segmentation display.