Dedent ui.mermaid content like ui.markdown does - #6012
Merged
Conversation
ui.markdown auto-dedents triple-quoted content via remove_indentation, but ui.mermaid only stripped outer whitespace. The discrepancy is most visible with Mermaid's YAML front-matter syntax (e.g. displayMode: compact), which requires --- markers at column 0 and breaks under any leading indent. Refs discussion #6011. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
The helper is no longer markdown-specific now that ui.mermaid uses it too, so promoting it to nicegui.helpers keeps imports clean and avoids cross-element dependencies. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
evnchn
approved these changes
Apr 30, 2026
Contributor
Author
|
@evnchn Yes, Claude couldn't come up with a counter example where existing Mermaid code would break after this change. 👍🏻 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Motivation
ui.markdownalready auto-dedents its content viaremove_indentation, butui.mermaidonly stripped outer whitespace.Identical triple-quoted strings therefore behaved differently between the two elements.
The discrepancy becomes a hard error with Mermaid's YAML front-matter (e.g.
displayMode: compactfor compact-mode Gantt charts), which requires---markers at column 0.Any leading indentation makes Mermaid bail out with "Diagrams beginning with --- are not valid. If you were trying to use a YAML front-matter, please use un-indented
---blocks".Refs discussion #6011.
Implementation
remove_indentationfromnicegui/elements/markdown.pytonicegui/helpers/strings.pyand re-export it vianicegui.helpers.It is no longer markdown-specific now that
ui.mermaiduses it as well, and lifting it removes the cross-element dependency frommermaid→markdown.code,markdown,restructured_text,tests/test_vbuild.py, three website files) to import from the new location.remove_indentationinsideMermaid._handle_content_change, replacing the previouscontent.strip()calls.Since
remove_indentationalready drops leading whitespace-only lines and produces no leading whitespace on the first line, no extra.strip()is needed; Mermaid is fine with any trailing whitespace.test_mermaid_with_yaml_frontmatterthat places a YAML front-matter block inside an indented triple-quoted string and verifies the chart renders without a syntax error.This is not a breaking change in practice: Mermaid is whitespace-insensitive at the start of lines for every diagram type, so removing a uniform leading indent is a no-op for existing diagrams.
The four demos in
mermaid_documentation.pycontinue to render identically.Progress