没有不值得去解决的问题,也没有不值得去学习的技术!

Mermaid 11.9.0 Syntax Error in Text: Fix It by Quoting Node Text

Figure 1: The article front end displays "Syntax error in text", and the Mermaid version is 11.9.0

作者:

While organizing legacy WordPress posts recently, I ran into a Mermaid flowchart syntax issue.

The flowcharts in the article had been migrated to a MerPress Mermaid block, but they were not rendering correctly on the front end. Instead, the following appeared directly:

Plaintext
Syntax error in text
mermaid version 11.9.0
Figure 1: The article front end displays "Syntax error in text", and the Mermaid version is 11.9.0
Figure 1: The article front end displays Syntax error in text, and the Mermaid version is 11.9.0

At first, I thought the flowchart declaration was simply written incorrectly, but my actual troubleshooting revealed that the real key issue was not just on the first line.

The ultimately effective solution was:

Plaintext
A["节点文本"]

instead of:

Plaintext
A[节点文本]

This distinction is especially important when nodes contain function names like test(), main(), and go test(), as well as mixed Chinese and English text.

1. The first issue discovered: 流程图 TD

In the original Mermaid content, the first line was written as:

Plaintext
流程图 TD

This is, of course, not a valid Mermaid flowchart declaration.

Mermaid should use:

Plaintext
flowchart TD

or:

Plaintext
graph TD

So initially I changed:

Plaintext
流程图 TD

to:

Plaintext
flowchart TD

For example, the original code:

Plaintext
流程图 TD
    A[程序启动] --> B[主协程启动,执行go test()]
    B --> C[子协程test()启动,就绪态]
    B --> D[主协程执行自身for循环]

was modified to:

Plaintext
flowchart TD
    A[程序启动] --> B[主协程启动,执行go test()]
    B --> C[子协程test()启动,就绪态]
    B --> D[主协程执行自身for循环]

This modification itself was correct.

However, after saving and checking the front end again, the result was still:

Plaintext
Syntax error in text
mermaid version 11.9.0

In other words:

流程图 TD was indeed problematic, but it was not the only issue in this flowchart.

2. flowchart TD is now correct, so why is it still throwing an error?

Continuing to look at the flowchart code, I noticed that many nodes used this format:

Plaintext
B[主协程启动,执行go test()]

and:

Plaintext
C[子协程test()启动,就绪态]

as well as in other scenarios:

Plaintext
B[主协程启动,执行test()(无go关键字)]
Plaintext
C[test()输出hello,world 1]
Plaintext
H[main()输出hello:golang 1]

These node texts mixed:

Plaintext
test()
main()
go test()

along with:

  • Chinese characters;
  • English half-width parentheses ();
  • Chinese parentheses ();
  • commas;
  • colons;
  • numbers;
  • English function names.

At this point, continuing to focus only on:

Plaintext
flowchart TD

was no longer meaningful.

What really needed to be addressed was:

the node text formatting.

3. The truly effective solution: A["节点文本"]

The final approach I took was very simple:

Change:

Plaintext
A[节点文本]

uniformly to:

Plaintext
A["节点文本"]

For example:

Plaintext
B[主协程启动,执行go test()]

was modified to:

Plaintext
B["主协程启动,执行go test()"]

The original:

Plaintext
C[子协程test()启动,就绪态]

was modified to:

Plaintext
C["子协程test()启动,就绪态"]

As another example:

Plaintext
B[主协程启动,执行test()(无go关键字)]

was modified to:

Plaintext
B["主协程启动,执行test()(无go关键字)"]

This was the most crucial fix for this Syntax error in text issue.

In other words, this issue can be summarized very simply as changing:

Plaintext
A[节点文本]

to:

Plaintext
A["节点文本"]

4. Complete repaired Mermaid example

Using one of the goroutine execution flowcharts as an example, the original code was roughly:

Plaintext
flowchart TD
    A[程序启动] --> B[主协程启动,执行go test()]
    B --> C[子协程test()启动,进入就绪态]
    B --> D[主协程继续执行自身for循环]
    C --> E[子协程输出hello,world 1]
    D --> F[主协程输出hello:golang 1]
    E --> G[子协程休眠1秒,让出CPU,进入等待态]
    F --> H[主协程休眠1秒,让出CPU,进入等待态]
    G --> I[子协程休眠结束,进入就绪态,等待调度]
    H --> J[主协程休眠结束,进入就绪态,等待调度]
    I --> K[调度器分配执行权,子协程输出hello,world 2]
    J --> L[调度器分配执行权,主协程输出hello:golang 2]
    K --> M[子协程休眠1秒]
    L --> N[主协程休眠1秒]
    M --> O[重复执行,直到两者都执行10次]
    N --> O
    O --> P[主协程执行完毕,退出]
    O --> Q[子协程执行完毕,退出]
    P --> R[程序终止]
    Q --> R

It was finally modified to:

Plaintext
flowchart TD
    A["程序启动"] --> B["主协程启动,执行go test()"]
    B --> C["子协程test()启动,进入就绪态"]
    B --> D["主协程继续执行自身for循环"]
    C --> E["子协程输出hello,world 1"]
    D --> F["主协程输出hello:golang 1"]
    E --> G["子协程休眠1秒,让出CPU,进入等待态"]
    F --> H["主协程休眠1秒,让出CPU,进入等待态"]
    G --> I["子协程休眠结束,进入就绪态,等待调度"]
    H --> J["主协程休眠结束,进入就绪态,等待调度"]
    I --> K["调度器分配执行权,子协程输出hello,world 2"]
    J --> L["调度器分配执行权,主协程输出hello:golang 2"]
    K --> M["子协程休眠1秒"]
    L --> N["主协程休眠1秒"]
    M --> O["重复执行,直到两者都执行10次"]
    N --> O
    O --> P["主协程执行完毕,退出"]
    O --> Q["子协程执行完毕,退出"]
    P --> R["程序终止"]
    Q --> R

After the modifications were completed, the flowchart finally rendered correctly.

Figure 2: The repaired Mermaid flowchart displays correctly; go test(), test(), Chinese descriptions, and branch arrows all render normally
Figure 2: The repaired Mermaid flowchart displays correctly; go test(), test(), Chinese descriptions, and branch arrows all render normally

5. Why I will prioritize using A["节点文本"] from now on

Strictly speaking, not all Mermaid nodes must be written as:

Plaintext
A["节点文本"]

Some simple nodes, such as:

Plaintext
A[程序启动]

might parse correctly on their own.

However, for a technical blog, flowchart nodes often contain:

Plaintext
test()
main()
time.Sleep()
go test()
runtime.Gosched()
hello,world
hello:golang

along with mixed Chinese descriptions.

Having to judge every time:

  • which parenthesis might cause an issue;
  • which punctuation needs escaping;
  • which combination Mermaid 11.9.0 can accept properly;
  • and which combination might trigger a parsing error;

is unnecessary.

For standard text rectangle nodes, I prefer to just uniformly write them as:

Plaintext
A["节点文本"]

For example:

Plaintext
A["程序启动"]
B["主协程启动,执行go test()"]
C["子协程test()启动,就绪态"]
D["主协程执行自身for循环"]

This is much simpler.

6. Why I later processed the entire WordPress source code

At the time, this article did not just have one Mermaid flowchart; there were multiple MerPress Mermaid blocks.

Since the repair rule was already established as changing:

Plaintext
A[节点文本]

to:

Plaintext
A["节点文本"]

opening each flowchart one by one in the WordPress editor to modify them line by line would have been cumbersome and prone to missing a node.

So later, I directly copied the entire Gutenberg source code from the WordPress source code editor and handed it over to ChatGPT for one-pass processing.

A special note here:

Copying the entire Gutenberg source code was not a necessary step to fix the Mermaid errors.

It was only to:

modify all Mermaid flowcharts in the article at once, since I already knew how to fix them.

If an article only has one flowchart, you can simply modify it directly in the Mermaid block from:

Plaintext
A[节点文本]

to:

Plaintext
A["节点文本"]

There is no need to process the entire WordPress source code.

7. The actual troubleshooting sequence for this issue

Looking back at the whole process, here is what actually happened:

Plaintext
The front end displayed:

Syntax error in text
mermaid version 11.9.0

First, I discovered:

Plaintext
流程图 TD

So I changed it to:

Plaintext
flowchart TD

But it still threw an error.

Then I continued checking the nodes and found that:

Plaintext
B[主协程启动,执行go test()]

these types of nodes existed in large numbers.

Finally, I uniformly changed them to:

Plaintext
B["主协程启动,执行go test()"]

and the flowchart returned to normal.

So the issue this time was not:

flowchart TD was written incorrectly.

To be precise, it should be stated as:

The Mermaid source code had multiple syntax compatibility issues. After fixing the flowchart declaration, the node text still caused parsing failures; this was ultimately resolved by uniformly adding double quotes to the node text.

8. How I will handle Syntax error in text in the future

If I see:

Plaintext
Syntax error in text

again, I should still first check the flowchart declaration:

Plaintext
flowchart TD

or:

Plaintext
flowchart LR

to see if it is correct.

Next, I will check:

Plaintext
[]
()
{}

to see if any of these parentheses are incomplete.

Then I will focus on the node text.

For example, if I encounter:

Plaintext
A[test()]
Plaintext
B[执行go test()]
Plaintext
C[main()执行结束]

I will prioritize directly changing them to:

Plaintext
A["test()"]
B["执行go test()"]
C["main()执行结束"]

For standard text nodes in a technical blog, this can serve as a practical default rule.

9. This also supplements my legacy article migration rules

I encountered this issue while handling the format migration of legacy WordPress articles.

In the past, many flowcharts, terminal outputs, code snippets, and explanatory content were placed in legacy code blocks like SyntaxHighlighter.

During migration, not all content should be mechanically converted to Code Block Pro.

For example, actual flowchart content is better suited for conversion to:

Plaintext
MerPress / Mermaid

Therefore, migration validation cannot simply require:

Plaintext
Original SyntaxHighlighter count
=
New Code Block Pro count

A more reasonable minimum requirement should be:

Plaintext
SyntaxHighlighter = 0

The original content can be migrated into different formats based on its actual type:

Plaintext
Code Block Pro
Mermaid
Standard paragraphs
Other more appropriate Gutenberg blocks

But for Mermaid, an additional validation condition is needed:

It is not enough for the block to merely exist; the Mermaid source code must actually render.

Because:

HTML
<!-- wp:merpress/mermaidjs -->

Its existence only indicates that the Gutenberg block was created successfully.

If there are issues with the internal source code, the front end will still display:

Plaintext
Syntax error in text

So future Mermaid migration validation should include:

Plaintext
Mermaid block exists
+
Source code structure is correct
+
Front end renders normally

10. Summary

The error encountered this time was:

Plaintext
Syntax error in text
mermaid version 11.9.0

Initially, I found that the first line of the flowchart was written as:

Plaintext
流程图 TD

I changed it to:

Plaintext
flowchart TD

After that, the error persisted.

Upon further inspection, I finally determined that the truly effective solution was to change:

Plaintext
A[节点文本]

to:

Plaintext
A["节点文本"]

Especially when nodes contain:

Plaintext
test()
main()
go test()
time.Sleep()

or mixed Chinese and English text, parentheses, and punctuation, uniformly using double quotes is much safer.

So the most important takeaway this time is not the complex troubleshooting process, but simply this one rule:

Plaintext
flowchart TD
    A["节点文本"]

instead of:

Plaintext
flowchart TD
    A[节点文本]

The reason I later copied out the entire Gutenberg source code for processing was simply because the article contained multiple Mermaid flowcharts, making it convenient to modify them all at once; it was not a required step to resolve the issue.

Ultimately, the repaired flowcharts are now able to display correctly.

Figure 3: The finally repaired Mermaid 11.9.0 flowchart renders normally, and Syntax error in text no longer appears.

This also adds a very practical lesson for future legacy WordPress article migrations:

Prioritize using A["节点文本"] for standard Mermaid text nodes; do not wait for syntax errors to appear on the front end before dealing with them one by one.

需要长期技术维护或远程问题排查?

我是拥有 15+ 年经验的 PHP / Go 后端工程师,长期关注已有系统维护、Bug 修复、性能优化、服务器排查、WordPress 网站维护和小功能迭代。

如果你的项目遇到以下情况,可以先从一次小问题排查开始合作:

  • ✅ PHP / Laravel / Yii2 老项目无人维护
  • ✅ Go / Gin 后端接口需要排查或优化
  • ✅ WordPress 网站访问慢、报错或插件冲突
  • ✅ Nginx / MySQL / Redis / Linux 服务器异常
  • ✅ CDN / Cloudflare / DNS / HTTPS 配置问题
  • ✅ 需要长期远程技术支持或兼职维护

更多介绍请查看:关于我 & 合作

微信:13980074657
邮箱:shuijingwanwq@gmail.com
Telegram:@shuijingwan
GitHub:https://github.com/shuijingwan

评论

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

这个站点使用 Akismet 来减少垃圾评论。了解你的评论数据如何被处理