Can I control whether Markdown content in AnQiCMS templates is automatically converted to HTML?

Calendar 👁️ 73

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.

Related articles

How does AnQiCMS render Markdown formatted article content to HTML?

AnQiCMS boasts its efficient content management capabilities, is favored by users, especially in handling text content, providing flexible and diverse options.For users accustomed to using Markdown format, AnQiCMS also provides comprehensive support, able to seamlessly render Markdown formatted article content into user-friendly HTML pages.To understand how AnQiCMS achieves this transformation, we can explore from three aspects: content creation, system configuration, and template rendering.

2025-11-08

How to avoid AnQiCMS from destroying the tag structure when truncating HTML text?

In content management, in order to maintain the neatness and loading efficiency of the website page, we often need to truncate articles, product descriptions, or other long text content, and only display part of the abstract.However, if the content itself contains HTML tags, simple character truncation often breaks the structure of these tags, causing the page display to become chaotic and even affecting the layout and functionality of the website.For example, the content of a `<p>This is an <b>important</b> paragraph</p>`, if it is simply truncated to `<p>This is an <b>important</b`

2025-11-08

How to safely truncate a long text containing HTML tags in AnQiCMS template?

In AnQiCMS template design, we often encounter scenarios where it is necessary to display long text content, such as the abstract on the article list page, and the brief introduction of product details.If this long text content is displayed directly, it may cause the page to be long, affecting user experience and layout aesthetics.Therefore, truncating long text is a common requirement.However, when long text content contains HTML tags, simple character truncation may cause problems.For example, a content like this `\u003cp\u003eThis is an important\u003cb\u003e text\u003c/b\u003e\u003c/p\u003e`

2025-11-08

Only delete the specified HTML tags in AnQiCMS article content, which filter should be used?

When using AnQiCMS for content operations, we often encounter situations where we need to refine the processing of HTML tags in article content.For example, during the import or copy and paste process, some unnecessary, format-inconsistent tags may be brought in, which may affect the page layout, SEO performance, and even introduce security risks.In order to meet the requirement of "only deleting the specified HTML tags from the content of AnQiCMS articles", we need to use the specific filter provided by the template engine.In AnQiCMS template system

2025-11-08

How to call and safely display the `Content` field that contains HTML on the AnQiCMS document detail page?

On a website built with AnQiCMS, the core of the document detail page is often the main content of the article, namely the `Content` field.This field carries a wealth of information, ranging from simple text to complex text and image layouts, multimedia embedding, and even custom code segments.Therefore, how to correctly and safely display these contents containing HTML format in the template is a key skill that every AnQiCMS user needs to master.AnQiCMS when designing template rendering, fully considers the security of the content.

2025-11-08

How to prevent AnQiCMS template from automatically escaping HTML tags and output the original content directly?

When using AnQiCMS to build a website and design a template, you may encounter a common problem: when outputting some content in the template, the tags that were originally expected to be displayed as HTML are automatically converted to plain text, for example, `<p>This is a paragraph</p>` becomes `&lt;p&gt;This is a paragraph&lt;/p&gt;`.This loses the original style and structure of the content.Understanding this problem and knowing how to handle it is very important for template developers.Why does the AnQiCMS template automatically escape HTML tags?

2025-11-08

What are the potential uses of the `safe` filter in AnQiCMS besides displaying HTML?

In AnQi CMS template engine, the default automatic escaping mechanism is an important security feature, which can convert special characters in HTML tags and JS scripts (such as `<`, `>`, `&`, etc.) to corresponding HTML entities, thereby effectively preventing cross-site scripting (XSS) attacks.However, in certain specific content output scenarios, we indeed need to allow the browser to parse and render the HTML or similar HTML code as it is, at which point the `safe` filter becomes crucial.

2025-11-08

How does AnQiCMS template escape HTML to prevent XSS attacks when displaying user submitted content?

In today's network environment, website security is of great concern to operators, among which cross-site scripting attacks (XSS) are one of the common security threats.XSS attacks inject malicious scripts into web pages, steal user data, alter page content, and even control user sessions.AnQiCMS as a content management system that focuses on security, built a series of powerful HTML escaping mechanisms to effectively prevent such attacks when processing user submitted content and displaying it in templates.

2025-11-08