Skip to content

Commit f4a7936

Browse files
authored
Fix Mermaid flowchart rendering (#3147)
1 parent 7189e8e commit f4a7936

2 files changed

Lines changed: 30 additions & 1 deletion

File tree

docs/_static/mermaid-normalize.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
(function () {
2+
function dedent(text) {
3+
const lines = text.replace(/\s+$/u, "").split("\n");
4+
const indents = lines
5+
.filter((line) => line.trim())
6+
.map((line) => line.match(/^\s*/u)[0].length);
7+
8+
if (!indents.length) {
9+
return text;
10+
}
11+
12+
const indent = Math.min(...indents);
13+
return lines.map((line) => line.slice(indent)).join("\n");
14+
}
15+
16+
function normalizeMermaidBlocks() {
17+
document.querySelectorAll("pre.mermaid").forEach((block) => {
18+
block.textContent = dedent(block.textContent);
19+
});
20+
}
21+
22+
if (document.readyState === "loading") {
23+
document.addEventListener("DOMContentLoaded", normalizeMermaidBlocks, {
24+
once: true,
25+
});
26+
} else {
27+
normalizeMermaidBlocks();
28+
}
29+
})();

docs/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
pygments_style, pygments_dark_style = "sphinx", "monokai"
4949
html_static_path = ["_static"]
5050
html_css_files = ["custom.css"]
51-
html_js_files = ["rtd-search.js"]
51+
html_js_files = ["mermaid-normalize.js", "rtd-search.js"]
5252
html_favicon = "_static/virtualenv.svg"
5353
html_theme_options = {
5454
"light_logo": "virtualenv.png",

0 commit comments

Comments
 (0)