In content creation, especially in fields involving technology, science, or complex concepts, we often need to insert mathematical formulas or draw flowcharts to assist in explanation.The Markdown editor of AnQiCMS (AnQiCMS) provides us with great convenience, allowing these complex elements to be input in a concise text format and presented elegantly on the web.How can we specifically operate to ensure that the content is displayed correctly?
Firstly, make sure that your CMS system has enabled the Markdown editor.You can go to the Anqi CMS backend, find the corresponding option under "Global Settings" and "Content Settings", and set it to enabled.This is the foundation for all subsequent steps.
Insert mathematical formula and ensure its correct display
In the Markdown editor, mathematical formulas are usually written using LaTeX syntax.AnQi CMS integrates MathJax or a similar library to parse these formulas.When writing, you can choose between two forms: inline formula and block-level formula.
- Inline formula: If you want to insert a short mathematical expression in a paragraph of text, you can use a single dollar sign
$Wrap the formula. For example,$E=mc^2$It will display Einstein's mass-energy equation in the text stream. - Block formula: For formulas that need to be displayed independently, centered, and may contain multiple lines or complex structures, you can use double dollar signs.
$$Enclose it. For example:
This format causes the formula to be displayed on a new line and is usually centered.$$ \int_0^\infty e^{-x^2} dx = \frac{\sqrt{\pi}}{2} $$
It is not enough to enter formulas in the editor, a special JavaScript library is needed in the web browser to render these LaTeX syntaxes into recognizable mathematical symbols.We usually rely on CDN resources like MathJax./templateUnder the directorybase.htmlfile, and in its<head>the tag the followingscriptcode:
<script id="MathJax-script" async src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js"></script>
This code will asynchronously load the MathJax library, which will automatically scan and render mathematical formulas on the page after it is loaded.
Insert a flowchart and ensure it is displayed correctly.
Flowcharts play an indispensable role in explaining business logic and program algorithms.The Anqi CMS Markdown editor supports Mermaid syntax for drawing flowcharts.Mermaid is a text-based chart tool that can convert concise text descriptions into beautiful charts.
In the Markdown editor, you need to use special code blocksmermaidto enclose your flowchart description. For example, a simple flowchart can be written like this:
graph TD
A[Start] --> B{Do you meet the condition?};
B -- Yes --> C[Perform action];
B -- No --> D[End];
C --> D;
This code will describe a simple judgment process from 'beginning' to 'end'.
Similar to mathematical formulas, Mermaid flowcharts also require a JavaScript library to be rendered in the browser. You also need to editbase.htmlfile, and in its<head>the tag the followingscriptcode:
<script type="module">
import mermaid from 'https://cdn.jsdelivr.net/npm/mermaid@10/dist/mermaid.esm.min.mjs';
mermaid.initialize({ startOnLoad: true });
</script>
This code will import the Mermaid library and initialize it to be able to recognize and render Markdown inmermaidcode blocks defined by flowcharts. Please notetype="module"It is the syntax of ES module, ensuring that the browser can load it correctly.
Integrate styles with the final presentation
To make your Markdown content, including formulas and flowcharts, visually more coordinated and professional, you can also consider introducing a default Markdown stylesheet. For example, you canbase.htmlof<head>Add:
<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" />
This stylesheet provides Markdown rendering effects similar to GitHub, making your content more unified and beautiful.
After completing these steps, save your template file and ensure that the article content has used LaTeX and Mermaid syntax correctly.When visiting a webpage, these formulas and flowcharts are automatically parsed and rendered by the JavaScript library loaded in the browser, clearly presented to the reader.If you encounter display issues, please check the browser console (F12) for any error messages and confirm that all CDN links are accessible and error-free.
Frequently Asked Questions (FAQ)
Why is the formula or flowchart I inserted in the background Markdown editor not displayed on the front page?This is usually because you have not included the template file for the website (such as
base.html) Properly introduce the corresponding rendering library script. MathJax (for mathematical formulas) and Mermaid (for flowcharts) both need to pass throughscriptThe tag needs to be loaded from the CDN and initialized before it can be parsed and displayed in the browser for the special Markdown syntax. Please check yourbase.htmlfile to ensure that the mentioned above is correctscriptThe code has been added correctly.If my website already has custom CSS styles, introducing
github-markdown-cssWill it cause style conflicts?github-markdown-cssIt is a general Markdown rendering stylesheet that provides default styles for common Markdown elements (such as headings, paragraphs, lists, code blocks, etc.).If your website already has very detailed custom CSS, there is indeed a possibility of some style conflicts.github-markdown-cssPlace the reference after your custom CSS so that your custom styles can override it; or, you can optionally only include a part of itgithub-markdown-cssThe rule, or simply not to introduce, but to write exclusive styles for Markdown content according to your own design style.Can I use multiple mathematical formula rendering libraries or flowchart libraries at the same time?In technical terms, it is feasible to load multiple libraries simultaneously, but it is usually not recommended.This may lead to resource redundancy, increase page load time, and there may be compatibility issues or conflicts between different libraries, leading to incorrect rendering.To ensure **'s performance and stability, it is recommended that you choose a rendering library that meets your needs (such as MathJax and Mermaid) and maintain consistency throughout the entire website.If you indeed have special requirements, be sure to perform thorough testing to ensure that all content is displayed normally.