In website content management, we often need to balance the efficiency of content writing with the final presentation effect.Markdown with its concise syntax greatly enhances the speed of content creation.But the question that follows is: do we always want the content to be automatically converted to HTML when it enters the template?Or in certain specific scenarios, we want to maintain the original Markdown format, or manually control the conversion process?

For AnQiCMS users, the control over converting Markdown content to HTML actually provides two levels of flexible mechanisms, allowing content managers to make fine adjustments according to their actual needs.

First-level control: global settings, unified management of content input and default rendering

AnQiCMS provides a global switch at the website level to determine whether to use the Markdown editor by default when editing content, which in turn affects its default rendering behavior on the front end.

To find this setting, you need to enter the AnQiCMS admin interface and navigate to『Global Settings』below『Content Settings』options. Here, you will find a named『Whether the Markdown editor is enabled』switch.

When this switch isenabledAt the same time, it means that when you are editing articles, pages, category descriptions, or tag content in the background, the system will provide a Markdown editor. At the same time, these contents entered through the Markdown editor are called in the front-end template (for example, througharchiveDetail/categoryDetailThe label getsContentThe field) is usuallyAutomatically parsed and rendered into HTML by the system.This is a very convenient feature for websites that want to use Markdown for content editing and display throughout the site, ensuring that the content appears automatically in rich HTML style to the user after publication, without any additional manual operation.

On the contrary, if this switch isturned offSo the background content editor interface will no longer provide a Markdown editor, but a conventional rich text editor. At this point, even if you manually input Markdown syntax, the system alsoIt will not default convert it to HTMLInstead, it will be treated as plain text output.

Second-level control: template tags, precise coverage and manual intervention

Even though there are global settings, in some more refined scenarios, we may want to override the global behavior or personalize specific content blocks. AnQiCMS does this through template tags in therenderParameters provide this powerful template-level control capability.

When you usearchiveDetail(Document Details),categoryDetail(Category Details),pageDetailOr (Single Page Details)tagDetailTags like (Label Details) etc. call itsContentWhen the field is added, you can also add extrarenderParameters to manually specify whether to perform Markdown to HTML conversion.

  1. Force Markdown conversion (render=true)If you want to force a specific content block (such as the main text of a document) to convert Markdown content to HTML, even if the global Markdown editor is turned off, you can explicitly specify itrender=trueFor example, calling the Markdown conversion of the document content:

    {# 强制进行Markdown转HTML转换 #}
    <div>文档内容:{% archiveDetail archiveContent with name="Content" render=true %}{{archiveContent|safe}}</div>
    

    Pay special attention here|safeThe use of filters. Since the AnQiCMS template defaults to escaping output content to prevent potential XSS attacks, you must use it in conjunction with Markdown converted HTML content when you want to display it.|safefilter.|safeIt tells the template engine that this content is safe HTML, which does not need to be escaped again, so that it can be rendered correctly as HTML tags rather than displayed&lt;p&gt;such encoding.

  2. Prevent Markdown conversion (render=false)On the contrary, if you want to prevent the system from automatically converting Markdown to HTML and keep the original Markdown text format, even if the global Markdown editor is enabled in the background, you can also setrender=falseFor example, calling the original Markdown text of the category description:

    {# 不进行Markdown转换,显示原始Markdown文本 #}
    <div>分类描述:{% categoryDetail categoryDescription with name="Content" render=false %}{{categoryDescription}}</div>
    

    In this case, since the output is the original text, it is usually not necessary|safeFilter (unless you want to preserve and display HTML fragments in Markdown syntax).

Summary

AnQiCMS provides a comprehensive and flexible control mechanism for automatically converting Markdown content to HTML. You can access the backend's『Global Settings』Unified management of the website's default behavior, can also be achieved through template tags inrenderThe parameter makes detailed intervention on specific content.This double control ensures the convenience of content editing, while also providing flexibility for front-end display, allowing content to be presented in the most ideal format for different scenarios.Understand and make good use of these features, and it will help you better handle the content management capabilities of AnQiCMS.


Frequently Asked Questions (FAQ)

  1. Why didn't my Markdown content convert to HTML but was displayed as raw text instead?

    • First, please check the AnQiCMS background『Global Settings』below『Content Settings』,『Whether the Markdown editor is enabled』Is the switchIn the on state. If this switch is turned off, the system will not default to convert Markdown.
    • If the global setting is enabled, then check if you accidentally added the content field when calling it in the templaterender=falseThe parameter will force the Markdown conversion to be blocked.
  2. Why doesn't the HTML tag work after converting my Markdown content to HTML and instead shows&lt;p&gt;entity encoding?

    • This is usually because you didn't use a filter when outputting the template|safeThe HTML content converted from Markdown needs to be processed through|safeThe filter explicitly informs the AnQiCMS template engine that this content is safe HTML, which does not need to be escaped again in order to correctly parse and display HTML tags. For example:{{ archiveContent|safe }}.
  3. render=trueWhat is the difference between the parameter and enabling Markdown editor in the background?

    • Enabling Markdown editor in the backgroundIs a global setting that affects: 1) The type of the backend content editor (Markdown editor or rich text editor); 2) Whether the system defaults to automatically convert Markdown to HTML when the content field is called in the template.
    • render=trueParameterIs a mandatory instruction at the template level.It allows you to force Markdown to HTML conversion in the output of specific content fields, regardless of global settings.render=trueForce it to be interpreted as Markdown and converted to HTML.