In the era of increasingly rich and diverse 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, what we care about most is whether the input of these contents is convenient, and whether they can be rendered and displayed correctly and beautifully on the front end.AnQiCMS (AnQiCMS) provides a highly efficient and flexible solution in this aspect.
Content creation and backend support
The autoCMS 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.#to indicate the title,**to make text bold,-or*to create lists, and throughcodeormermaid/mathcode blocks to insert specific types of content.
This approach greatly simplifies the content creation process.We no longer need to struggle to remember complex HTML tags, but can focus on the logic and structure of the content.For scenarios that require inserting code snippets, tables, or referenced text, Markdown can handle them in a concise and clear manner.Especially when dealing with technical articles or academic content, embedding mathematical formulas and flowcharts directly in Markdown syntax greatly enhances creation efficiency.
核心渲染机制:从Markdown到HTML
When we publish or edit content containing Markdown in the background, the safe CMS will not directly send the original Markdown text to the frontend.The system will perform a key step in the background: it will parse the Markdown text and convert it into standard HTML structure.This process ensures that the content can be displayed in a format recognizable by the web page even if there is no additional Markdown parser on the frontend.
更值得一提的是,安企CMS在模板调用内容时,还提供了精细化的控制。例如,在使用EnglisharchiveDetail/pageDetailortagDetailTags calling contentContentWhen setting fieldsrender=trueorrender=falseThe parameter determines whether to perform Markdown to HTML conversion.This means that if you have special requirements and want the frontend to handle the original Markdown text, you can completely turn off the automatic conversion feature and hand over the control to the frontend.Of course, in most cases, enabling automatic rendering can make content display quickly and stably on web pages.
Front-end display: Achieving powerful rendering with external forces
Universal Markdown styleEnglish: To ensure that the converted Markdown content has a unified and beautiful visual effect, we can add in the header of the website
base.htmlEnglish: A template file likegithub-markdown-cssSuch an external stylesheet. It can provide 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 containing LaTeX or MathML syntax, we need to introduce the MathJax library.MathJax is a powerful JavaScript rendering engine that can display mathematical formulas in high quality in all mainstream browsers.
base.htmlAdd the corresponding script at the top, and it can automatically scan mathematical formulas in 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>Flowchart 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, which is then rendered into SVG graphics by JavaScript.
base.htmlIntroduce the Mermaid script and initialize it, and these text diagrams will 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 front-end and back-end collaboration model, the security CMS not only ensures the simplicity of content storage (Markdown), but also achieves the powerful functions and flexibility of front-end rendering.We, as users, can selectively enable these features according to our actual needs, thus providing readers with a rich content and professional display reading environment.This architecture not only reduces the rendering pressure on the server but also takes advantage of the CDN's benefits, ensuring that all global users can enjoy a fast loading experience.
Common Questions (FAQ)
1. Why do you need to manually add CDN links in the template file instead of AnQiCMS automatic injection?The Auto CMS uses this method to provide users with the greatest flexibility and control.Different websites may have different preferences for Markdown styles, mathematical formulas, or flowcharts rendering, and may even wish to use custom libraries or CDNs.base.htmlAdding to the configuration means you can freely choose (or replace) the version of the third-party library and CDN service that best suits your website needs, even completely disable a feature to avoid unnecessary resource loading, thereby optimizing website performance.
2. Can I integrate other types of formula or chart rendering libraries besides MathJax and Mermaid?Of course, you can.This design philosophy of Anqi CMS encourages openness and expansion.base.htmlThe scripts introduced in them and initialized. The system is open to the introduction of front-end scripts, allowing you to freely choose and replace them according to specific needs.
3. If my article content is not fully written in Markdown, does this rendering mechanism still work?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, the conversion step from Markdown to HTML 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 (for example, <div class="mermaid">or$$\alpha + \beta$$)。That is to say, even when mixed, as long as the corresponding grammar rules are followed, the rendering of these contents can still be carried out normally.