In the era of increasingly diverse and rich content creation, we often need to present on the website not only plain text, but also a variety of Markdown documents, complex mathematical formulas, and intuitive flowcharts.As website operators, we are most concerned about the convenience of inputting these contents and whether they can be rendered and displayed correctly and beautifully on the front end.AnQiCMS (AnQiCMS) provides a high-efficiency and flexible solution in this aspect.

Content creation and backend support

The Anqi CMS provides a very user-friendly content editing experience in the backend, which includes deep integration with the Markdown editor.When creating articles, product detail pages, or standalone single pages, you can choose to enable the Markdown editor.This means you can directly use Markdown syntax to write content, for example, using#To indicate a title,**To bold,-or*To create a list, and throughcodeormermaid/mathInsert specific types of content with code blocks.

This greatly simplifies the content creation process. We no longer need to exert effort to memorize complex HTML tags, but can focus on the logic and structure of the content.For scenarios that require inserting code snippets, tables, or quoted text, Markdown can handle them in a concise and clear manner.Especially when dealing with technical articles or academic content, embedding mathematical formulas and flowchart syntax directly in Markdown can greatly enhance the efficiency of creation.

Core rendering mechanism: from Markdown to HTML

When we publish or edit content containing Markdown in the background, Anqi CMS will not directly send the original Markdown text to the front end.The system will perform a critical conversion step in the background: it will parse the Markdown text and convert it to standard HTML structure.This process ensures that even without an additional Markdown parser on the front end, the content can be displayed in a format that the web page can recognize.

What is more noteworthy is that Anqi CMS also provides fine-grained control when calling template content. For example, when usingarchiveDetail/pageDetailortagDetailTag call contentContentWhen setting the fieldrender=trueorrender=falseThe parameter determines whether to perform Markdown to HTML conversion.This means that if you have special requirements and want the front-end to handle the original Markdown text, you can completely turn off the automatic conversion feature and hand over control to the front-end.Of course, in most cases, enabling automatic rendering allows content to be displayed quickly and stably on the web page.

Front-end display: Achieving powerful rendering with external forces

Converting Markdown to HTML is just the first step, to ensure that mathematical formulas and flowcharts are displayed correctly and beautifully, the browser needs further 'understanding'.AnQi CMS cleverly utilizes mature third-party JavaScript libraries and CSS styles, entrusting the rendering of complex content to professional tools.These libraries are loaded through CDN (Content Delivery Network), which ensures access speed and facilitates the update of features.

  • Universal Markdown styleTo make the converted Markdown content have a unified and beautiful visual effect, we can add in the header of the website'sbase.htmltemplate file likegithub-markdown-cssThis is an external stylesheet. It provides default formatting and styling for the HTML structure of Markdown elements, making the article look more professional.

    <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" />
    
  • Mathematical formula (MathJax): For mathematical formulas that include LaTeX or MathML syntax, we need to introduce the MathJax library.MathJax is a powerful JavaScript display engine that can render mathematical formulas in high quality on all mainstream browsers. Just inbase.htmlAdd the corresponding script at the top, and it can automatically scan the mathematical formulas on the page and render them into clear and readable mathematical expressions.

    <script id="MathJax-script" async src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js"></script>
    
  • Flowcharts and Diagrams (Mermaid): If you use Mermaid syntax in Markdown to create flowcharts, sequence diagrams, Gantt charts, and so on, then the Mermaid.js library is indispensable.Mermaid allows you to define charts using simple text syntax, and then render them into SVG graphics with JavaScript.Similarly, inbase.htmlBy introducing the Mermaid script and initializing it, these text diagrams can come to life on your website.

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

Through this collaboration between the front and back ends, Anqi CMS ensures the simplicity of content storage (Markdown) and also achieves powerful and flexible front-end rendering functionality.We, as users, can selectively enable these features based on actual needs, thereby providing readers with a rich content and professional display reading environment.This architecture not only relieves the rendering pressure on the server, but also takes advantage of the CDN's advantages, ensuring that global users can enjoy a fast loading experience.

Frequently Asked Questions (FAQ)

1. Why do you need to manually add CDN links in the template file instead of AnQiCMS automatic injection?This approach is adopted by AnQi CMS to provide users with the greatest flexibility and control.Different websites may have different preferences for the rendering of Markdown styles, mathematical formulas, or flowcharts, and may even wish to use custom libraries or CDNs. Manually inbase.htmlAdd it means you can freely choose (or replace) the third-party library version and CDN service that is most suitable for your website needs, and even completely disable a feature to avoid unnecessary resource loading, thus optimizing website performance.

2. Can I integrate other types of formula or chart rendering libraries besides MathJax and Mermaid?Of course, it can. Anqi CMS's design philosophy encourages openness and expansion.If the rendering library you choose is based on JavaScript and runs on the browser, and provides similar CDN references or local deployment solutions, you can refer to the integration methods of MathJax and Mermaid, inbase.htmlIntroduce their scripts and initialize them. The system takes an open attitude towards the introduction of front-end scripts, allowing you to freely choose and replace them according to your specific needs.

3. If my article content is not entirely written in Markdown, is this rendering mechanism still effective?This rendering mechanism is mainly aimed at the content input by the backend Markdown editor. If your content is entered directly in HTML format, or generated by a rich text editor into HTML, then the Markdown to HTML conversion step will not occur, but front-end rendering libraries such as MathJax and Mermaid can still recognize and process the corresponding syntax blocks contained in the HTML content (such as,<div class="mermaid">or$$\alpha + \beta$$)。Meaning that even when mixed, as long as the grammar rules are followed, the rendering of these contents can still be carried out normally.