feat: support remark directive

This commit is contained in:
DIYgod
2022-10-03 16:17:45 +01:00
parent e4f48cbc2e
commit bca1eaa7c7
3 changed files with 58 additions and 1 deletions
+2
View File
@@ -79,6 +79,8 @@
"rehype-react": "^7.1.1",
"rehype-sanitize": "^5.0.1",
"rehype-stringify": "^9.0.3",
"remark-directive": "^2.0.1",
"remark-directive-rehype": "^0.4.2",
"remark-frontmatter": "^4.0.1",
"remark-gfm": "^3.0.1",
"remark-parse": "^10.0.1",
+50
View File
@@ -99,6 +99,8 @@ specifiers:
rehype-react: ^7.1.1
rehype-sanitize: ^5.0.1
rehype-stringify: ^9.0.3
remark-directive: ^2.0.1
remark-directive-rehype: ^0.4.2
remark-frontmatter: ^4.0.1
remark-gfm: ^3.0.1
remark-parse: ^10.0.1
@@ -185,6 +187,8 @@ dependencies:
rehype-react: 7.1.1_@types+react@18.0.21
rehype-sanitize: 5.0.1
rehype-stringify: 9.0.3
remark-directive: 2.0.1
remark-directive-rehype: 0.4.2
remark-frontmatter: 4.0.1
remark-gfm: 3.0.1
remark-parse: 10.0.1
@@ -7412,6 +7416,17 @@ packages:
unist-util-visit: 4.1.1
dev: false
/mdast-util-directive/2.2.1:
resolution: {integrity: sha512-yZRRuaulzc6bM4IOyZfkOrVs+9Sf1BC+rldRXJyl/Ej6S/6ewQQ9jt75HvEoqZZ4m9ealVTHiS4MP2GRUE7INA==}
dependencies:
'@types/mdast': 3.0.10
'@types/unist': 2.0.6
mdast-util-to-markdown: 1.3.0
parse-entities: 4.0.0
stringify-entities: 4.0.3
unist-util-visit-parents: 5.1.1
dev: false
/mdast-util-find-and-replace/2.2.0:
resolution: {integrity: sha512-bz8hUWkMX7UcasORORcyBEsTKJ+dBiFwRPrm43hHC9NMRylIMLbfO5rwfeCN+UtY4AAi7s8WqXftb9eX6ZsqCg==}
dependencies:
@@ -7593,6 +7608,18 @@ packages:
uvu: 0.5.4
dev: false
/micromark-extension-directive/2.1.1:
resolution: {integrity: sha512-+7MYZ3a10cpPrQRg3530srFMSBx0EL7gQaJ3ekguOQFSlJHLikW15AphBmNxvCNdRSWTX1R8RepzjKQra8INQw==}
dependencies:
micromark-factory-space: 1.0.0
micromark-factory-whitespace: 1.0.0
micromark-util-character: 1.1.0
micromark-util-symbol: 1.0.1
micromark-util-types: 1.0.2
parse-entities: 4.0.0
uvu: 0.5.4
dev: false
/micromark-extension-frontmatter/1.0.0:
resolution: {integrity: sha512-EXjmRnupoX6yYuUJSQhrQ9ggK0iQtQlpi6xeJzVD5xscyAI+giqco5fdymayZhJMbIFecjnE2yz85S9NzIgQpg==}
dependencies:
@@ -9232,6 +9259,23 @@ packages:
unified: 10.1.2
dev: false
/remark-directive-rehype/0.4.2:
resolution: {integrity: sha512-T6e+IG+BwqU4++MK54vFb+KDFjs3a+tHeK6E0T0ctR1FSyngolfDtAEzqxHWlRzQZqGi2sB4DFXry6oqH87D/g==}
engines: {node: ^12.20.0 || ^14.13.1 || >=16.0.0}
dependencies:
hastscript: 7.0.2
unist-util-map: 3.1.2
dev: false
/remark-directive/2.0.1:
resolution: {integrity: sha512-oosbsUAkU/qmUE78anLaJePnPis4ihsE7Agp0T/oqTzvTea8pOiaYEtfInU/+xMOVTS9PN5AhGOiaIVe4GD8gw==}
dependencies:
'@types/mdast': 3.0.10
mdast-util-directive: 2.2.1
micromark-extension-directive: 2.1.1
unified: 10.1.2
dev: false
/remark-frontmatter/4.0.1:
resolution: {integrity: sha512-38fJrB0KnmD3E33a5jZC/5+gGAC2WKNiPw1/fdXJvijBlhA7RCsvJklrYJakS0HedninvaCYW8lQGf9C918GfA==}
dependencies:
@@ -10330,6 +10374,12 @@ packages:
resolution: {integrity: sha512-F5CZ68eYzuSvJjGhCLPL3cYx45IxkqXSetCcRgUXtbcm50X2L9oOWQlfUfDdAf+6Pd27YDblBfdtmsThXmwpbQ==}
dev: false
/unist-util-map/3.1.2:
resolution: {integrity: sha512-WLA2R6x/UaopedG2poaWLShf5LCi+BNa6mMkACdjft23PHou4v85PvZItjbO2XgXvukMP365PlL/DrbuMgr3eg==}
dependencies:
'@types/unist': 2.0.6
dev: false
/unist-util-position/4.0.3:
resolution: {integrity: sha512-p/5EMGIa1qwbXjA+QgcBXaPWjSnZfQ2Sc3yBEEfgPwsEmJd8Qh+DSk3LGnmOM4S1bY2C0AjmMnB8RuEYxpPwXQ==}
dependencies:
+6 -1
View File
@@ -18,6 +18,8 @@ import jsYaml from "js-yaml"
import rehypeReact from "rehype-react"
import { createElement, ReactElement } from "react"
import { Image } from "~/components/ui/Image"
import remarkDirective from "remark-directive"
import remarkDirectiveRehype from "remark-directive-rehype"
export type MarkdownEnv = {
excerpt: string
@@ -51,7 +53,6 @@ export const renderPageContent = (
const result = unified()
.use(remarkParse)
.use(rehypeStringify)
.use(remarkFrontmatter, ["yaml"])
.use(() => (tree) => {
const yaml = tree.children.find((node) => node.type === "yaml")
@@ -67,7 +68,10 @@ export const renderPageContent = (
.use(remarkGfm, {})
.use(remarkExcerpt, { env })
.use(remarkCallout)
.use(remarkDirective)
.use(remarkDirectiveRehype)
.use(remarkRehype, { allowDangerousHtml: true })
.use(rehypeStringify)
.use(rehypeRaw)
.use(rehypeImage, { env })
.use(rehypeSanitize, {
@@ -79,6 +83,7 @@ export const renderPageContent = (
...(defaultSchema.attributes?.div || []),
["className"],
["style"],
["id"],
],
code: [["className"]],
blockquote: allowedBlockquoteAttrs,