[MarkdownViewer] Mermaid classDiagram with <<annotation>> fails with "Syntax error in text"
Maintainers usually reply within 4 days
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
- Domain
- desktop, documentation
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
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from QL-Win/QuickLook
-
Difficulty 1/5 Under an hour Newbie friendliness 78/100
Maintainers usually reply within 4 days
-
Difficulty 2/5 1-3 hours Newbie friendliness 60/100
QL-Win/QuickLook#2028 · 3 comments ·
Maintainers usually reply within 4 days
-
[Bug] If the first character entered into the search box is a space, the preview window will close.Possibly taken @MORTEM3845 claimed this 25 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 67/100
Maintainers usually reply within 4 days
-
Difficulty 2/5 1-3 hours Newbie friendliness 57/100
Maintainers usually reply within 4 days
-
Emptying the Recycle Bin stops when the preview window is closedMay be free again A pull request for this issue was closed without being merged. Open
Difficulty 3/5 1-2 days Newbie friendliness 57/100
Maintainers usually reply within 4 days
All issues in QL-Win/QuickLook
Similar issues
-
Support Flux ignore rules (drift detection ignore paths) in Microsoft.KubernetesConfiguration schemaOpen
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
Azure/azure-resource-manager-schemas#3921 ·
Maintainers usually reply within 1 day
-
text-align: justify is ignored in HTML to PDF conversionPossibly taken @PrzemyslawKlys claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
Maintainers usually reply within 1 day
-
documentation
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
-
area/backend type/bug
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
umbraco/Umbraco-CMS#24668 · 1 comment ·
Maintainers usually reply within 1 day