How to correctly render Markdown content as HTML and display mathematical formulas or flowcharts in Anqi CMS?

Calendar 👁️ 96

In Anqi CMS, using Markdown format to write content not only improves editing efficiency, but also maintains the structured and readable nature of the content.When the content involves complex mathematical formulas or requires a clear flowchart, the power of Markdown can be demonstrated.The Anqi CMS provides good support for this, let's take a look at how to correctly render and display these advanced contents on the website.

Step 1: Enable Markdown editor

First, make sure that your security CMS system has enabled the Markdown editing feature. This setting is usually in the background ofGlobal SettingsFind it.

Enter the Anqi CMS backend, find the left menu bar ofBackend settingsand click to enterContent settings. On this page, you will see an option, usually 'Enable Markdown Editor' or similar descriptions.Make sure this option is checked or enabled and save your changes.This is the foundation for the system to recognize and process Markdown content.

Second step: write Markdown content in the document

When the Markdown editor is enabled, you can write content using Markdown syntax when creating or editing documents.Markdown is concise and intuitive, allowing us to focus on the content itself.

For mathematical formulas, Markdown usually combines LaTeX syntax to write:

  • Inline formula: Use a single dollar sign$Wrap, for example:$\sum_{i=1}^n i = \frac{n(n+1)}{2}$It will be rendered as:(The sum of the first n natural numbers is n(n+1)/2).
  • Block formula(Displayed on a separate line): Use double dollar signs$$Wrap, for example:
    
    $$
    E=mc^2
    $$
    
    It will be rendered as: $( E=mc^2 )$

For flowcharts, Anqi CMS supports generating through Mermaid syntax.Mermaid allows you to describe diagrams using text and then automatically render them into graphics.Mermaid's syntax is very intuitive, withmermaidThe keyword is followed by the chart type and definition, and enclosed in three backticks ` . For example, a simple flowchart can be like this:

graph TD;
    A[Start] --> B{Decision};
    B --> |Yes| C[Perform action];
    B --> |No| D[End];
    C --> D;

You can directly paste or write these Markdown codes in the document content editor of AnQi CMS.

Step 3: Adjust the website template to support rendering

Markdown content, especially mathematical formulas and flowcharts, need to rely on front-end JavaScript libraries to be correctly rendered in the browser.The Anqi CMS template system is very flexible, allowing us to easily integrate these libraries.You need to modify the template file, usually the "skeleton file" of the website——base.htmlto include the necessary CSS and JavaScript.

base.htmlThe file is usually located in the root directory of your theme folder, for example./template/default/base.htmlIn the file.<head>Within the tag, we need to add the following code:

  1. Provide basic styling for Markdown content:To make the rendered content of Markdown more visually appealing and conform to standards, you can introduce GitHub-style Markdown CSS.

    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/github-markdown-css/5.2.0/github-markdown.min.css" crossorigin="anonymous" referrerpolicy="no-referrer" />
    
  2. Supports display of mathematical formulas:MathJax is a powerful JavaScript rendering engine that can render LaTeX-formatted mathematical formulas into high-quality layouts.

    <script id="MathJax-script" async src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js"></script>
    
  3. Support flowchart display:The Mermaid library can parse Mermaid syntax and convert it into SVG graphics.It should be noted that Mermaid usually needs to be imported and initialized as an ES module.

    <script type="module">
        import mermaid from 'https://cdn.jsdelivr.net/npm/mermaid@10/dist/mermaid.esm.min.mjs';
        mermaid.initialize({ startOnLoad: true });
    </script>
    

    Make sure these scripts are placed in<head>tags so that the page can be processed in time during loading. Among them, the initialization code of Mermaidmermaid.initialize({ startOnLoad: true });Tell Mermaid to automatically find and render all Mermaid charts after the page is loaded.

Step 4: Make sure the content is displayed correctly on the document details page.

In Anqi CMS, document content (for examplearchive.Content)usually gets automatically rendered as HTML. However, if you are storing Markdown content in custom fields or want to explicitly control the rendering behavior, you can do so in the template byarchiveDetailLabel collaborationrenderParameter to achieve.

For example, in your article detail template (usually{模型table}/detail.html), the display of document content snippets may be as follows:

{%- archiveDetail articleContent with name="Content" render=true %}
{{articleContent|safe}}

here,render=trueIt ensured that Markdown content would be processed into HTML. And|safeThe filter is crucial, it tells the template engine that this content is safe HTML, which does not need to be escaped again, otherwise you might see the original HTML tags instead of the rendered effect.

If your Markdown content is stored in a custom field (for example, you have created a field namedintroductionThe custom field to store Markdown introduction), then you may need to use it similarlyrenderFilter:

{% archiveDetail introduction with name="introduction" %}
{{introduction|render|safe}}

After completing these steps, you can publish a document containing Markdown, mathematical formulas, and flowcharts, and then visit the front-end page for testing.Remember to clear your browser cache before viewing the effect to ensure that the latest template files and scripts are loaded.

With the above configuration, your Anqi CMS website can not only publish standard text content, but also present complex mathematical formulas and dynamic flowcharts in a professional and intuitive manner, greatly enriching the expressiveness of the website content.


Frequently Asked Questions (FAQ)

1. Why is my mathematical formula or flowchart not displayed, but only the original code?This is usually because the front-end JavaScript rendering library has not been loaded or initialized correctly. Please check the following points:

  • Is the Markdown editor enabled?Please confirm that the Markdown editor has been enabled in the "Content Settings" of the Anqi CMS backend.
  • Is the template file modification correct?Please check carefully.base.htmlIn the file, whether the CDN links of MathJax and Mermaid are complete, the paths are correct, and they are all placed in<head>the tags. Especially Mermaid'sscript type="module"andmermaid.initialize()Have all been added?
  • Whether used when outputting content?|safeFilterIn{% archiveDetail %}Make sure to use tags when outputting content,|safeFilter, for example{{articleContent|safe}}otherwise the HTML code will be escaped and cannot be rendered.
  • Network connection issue: Confirm that your server and visitors can connect to the CDN service (cdnjs.cloudflare.comandcdn.jsdelivr.net), if the network is restricted, these scripts may not load.

2. I only want to use Markdown text formatting, not mathematical formulas and flowcharts, can I?Of course you can. If you only need Markdown text formatting and styling (such as headings, lists, code blocks, etc.), and do not need support for mathematical formulas and flowcharts, then you just need tobase.htmlAdd the GitHub Markdown CSS link.You can omit the JavaScript inclusion of MathJax and Mermaid, which can reduce the resources loaded on the page.

3. Will these third-party CDN resources affect the loading speed or stability of the website?Using CDN (Content Delivery Network) usually speeds up the loading of resources because CDN distributes resources to servers around the world, and users can obtain resources from the nearest node.cdnjs.cloudflare.comandcdn.jsdelivr.netSuch mainstream CDN services have very high stability and speed.However, any external dependency carries potential risks, such as temporary interruptions in CDN services or network congestion.For most small and medium-sized enterprise websites, this impact is usually negligible and the benefits outweigh the drawbacks.If you have high requirements for performance and stability and possess relevant technical capabilities, you can also consider downloading these JS/CSS files to host them on a local server, but this will increase maintenance costs.

Related articles

How does AnQi CMS truncate long text content and add an ellipsis?

In website content operation, effectively displaying information while maintaining the page's cleanliness and the smoothness of user experience is a crucial link.Especially for long text content, how to truncate the display on the list page or overview section with an ellipsis is a common technique to improve the readability and aesthetics of the website.AnQiCMS (AnQiCMS) is a feature-rich management system that provides a flexible mechanism to meet this requirement at the template layer.

2025-11-09

How to use the `archiveDetail` tag in AnQi CMS to display custom field content of a document?

AnQi CMS has a flexible content model design that allows users to add various custom fields to documents according to their business needs.These custom fields greatly enrich the expression of the website content, whether it is to display product specifications, event details, or additional information of articles, it can be handled with ease.How can `archiveDetail` tag be cleverly used on the document detail page to display these valuable custom field contents?### Understanding the core function of the `archiveDetail` tag In the Anqi CMS template system

2025-11-09

How to implement conditional judgment and loop traversal in the Anqi CMS template to control content display?

In Anqi CMS, templates are the core of website content presentation, they are not only responsible for the layout and style of content, but also bear the important responsibilities of displaying different content based on different conditions and cyclically presenting data lists.To make your website content more dynamic and interactive, it is particularly important to have a deep understanding of how to implement conditional judgments and loop traversals in templates.The Anqi CMS template engine uses syntax similar to Django, which allows you to quickly get started and flexibly apply it if you are familiar with web development.### Understand AnQiCMS

2025-11-09

How to customize TDK (Title, Description, Keywords) in Anqi CMS to optimize the display of pages in search results?

In website operation, the display effect of the page in search results is crucial for attracting users and increasing traffic.Among them, TDK (Title, Description, Keywords) is the core element that search engines understand the content of the page and decide how to display the page.AnQiCMS (AnQiCMS) provides users with flexible and powerful TDK customization features, helping us refine page optimization, thereby achieving better performance in search results.

2025-11-09

How to implement pagination functionality in Anqi CMS and customize the display style of page numbers?

In AnQi CMS, the pagination feature of website content is an indispensable part of improving user experience and optimizing site structure.Whether it is a list of blog articles, product display pages, or other dynamic content, reasonable pagination makes it easier for users to browse a large amount of information and also helps search engines better understand and extract website content.Today, let's delve deeper into how to implement pagination in AnQiCMS and customize the display style of page numbers according to your own needs. ### Why do we need pagination? Imagine that your website has hundreds or even thousands of wonderful articles.If there is no pagination

2025-11-09

How to use the global settings of Anqi CMS to unify the display of copyright information and contact details on the website?

In website operation, copyright statements and contact information are important components for building brand trust, providing user support, and ensuring legal compliance.AnQiCMS (AnQiCMS) fully understands the importance of this information, and therefore provides an intuitive and powerful global setting function, allowing website administrators to uniformly and conveniently control the display of these contents without frequent code modifications.Imagine if your website has hundreds of pages and you need to manually edit each page every time you update the copyright year or customer service phone number, it would be such a繁琐 and error-prone task.

2025-11-09

How to filter and display a specific list of documents based on keywords in AnQi CMS?

When using Anqi CMS to manage website content, we often need to search and display related document lists based on specific keywords.It is crucial to master the keyword filtering method, whether it is to create an in-site search results page or to display content closely related to a theme on a specific topic page.The AnQi CMS provides flexible and powerful template tag functions, making this task intuitive and efficient.### The foundation of keyword filtering: `archiveList` tag's `q`

2025-11-09

How to display the document category list at different levels in Anqi CMS and its associated documents?

How to efficiently organize and display a large amount of content in website operation is the key to improving user experience and website usability.For those who use AnQiCMS, the system provides powerful content model and template tag features, which can help us easily implement multi-level document classification lists and clearly display the associated documents under each category. Let's explore together how to build a website navigation with both hierarchy and rich content using these features in Anqi CMS.### Understand the content structure of AnQi CMS In AnQi CMS

2025-11-09