[MarkdownViewer] Mermaid classDiagram with <<annotation>> fails with "Syntax error in text"

Open Beginner friendly
#2,054 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 4 days

@suhyun-nam is already working on this.

Since Nov 7, 2026.

  • #2059 by @suhyun-nam — open

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
75/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
csharp, html, javascript

Research direction

Read QuickLook.Plugin/QuickLook.Plugin.MarkdownViewer/Resources/md2html.html, focusing on the Mermaid fence handler and how its output is assigned to innerHTML. Check how the Markdown renderer exposes escapeHtml, then preview the supplied class diagram and confirm annotations such as <<interface>> render correctly while other Mermaid diagrams still work.

Written by the indexing model from the issue text.

Description

Environment

  • QuickLook version: 4.5.0
  • Plugin: QuickLook.Plugin.MarkdownViewer (bundled mermaid 11.13.0)
  • OS: Windows 11 24H2

Description

A Mermaid classDiagram that contains annotations such as <<interface>> fails to render in the Markdown preview and shows "Syntax error in text".
The same diagram renders correctly with mermaid 11.13.0 elsewhere (e.g. mermaid.live, standalone mermaid).

Steps to reproduce

Create a .md file with the following content and preview it with QuickLook:

classDiagram
  class IWeaponOutput {
    <<interface>>
    +Emit(ShotRequest request)
  }

Expected: Class box with the «interface» annotation.
Actual: "Syntax error in text".

Removing the <<interface>> line makes the diagram render correctly.

Cause

In QuickLook.Plugin/QuickLook.Plugin.MarkdownViewer/Resources/md2html.html, the mermaid fence content is inserted without HTML escaping:

if (lang === 'mermaid') {
  return '<div class="mermaid">' + str + '</div>';
}

The rendered output is then assigned to innerHTML, so the browser parses the diagram source as HTML. <<interface>> becomes an <interface> element (lowercased, with an auto-inserted closing tag), and mermaid receives corrupted text.
Any < followed by a letter in the diagram source is affected, e.g. <<ScriptableObject>>, <<enumeration>>, or generic text like List<T>.

Suggested fix

Escape the content before inserting it:

if (lang === 'mermaid') {
  return '<div class="mermaid">' + md.utils.escapeHtml(str) + '</div>';
}

(or markdownit().utils.escapeHtml(str) if md is not in scope at that point).
Mermaid decodes HTML entities when it reads the element's content, so the escaped source should render correctly.

Dominant language
C#
Stars
25.7k
Forks
1.4k
Avg merge
3d 19h
Merged PRs (30d)
3

Getting set up

  • No Dockerfile or Docker Compose file
  • Has a pull request template
  • No contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from QL-Win/QuickLook

All issues in QL-Win/QuickLook

Similar issues

More C# issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.