@@ -24,7 +24,6 @@ export const PageContent: React.FC<{
|
||||
}) => {
|
||||
const $articleRef = useRef<HTMLDivElement>(null)
|
||||
useCodeCopy()
|
||||
useMermaid($articleRef)
|
||||
|
||||
const inParsedContent = useMemo(() => {
|
||||
if (parsedContent) {
|
||||
@@ -36,6 +35,7 @@ export const PageContent: React.FC<{
|
||||
return null
|
||||
}
|
||||
}, [content, parsedContent])
|
||||
useMermaid($articleRef, inParsedContent?.element)
|
||||
|
||||
return (
|
||||
<div
|
||||
|
||||
@@ -17,3 +17,7 @@ pre {
|
||||
@apply inline-block w-4 text-right mr-5 -ml-2 text-zinc-400;
|
||||
content: attr(line);
|
||||
}
|
||||
|
||||
pre.mermaid {
|
||||
@apply bg-transparent flex justify-center;
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ declare global {
|
||||
|
||||
export const useMermaid = (
|
||||
contentRef: React.MutableRefObject<HTMLElement | null>,
|
||||
deps: any,
|
||||
) => {
|
||||
useEffect(() => {
|
||||
if (contentRef.current) {
|
||||
@@ -28,5 +29,5 @@ export const useMermaid = (
|
||||
}
|
||||
})
|
||||
}
|
||||
}, [contentRef])
|
||||
}, [contentRef, deps])
|
||||
}
|
||||
|
||||
@@ -6,7 +6,12 @@ import { visit } from "unist-util-visit"
|
||||
export const rehypeWrapCode: Plugin<Array<void>, Root> = () => {
|
||||
return (tree) => {
|
||||
visit(tree, { type: "element", tagName: "pre" }, (node, index, parent) => {
|
||||
if (parent && typeof index === "number") {
|
||||
if (
|
||||
parent &&
|
||||
typeof index === "number" &&
|
||||
// @ts-ignore
|
||||
node?.properties?.className?.[0] !== "mermaid"
|
||||
) {
|
||||
const wrapper = u("element", {
|
||||
tagName: "div",
|
||||
properties: {
|
||||
|
||||
@@ -7,7 +7,7 @@ export const remarkMermaid: Plugin<Array<void>, Root> = () => (tree, file) => {
|
||||
if (node.type === "code" && node.lang === "mermaid") {
|
||||
// @ts-ignore
|
||||
node.type = "html"
|
||||
node.value = `<div class="mermaid">${node.value}</div>`
|
||||
node.value = `<pre class="mermaid" data-mermaid='true'>${node.value}</pre>`
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user