mirror of https://github.com/usememos/memos
feat: add mermaid support in codeblock (#2971)
parent
a86117f613
commit
03d67d5a00
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,27 @@
|
||||
import mermaid from "mermaid";
|
||||
import { useEffect, useRef } from "react";
|
||||
|
||||
interface Props {
|
||||
content: string;
|
||||
}
|
||||
|
||||
const MermaidBlock: React.FC<Props> = ({ content }: Props) => {
|
||||
const mermaidDockBlock = useRef<null>(null);
|
||||
|
||||
useEffect(() => {
|
||||
if (!mermaidDockBlock.current) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Render mermaid when mounted
|
||||
mermaid.run({
|
||||
nodes: [mermaidDockBlock.current],
|
||||
});
|
||||
});
|
||||
|
||||
return (
|
||||
<pre ref={mermaidDockBlock} className="w-full p-2 whitespace-pre-wrap relative" dangerouslySetInnerHTML={{ __html: content }}></pre>
|
||||
);
|
||||
};
|
||||
|
||||
export default MermaidBlock;
|
Loading…
Reference in New Issue