Today, with the increasingly rich digital content, websites are no longer just a pile of text and images.For users who need to display technical documents, academic papers, data analysis reports, even complex business processes, how to efficiently and beautifully present mathematical formulas and flowcharts has become the key to enhancing the professionalism of content and user experience.AnQi CMS is well-versed in this, providing powerful Markdown editor integration capabilities,配合simple front-end configuration, allowing your website to easily support the display of these advanced content.
Enable Markdown Editor: A New Paradigm for Content Creation
To start enjoying the convenience of Markdown in Anqi CMS, you first need to activate it. This is like adding a Swiss Army knife to your content creation tool box.
You just need to go to the Anqi CMS backend management interface, in全局设置below内容设置In the menu, find and enable the Markdown editor option.Once enabled, you will find that the article editing interface is completely new, focusing more on plain text input and concise format tags, goodbye to the format compatibility issues and complex operations that traditional rich text editors may bring.Markdown with its intuitive syntax allows you to easily complete formatting while writing, greatly enhancing content production efficiency.
To inject styles for Markdown content: the basis for beautiful presentation
Enable Markdown editor after, your content will be stored in Markdown syntax.In order to present these contents in an aesthetically pleasing way on the website front-end, especially for elements such as code blocks and quotes, we need to apply a suitable set of CSS styles.
Generally, the core layout files of website templates are locatedtemplateUnder the directorybase.htmlOr other main layout file. Find the file<head>The part of the label, and introduce a popular GitHub style Markdown CSS library.This library can provide a simple and professional default style for your Markdown content, making your articles look more standardized and readable.
<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" />
Add this line of code to<head>Within the tags, save the file, and your Markdown content will have the basic GitHub style.
Elegant display of mathematical formulas: Say goodbye to images and layout troubles.
For websites in fields such as science and engineering, finance, or data analysis, mathematical formulas are the soul of the content.The traditional approach is often to take screenshots or use images, which is not only麻烦 for editing, but also不利于SEO and responsive design.The Anqi CMS can perfectly solve this problem by integrating JavaScript libraries like MathJax.
After modifying the Markdown style, please continue inbase.htmlthe file<head>the tag (usually after the CSS file), add the following MathJax script reference:
<script id="MathJax-script" async src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js"></script>
This script will intelligently recognize LaTeX format mathematical formulas in your Markdown content and render them as high-quality, scalable SVG or HTML format.Now, you can use common LaTeX syntax to write formulas in Markdown documents.
当 $ax^2 + bx + c = 0$ ($a \neq 0$) 时,其解为:
$$ x = \frac{-b \pm \sqrt{b^2 - 4ac}}{2a} $$
Among, the single dollar sign$Enclosed formula is inline formula, double dollar signs$$Enclosed formula is an independent line formula.
The intuitive presentation of the flowchart: clearly shows complex logic
In addition to mathematical formulas, flowcharts are indispensable elements in many technical and business documents. They can visually represent complex logical relationships or operational steps in a graphical way.AnQi CMS integrates the Mermaid library, allowing you to easily create various charts in Markdown.
Inbase.htmlthe file<head>Within the tag, add the Mermaid module import script after the MathJax script:
<script type="module">
import mermaid from 'https://cdn.jsdelivr.net/npm/mermaid@10/dist/mermaid.esm.min.mjs';
mermaid.initialize({ startOnLoad: true });
</script>
This script enables Mermaid, allowing your Markdown content to parse and render diagrams written in Mermaid syntax. Here is a simple flowchart example:
graph TD
A[Start] --> B{Do you meet the conditions?};
B -- Yes --> C[Perform operation 1];
B -- No --> D[Perform operation 2];
C --> E[End];
D --> E;
In the Markdown editor, usemermaidcode blocks (such as themermaidtags shown) to write various charts, including flowcharts, sequence diagrams, Gantt charts, and so on.
Content creation and publishing: turning ideas into reality
After completing the configuration of the above front-end template, you can return to the Anqi CMS backend and create your content freely.Whether it is complex formulas in technical articles or clear processes in project plans, they can be concisely written in Markdown editors and displayed professionally and beautifully on the front-end pages.
When creating or editing a document, simply enter your text, mathematical formulas (LaTeX syntax), and flowcharts (Mermaid syntax) directly in the Markdown editor.After saving and publishing, your website visitors will be able to see beautifully rendered professional content.
Practical tips: ensuring perfect content presentation
- CDN accelerationIn the example, we used CDN (Content Delivery Network) to load GitHub Markdown CSS, MathJax, and Mermaid scripts.CDN can significantly improve the loading speed of these external resources, optimizing the user experience.It is strongly recommended to continue using CDN services in actual deployment.
- Preview and testBefore you publish articles containing this advanced content, be sure to preview and test them on different browsers (such as Chrome, Firefox, Safari) and devices (PC, mobile phone, tablet).This helps ensure that all formulas and charts are loaded and displayed correctly, avoiding compatibility issues that may affect user experience.
- Template tags and escapingIn some cases, if you directly go through the template tag (such as in
base.htmlpass througharchive.ContentVariable output article content) Output Markdown content, and find that the formula or flowchart code is not rendered correctly, which may be because the template engine defaults to escaping HTML. At this point, you may need to add|safefor example:{{ archive.Content|safe }}This will inform the template engine that the content is safe HTML, no need to escape, thus allowing MathJax and Mermaid to parse correctly. Anqi CMS'sarchiveDetaillabel'sContentfield, after enabling the Markdown editor in the background, it will usually automatically convert Markdown to HTML. If the Markdown editor is disabled in the background, but you still want the content to be parsed, you can manually inarchiveDetailthe tag withrender=truefor example:{% archiveDetail archiveContent with name="Content" render=true %}.
Through the powerful Markdown editor provided by Anqi CMS and its flexible template system, integrating mathematical formulas and flowcharts is no longer an unreachable technical challenge.It will help you create more professional, vivid and informative website content, greatly enhancing the professionalism and user interaction experience of the website.
Frequently Asked Questions (FAQ)
Ask: Why did the mathematical formula or flowchart still display as raw code on the page instead of being rendered after I followed the steps?Answer: This is usually caused by the HTML escaping mechanism of the template engine. Please check the output content part of your template file, for example
{{ archive.Content }}, to make sure it is added after.|safea filter such as{{ archive.Content|safe }}In addition, make sure you are logged in on the back end's全局设置-u003e内容设置China has enabled the Markdown editor, and the related JavaScript libraries (MathJax and Mermaid) have been correctly introduced tobase.htmlthe file<head>Tag inside.Ask: Can I change the default style of Markdown content on the page, such as adjusting font, color, or spacing?Of course you can. The article mentions
github-markdown-cssThe library provides a set of basic styles.If you want to customize, you can directly modify the CSS file of your website template, by overriding the GitHub Markdown CSS rules to achieve this.