-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from zhumeisongsong/feature/render-markdown
✨ Render markdown with mermaid graph
- Loading branch information
Showing
12 changed files
with
171 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
name: CI | ||
|
||
on: | ||
pull_request: | ||
# Allows you to run this workflow manually from the Actions tab | ||
workflow_dispatch: | ||
|
||
jobs: | ||
setup: | ||
uses: zhumeisongsong/shared-actions/.github/workflows/reusable-pnpm-setup.yml@main | ||
|
||
lint: | ||
needs: setup | ||
uses: zhumeisongsong/shared-actions/.github/workflows/reusable-eslint.yml@main | ||
|
||
type-check: | ||
needs: setup | ||
uses: zhumeisongsong/shared-actions/.github/workflows/reusable-ts-type-check.yml@main | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
{ | ||
"cSpell.words": [ | ||
"dompurify", | ||
"Nextjs" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
"use client"; | ||
import markdownToHtml from "@/lib/markdown-to-html"; | ||
import { useEffect, useState } from "react"; | ||
import DOMPurify from 'dompurify'; | ||
|
||
import markdownStyles from "./markdown-styles.module.css"; | ||
|
||
type Props = { | ||
content: string; | ||
}; | ||
|
||
export function BodyMarkdown({ content }: Props) { | ||
const [html, setHtml] = useState<string>(""); | ||
useEffect(() => { | ||
markdownToHtml(content).then((html) => { | ||
setHtml(html); | ||
}); | ||
}, [content]); | ||
|
||
return ( | ||
<div | ||
className={markdownStyles["markdown"]} | ||
dangerouslySetInnerHTML={{ __html: DOMPurify.sanitize(html) }} | ||
/> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
"use client"; | ||
import mermaid from "mermaid"; | ||
import { useEffect, useRef } from "react"; | ||
|
||
import mermaidStyles from "./mermaid-styles.module.css"; | ||
|
||
type Props = { | ||
graph: string; | ||
}; | ||
|
||
export function BodyMermaid({ graph }: Props) { | ||
const chartRef = useRef<HTMLDivElement>(null); | ||
|
||
useEffect(() => { | ||
if (chartRef.current) { | ||
try { | ||
mermaid.contentLoaded(); | ||
} catch (error) { | ||
console.error("Error rendering mermaid diagram:", error); | ||
// Optionally, you could set an error state here and render an error message | ||
} | ||
} | ||
}, [graph]); | ||
|
||
// Basic validation | ||
if (!graph || typeof graph !== "string") { | ||
return <div>Invalid graph data</div>; | ||
} | ||
|
||
return ( | ||
<div ref={chartRef} className={mermaidStyles["mermaid"]}> | ||
<div className="mermaid">{graph}</div> | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.mermaid { | ||
text-align: center; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters