How to display Markdown formatted content on a front-end page (including mathematical formulas and flowcharts)?

Calendar 👁️ 75

The Anqi CMS provides powerful and flexible content management capabilities for users, among which the support for Markdown format greatly enhances the efficiency of content creators.Whether it is to write technical articles that require the display of complex mathematical formulas or product documents that need clear flowcharts, AnQi CMS can help you beautifully present these contents on the front-end page.

To achieve this goal, we need to proceed in several steps, from backend settings to frontend template adjustments, to ensure that the content is correctly parsed and rendered.

Step 1: Enable Markdown editor in the background

First, you need to enable the Markdown editor in the Anqi CMS backend management interface. This is the foundation for creating content that includes mathematical formulas and flowcharts.

  1. Log in to the AnQi CMS background.
  2. Go to the “Global Settings” menu and click on “Content Settings”.
  3. On the Content Settings page, find the “Enable Markdown Editor” option and turn it on.
  4. Save your settings.

After enabling, when you are editing articles, single pages, category descriptions, and other content, you can choose to use the Markdown editor to create.

Step 2: Create mathematical formulas and flowcharts in the content

Enable Markdown editor after, you can use Markdown syntax in the text content to write mathematical formulas and flowcharts.

  • Mathematical formula:The mathematical formula in Markdown can usually be written in LaTeX syntax and enclosed with special symbols.
    • Inline formula: Enclosed by a single dollar sign, for example$E=mc^2$.
    • Block formula (displayed independently in a centered line): Enclosed with double dollar signs, for example$$ \int_0^\infty e^{-x^2} dx = \frac{\sqrt{\pi}}{2} $$.
  • Flowchart:Flowcharts are usually implemented in Markdown code blocks using Mermaid syntax.
    • In the Markdown editor, create a code block and specify the language asmermaidFor example:
      graph TD;
          A[Start] --> B{Decision};
          B -- Yes --> C[Perform action];
          C --> D[End];
          B -- No --> E[Wait];
          E --> A;
      This content will be stored in the database in its original Markdown text format after you save it, waiting to be parsed and rendered by the front-end.

Step 3: Ensure the front-end page can correctly render Markdown content

The AnqiCMS Markdown editor itself has already converted Markdown content to HTML, but the complex rendering of mathematical formulas and flowcharts requires additional JavaScript libraries to handle.This is like a browser being able to parse HTML, but to display beautiful charts or interactive components, you need to introduce the corresponding scripts.You need to include the necessary CDN resources in the frontend template file.

Find the directory of the template you are currently using (usually in/template, for exampledefault), then open the template under it.base.htmlFile. This file usually contains the common header of the website (<head>) and footer area, which is an ideal place to introduce global scripts and stylesheets.

Please add the following code snippet tobase.htmlthe file<head>Inside the tag:

  1. Apply the default Markdown style:To make the HTML content rendered by Markdown have good formatting and style, we can introduce a universal Markdown stylesheet.

    <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. Implement the correct display of mathematical formulas:MathJax is a powerful JavaScript rendering engine used to display mathematical formulas in web browsers.

    <script id="MathJax-script" async src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js"></script>
    
  3. Implement the correct display of flowcharts:Mermaid is a JavaScript library that can create charts and visualizations from text definitions similar to Markdown.

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

    After completing these additions, savebase.htmlFile. So, when the browser loads your page, these scripts and styles will be included, thus enabling parsing and rendering of mathematical formulas and flowcharts.

Step 4: Control the rendering method of content fields in the template

Even if you use a Markdown editor in the background, how the final content is displayed on the front end still needs to be called and controlled in the template file.AnQi CMS provides flexible template tags, allowing you to decide whether to convert content fields from Markdown to HTML.

Taking the document detail page as an example, you usually usearchiveDetailtags to display article content. TheContentfield supports onerenderParameters used to control Markdown conversion behavior.

  • By defaultIf the Markdown editor is enabled on the backend,ContentThe field will automatically convert Markdown to HTML when called. You would typically call it like this:

    {% archiveDetail archiveContent with name="Content" %}
    {{ archiveContent|safe }}
    

    Here|safeFilters are crucial, they tell the template engine,archiveContentThe HTML content is safe, no need for double escaping, and can be output directly.

  • If you want to explicitly control whether Markdown rendering is performedyou can userenderparameters:

    • render=trueForce Markdown content to be rendered.
    • render=falseDo not render Markdown, output the original Markdown text directly.
    {# 强制进行Markdown转换,并安全输出HTML #}
    {% archiveDetail archiveContent with name="Content" render=true %}
    {{ archiveContent|safe }}
    
    {# 不进行Markdown转换,输出原始Markdown文本 #}
    {% archiveDetail rawContent with name="Content" render=false %}
    {{ rawContent }}
    

    ThisrenderParameters are very useful in handling some special cases, such as when you may want to display the Markdown syntax itself on the page instead of the rendered effect, or when your content includes some HTML generated by other systems and you do not want it to be parsed again by the Markdown parser.

By following these four steps, your secure CMS website can perfectly display Markdown formatted content on the front end, including complex mathematical formulas and clear flowcharts.


Frequently Asked Questions (FAQ)

Q1: I have enabled Markdown editor according to the steps and written mathematical formulas and flowcharts in the content, but these contents still only display as raw text on the front-end page without being rendered. Why is that?

A1:This usually happens because the frontend template file is missing (base.htmlor other files containing your website<head>The template file) correctly introduces the CDN resources used to render mathematical formulas (MathJax) and flowcharts (Mermaid), or the position of introduction is incorrect. Please carefully check whether the three CDN links provided in the third step have been added tobase.htmlof<head>Within the tags, and make sure there are no syntax errors. Also, ensure that you call it in the templateContentfields were used|safeFilter, for example{{ archiveContent|safe }}to prevent HTML content from being escaped.

Q2: I found that the Markdown content style on the page is a bit chaotic, or the formulas and flowcharts can be displayed but the style is not good, how to unify the display effect of these contents?

A2:Ensure that the default style of Markdown content is beautiful, depending on what you introduce inbase.htmlthe first CDN resource introduced ingithub-markdown-css. This CSS file provides a set of concise and universal Markdown rendering styles.If the style is still not satisfactory, you can choose: 1. Find another Markdown CSS library that better suits your website style and replace it;2. In your custom CSS file, formarkdown-bodyWrite additional CSS rules for the class or its internal elements, overriding or enhancing the default styles.For formulas and flowcharts, MathJax and Mermaid usually come with good default styles, but if you have specific needs, you can refer to their respective official documents to learn how to customize the configuration.

Q3: How should I set up an article that contains both Markdown-written content and some directly pasted HTML code so that they both display correctly without any errors?

A3:In such a mixed content situation, it is recommended to enable Markdown editor in the background and ensure it is called in the templateContentUse field whenrender=trueparameter and always append|safeFilter, for example{{ archiveContent|safe }}. Anqi CMS's Markdown editor usually recognizes and retains HTML tags within Markdown content,render=trueAttempts to convert Markdown sections to HTML, and|safeIt ensures that whether it is the HTML converted by the editor or the HTML pasted directly, it can be parsed as original HTML by the browser. If the HTML part is still escaped, please confirm again|safeIs the filter being used correctly.

Related articles

How to filter and display a list of documents with specific titles or categories in content management?

Today, as content management is increasingly becoming the core competitiveness of corporate websites, AnQiCMS (AnQiCMS) helps us easily manage a large amount of content with its flexible and efficient features.When you need to accurately filter and display a list of documents with specific titles, categories, or attributes, AnQiCMS provides intuitive and powerful template tags to make this process simple and efficient.### Core Tool: `archiveList` Tag Overview To display the document list on the website front-end, we mainly use AnQiCMS's core template tags

2025-11-08

How to display the list of all documents under a specific Tag?

In Anqi CMS, managing and displaying content, the tag (Tag) is undoubtedly a very flexible and powerful tool.It can help us classify content in multiple dimensions, not only making it convenient for visitors to find topics of interest, but also effectively improving the website's SEO performance.Today, let's delve deeply into how to elegantly display all document lists under a specific tag (Tag) on your website. ### Backend preparation: Ensure that the tag settings are in place Before starting the frontend display, we need to make sure that the backend tag settings are complete and standardized. First

2025-11-08

How to configure and display the article Tag tag list in AnQi CMS?

In website operation, Tag tags (also known as keyword tags) are a very practical way to organize content, which can help users quickly find related content and also improve the SEO effect of the website content.AnQiCMS (AnQiCMS) provides a comprehensive Tag label configuration and display function, making it easy and efficient to manage and display these tags.Below, let's take a detailed look at how to set up and use these tags in AnQiCMS.--- ### One, background configuration and management of article Tag label In AnQiCMS

2025-11-08

How to display the user message or article comment list and handle the review status?

In website operation, user comments and article reviews are an important part of promoting interaction and enhancing content value.For users of Anqi CMS, it is crucial to display user-generated content reasonably and manage their review status effectively to ensure the quality of website content and user experience.We will discuss in detail how to achieve this goal in Anqi CMS. ### Learn about comment and message management in Anqi CMS Anqi CMS provides users with convenient content comment and website message management features.In the background management interface

2025-11-08

How to configure URL rewrite rules in AnQi CMS to optimize link display?

The website link, like the door number of a website, a clear and regular door number is not only convenient for visitors to remember and share, but also a key to understanding the structure of the website content, improving the efficiency of inclusion and ranking for search engines.This technique of optimizing dynamic links to look like static files is called 'pseudo-static'.The Aanqi CMS thoroughly understands this, providing users with powerful and flexible static configuration capabilities, aimed at helping websites perform better in search engines while improving the user browsing experience.The value of pseudo-static: Why can't it be ignored?in website operation

2025-11-08

How to avoid XSS attacks and safely display HTML content when outputting?

In website content management, ensuring the safe display of information, especially in preventing cross-site scripting (XSS) attacks, is an important issue that every content creator and website administrator must face.XSS attacks exploit vulnerabilities in websites, injecting malicious code into web pages. When other users visit the web page, the malicious code will execute on the user's browser, potentially stealing user information, hijacking sessions, or even tampering with web content, posing serious harm to the website and users.Fortunately, AnQiCMS has fully considered content security from the beginning of its design, providing us with multiple protective measures

2025-11-08

How to truncate long text content and display an ellipsis?

In the operation of daily websites, we often encounter such situations: the content of the article detail page is rich, but the list page or recommendation module needs to display a concise version of the content for the sake of page layout, usually by truncating a part of the text and adding an ellipsis at the end.AnQi CMS understands the importance of content display and provides very convenient and powerful tools to handle such needs.Let's take a look at how to elegantly implement the truncation of long text content and display an ellipsis in Anqi CMS, making the website interface both beautiful and professional.The need and value of content truncation in many display scenarios

2025-11-08

How to batch generate and display images in Webp format in AnQi CMS?

Website performance is one of the key factors that determine user experience and search engine rankings.Among various optimization methods, image optimization plays a vital role.WebP is a modern image format that boasts excellent compression performance and almost lossless visual quality, and is gradually becoming the new standard for website optimization.How can we efficiently generate and display WebP images in the Anqi CMS management website?AnQi CMS provides very convenient and powerful functional support in this aspect, allowing you to easily achieve the WebPization of website images without delving into technical details

2025-11-08