What is the specific function of the `startOnLoad` parameter in `mermaid.initialize({ startOnLoad: true })`?

Calendar 👁️ 71

As an experienced senior person proficient in Anqi CMS operation, I know that every technical detail contains the value of improving user experience and content presentation efficiency. Formermaid.initialize({ startOnLoad: true })ofstartOnLoadThe parameter plays a crucial role in AnQiCMS content management, especially in scenarios that support Markdown content display.

The role of Mermaid in AnQiCMS content display

AnQi CMS to meet the modern website's demand for content diversity, has introduced support for Markdown editors.This means that content creators can not only use rich text editors, but also take advantage of the concise syntax of Markdown to build articles.The power of Markdown lies in its ability to handle not only regular text and images but also integrate more advanced content through specific extension syntaxes, such as mathematical formulas and flowcharts.In order to correctly convert these text-defined flowcharts into visual graphics on the web, Anqi CMS has integrated the JavaScript library named Mermaid.Mermaid can parse concise text descriptions and dynamically render them into SVG charts, greatly enhancing the expressiveness of the content.

mermaid.initialize()Configuration entry

The integration of the Mermaid library is not as simple as just including the script file. It requires initialization and configuration to ensure it works as expected in various environments. This is exactlymermaid.initialize()The function's purpose is located. When the Mermaid script is loaded into the page, the function is usually called to pass a configuration object, which contains all the settings required for the Mermaid runtime.For example, it can define the theme of the chart, default font, line style, and so on.In the Anqi CMS template file (usuallybase.htmlIn this case, we see the following initialization code snippet, which ensures that the Mermaid library can be loaded and configured correctly:

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

startOnLoadThe deep meaning of the parameters

In the above configuration object,startOnLoad: trueIt is one of the key parameters for the normal operation of Mermaid. Its specific function is to command the Mermaid library to execute after the web page content is fully loaded.automaticallyScan the entire HTML document, looking for all elements that contain Mermaid chart definitions (usually wrapped in a specific<pre>or<code>tag, and withmermaidThe text block of the class. Once these text blocks are found, Mermaid will immediately parse and render them into the corresponding SVG flowchart.

This parameter is set totrueThe meaning lies in the fact that it greatly simplifies the integration process of Mermaid charts.Content operators or template developers do not need to write additional JavaScript code to manually trigger the rendering of the chart.Once the page content is loaded, Mermaid will automatically "start", converting all text-defined flowcharts into clear and beautiful graphics.This ensures that when users visit a page containing a flowchart, they can see the fully rendered chart first, without first seeing plain text and then the chart transformation process, thereby providing a smooth and consistent user experience.If this parameter is missing or set tofalseThen the Mermaid chart in the page will only be displayed in its original text definition form until it is triggered by an explicit JavaScript call to render.

By this automated mechanism, Anqi CMS builds an efficient bridge between backend Markdown content creation and frontend visual presentation.It allows website operators to focus on content creation and optimization without having to pay too much attention to the technical details of underlying chart rendering, thereby ensuring that high-quality, interactive content is presented perfectly to visitors.


Frequently Asked Questions (FAQ)

Ask: If I do notstartOnLoadthe parameter totrue, how will the flowchart created in AnQiCMS be displayed?

Answer:IfstartOnLoadthe parameter is not set totrueOr omitted, the Mermaid library will not automatically scan and render charts when the page is loaded.This means that the flowchart the user sees in the browser will be in the original text definition form, rather than a beautiful SVG chart.In order for the chart to display, you will need to manually write JavaScript code, after the page is loadedmermaid.init()ormermaid.render()A method to trigger the rendering process, but this usually adds additional development burden and potential rendering delays.

Question:mermaid.initialize()in the methodstartOnLoadParameters excepttrue besides, are there other configurable values?

Answer: startOnLoadA parameter is a Boolean value, it mainly acceptstrueorfalsethese two values. When set totrue, Mermaid will automatically render the chart when the page is loaded. When set tofalseWhen, Mermaid will not automatically render charts, and you need to manually call its API method to control the timing of chart rendering.

Ask: In the AnQiCMS template,mermaid.initialize()where is this code usually placed on the page?

Answer:Including the examples and**practice in the AnQiCMS document,mermaid.initialize()The script code is usually placed on the page's<head>area, or<body>before the tag ends. The example given in the document is to place it insidebase.htmlThe file header. It is important that this script should be executed after most of the content of the page (especially the elements containing Mermaid diagram definitions) has been parsed and loaded by the browser to ensure that Mermaid can correctly find and process all diagrams. Usingtype="module"Helps the browser to load and execute scripts at the appropriate time.

Related articles

How to adjust the font, size, or color of MathJax rendered mathematical formulas?

As a senior security CMS website operator, I am well aware that the details of content presentation are crucial for user experience.Especially for websites that need to display mathematical formulas, ensuring the clarity, aesthetics, and unity of the website's overall style is an indispensable aspect of operation.AnQi CMS has integrated Markdown editor in the new version and supports rendering mathematical formulas through MathJax, which provides us with great convenience.However, enabling MathJax is not enough; we also need to further adjust its style to meet specific visual requirements.###

2025-11-06

Does Anqi CMS provide detailed usage examples and frequently asked questions for `MathJax` or `Mermaid`?

As a senior CMS website operation personnel of an enterprise, I am well aware of the importance of content in attracting and retaining users.With the continuous enrichment of internet content forms, we often encounter scenarios where it is necessary to display professional content such as mathematical formulas and flowcharts on websites.This not only enhances the professionalism and authority of the content, but also significantly improves the user experience.Whether AnQi CMS provides detailed usage examples and frequently asked questions for `MathJax` or `Mermaid`, I will elaborate in detail based on the characteristics of our system and actual operational experience.AnQi CMS as an efficient

2025-11-06

How to easily insert block quotes, ordered lists, and unordered lists in Markdown editors?

As an experienced security CMS website operator, I know that content quality and readability are crucial for attracting and retaining users.In the process of content creation and editing, proficiency in using various formatting features of the Markdown editor can greatly enhance the clarity of content structure and the reading experience of users.Among them, block quotes, ordered lists, and unordered lists are indispensable elements for building content that is structured hierarchically and logically clear.The AnQi CMS built-in Markdown editor supports standard Markdown syntax

2025-11-06

Does the AnQi CMS Markdown editor support custom shortcuts to improve editing efficiency?

As an experienced security CMS website operations personnel, I fully understand the importance of content creation and editing efficiency in improving user experience and the overall operation effect of the website.About the question you raised regarding whether the AnqiCMS Markdown editor supports custom shortcuts to improve editing efficiency, I will elaborate in detail for you based on the existing features and documentation of AnqiCMS.### AnQiCMS Markdown Editor and Editing Efficiency: The Current Status of Custom Shortcuts An efficient editor is a powerful assistant for content creators and operators in a content management system

2025-11-06

How to implement code highlighting in Markdown in AnQiCMS?

In Anqi CMS, implementing Markdown syntax highlighting for code can greatly enhance the readability and professionalism of technical articles.As an experienced website operator, I will introduce how to enable and configure this feature in Anqi CMS. ### Enable Markdown Editor AnQi CMS supports Markdown editor, which is the basis for code highlighting.Firstly, make sure Markdown is enabled as the content editing mode in the background.

2025-11-06

When updating the CDN version of `MathJax` and `Mermaid`, does the Anqi CMS need to manually modify the script link?

AnQi CMS as an efficient and customizable content management system, is committed to providing users with rich content display capabilities.In content creation, to support complex mathematical formulas and flowcharts, etc., Anqi CMS introduces integration support for third-party libraries - MathJax and Mermaid through its built-in Markdown editor.These libraries are usually loaded through content delivery networks (CDN) to ensure ** performance and reliability.Follow the document guidance of Anqi CMS

2025-11-06

How does AnQi CMS handle external links and internal links in Markdown content, will it automatically add the `nofollow` attribute?

As an experienced CMS website operation personnel of AnQi, I am well aware of the core position of content in website operation, as well as the importance of search engine optimization for content dissemination.When handling daily content publishing, the management of links, especially the handling of external links and internal links, is a key aspect that we focus on when writing and optimizing Markdown content.Our CMS provides clear and SEO-friendly features in this area.

2025-11-06

What search engines does AnQiCMS mainly support for link push function?

As an experienced website operator who deeply understands the operation of AnQi CMS, I am very clear that the key to content reaching readers lies in whether it can be effectively discovered and indexed by search engines.AnQi CMS provides a convenient link push function to help website operators accelerate the search engine inclusion process of content.This feature connects with interfaces of major search engine platforms to achieve immediate notifications for content publishing, thereby enhancing the visibility of website content.The AnQi CMS link push function mainly supports two types: direct API push and JavaScript automatic submission

2025-11-06