Fix unnecessary vertical whitespace in Mermaid graphs (#1415)

This commit is contained in:
Jonatan Kłosko 2022-09-16 15:52:04 +02:00 committed by GitHub
parent 3be3164e20
commit 9e43af7b4a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -45,6 +45,8 @@ class Markdown {
// can use morphdom's childrenOnly option
const wrappedHtml = `<div>${html}</div>`;
morphdom(this.container, wrappedHtml, { childrenOnly: true });
this._fixMermaidSpacing();
});
}
@ -83,6 +85,13 @@ class Markdown {
})
);
}
_fixMermaidSpacing() {
// A workaround for https://github.com/mermaid-js/mermaid/issues/1758
for (const svg of this.container.querySelectorAll(".mermaid svg")) {
svg.removeAttribute("height");
}
}
}
export default Markdown;
@ -171,7 +180,11 @@ function remarkPrepareMermaid(options) {
visit(ast, "code", (node, index, parent) => {
if (node.lang === "mermaid") {
node.type = "html";
node.value = `<div class="mermaid">${escapeHtml(node.value)}</div>`;
node.value = `
<div class="mermaid max-h-[600px] overflow-auto tiny-scrollbar">
${escapeHtml(node.value)}
</div>
`;
}
});
};