From 9b9d86474bedd244daa45f4d76704b182d6a99ad Mon Sep 17 00:00:00 2001
From: Jacky Zhao <j.zhao2k19@gmail.com>
Date: Tue, 19 Dec 2023 19:01:55 +0000
Subject: [PATCH] fix: mermaid rendering fix from upstream
---
quartz/plugins/transformers/ofm.ts | 31 +++++++++++++------------------
1 files changed, 13 insertions(+), 18 deletions(-)
diff --git a/quartz/plugins/transformers/ofm.ts b/quartz/plugins/transformers/ofm.ts
index 9adeff4..d0f2ee5 100644
--- a/quartz/plugins/transformers/ofm.ts
+++ b/quartz/plugins/transformers/ofm.ts
@@ -1,5 +1,5 @@
import { QuartzTransformerPlugin } from "../types"
-import { Root, Html, BlockContent, DefinitionContent, Paragraph } from "mdast"
+import { Root, Html, BlockContent, DefinitionContent, Paragraph, Code } from "mdast"
import { Element, Literal, Root as HtmlRoot } from "hast"
import { ReplaceFunction, findAndReplace as mdastFindReplace } from "mdast-util-find-and-replace"
import { slug as slugAnchor } from "github-slugger"
@@ -423,25 +423,15 @@
})
}
- return plugins
- },
- htmlPlugins() {
- const plugins: PluggableList = [rehypeRaw]
-
if (opts.mermaid) {
plugins.push(() => {
- return (tree: HtmlRoot, _file) => {
- visit(tree, "element", (node) => {
- if (node.tagName === "pre") {
- const firstChild = node.children[0]
- if (firstChild && firstChild.type === "element" && firstChild.tagName === "code") {
- const code = firstChild
- const isMermaidBlock =
- (code.properties["className"] as Array<string>)?.[0] === "language-mermaid"
- if (isMermaidBlock) {
- node.children = code.children
- node.properties.className = ["mermaid"]
- }
+ return (tree: Root, _file) => {
+ visit(tree, "code", (node: Code) => {
+ if (node.lang === "mermaid") {
+ node.data = {
+ hProperties: {
+ className: ["mermaid"],
+ },
}
}
})
@@ -449,6 +439,11 @@
})
}
+ return plugins
+ },
+ htmlPlugins() {
+ const plugins: PluggableList = [rehypeRaw]
+
if (opts.parseBlockReferences) {
plugins.push(() => {
const inlineTagTypes = new Set(["p", "li"])
--
Gitblit v1.10.0