-
Notifications
You must be signed in to change notification settings - Fork 678
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: clickable entry id in ai daily
- Loading branch information
Showing
5 changed files
with
108 additions
and
8 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
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
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,42 @@ | ||
import { | ||
MarkdownLink, | ||
} from "@renderer/components/ui/markdown/renderers" | ||
import { toJsxRuntime } from "hast-util-to-jsx-runtime" | ||
import { createElement } from "react" | ||
import { Fragment, jsx, jsxs } from "react/jsx-runtime" | ||
import rehypeSanitize from "rehype-sanitize" | ||
import rehypeStringify from "rehype-stringify" | ||
import remarkParse from "remark-parse" | ||
import remarkRehype from "remark-rehype" | ||
import { unified } from "unified" | ||
import { VFile } from "vfile" | ||
|
||
export const parseMarkdown = async ( | ||
content: string, | ||
) => { | ||
const file = new VFile(content) | ||
|
||
const pipeline = unified() | ||
.use(remarkParse) | ||
.use(remarkRehype) | ||
.use(rehypeSanitize) | ||
.use(rehypeStringify) | ||
|
||
const tree = pipeline.parse(content) | ||
|
||
const hastTree = pipeline.runSync(tree, file) | ||
|
||
return { | ||
content: toJsxRuntime(hastTree, { | ||
Fragment, | ||
ignoreInvalidStyle: true, | ||
jsx: (type, props, key) => jsx(type as any, props, key), | ||
jsxs: (type, props, key) => jsxs(type as any, props, key), | ||
passNode: true, | ||
components: { | ||
a: ({ node, ...props }) => | ||
createElement(MarkdownLink, { ...props } as any), | ||
}, | ||
}), | ||
} | ||
} |
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