Skip to content

Commit

Permalink
[#63734] support mermaid diagrams
Browse files Browse the repository at this point in the history
  • Loading branch information
Trzcin committed Aug 6, 2024
1 parent 45453f9 commit e9f23c6
Show file tree
Hide file tree
Showing 3 changed files with 450 additions and 1 deletion.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"test": "PW_TEST_HTML_REPORT_OPEN=never playwright test -c tests/playwright.config.js --reporter html"
},
"dependencies": {
"@agoose77/markdown-it-mermaid": "^1.1.0",
"@codemirror/commands": "^6.2.4",
"@codemirror/lang-markdown": "^6.2.3",
"@codemirror/merge": "@6.0.0",
Expand Down
8 changes: 7 additions & 1 deletion src/hooks/useText.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import markdownIt from "markdown-it";
import { markdownReplacer, useCustomRoles } from "./markdownReplacer";
import { useCallback, useEffect, useMemo, useReducer, useState } from "preact/hooks";
import IMurMurHash from "imurmurhash";
import markdownItMermaid from "@agoose77/markdown-it-mermaid";

const countOccurences = (str, pattern) => (str?.match(pattern) || []).length;

Expand Down Expand Up @@ -62,7 +63,12 @@ export const useText = ({ initialText, transforms, customRoles, preview }) => {
}, []);

const markdown = useMemo(
() => markdownIt({ breaks: true, linkify: true }).use(markdownitDocutils).use(markdownReplacer(transforms)).use(useCustomRoles(customRoles)),
() =>
markdownIt({ breaks: true, linkify: true })
.use(markdownitDocutils)
.use(markdownReplacer(transforms))
.use(useCustomRoles(customRoles))
.use(markdownItMermaid),
[],
);

Expand Down
Loading

0 comments on commit e9f23c6

Please sign in to comment.