-
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.
feat: add remark code block escape template
- Loading branch information
1 parent
0c03cae
commit 1d08a8c
Showing
3 changed files
with
35 additions
and
0 deletions.
There are no files selected for viewing
7 changes: 7 additions & 0 deletions
7
src/core/rendering/complex-plugins/code-block-escape/remark-code-block-escape.test.ts
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,7 @@ | ||
import remarkParse from "remark-parse"; | ||
import remarkRehype from "remark-rehype"; | ||
import { unified } from "unified"; | ||
|
||
test("code fields", () => { | ||
unified().use(remarkParse).use(remarkRehype); | ||
}); |
23 changes: 23 additions & 0 deletions
23
src/core/rendering/complex-plugins/code-block-escape/remark-code-block-escape.ts
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,23 @@ | ||
import { Code, Parent } from "mdast"; | ||
import unified from "unified"; | ||
import { visit } from "unist-util-visit"; | ||
|
||
export type RemarkCodeBlockEscapeOptions = {}; | ||
|
||
export const remarkCodeBlockEscape: unified.Plugin< | ||
[RemarkCodeBlockEscapeOptions?] | ||
> = (options) => { | ||
return (tree) => { | ||
visit(tree, "code", (node: Code, index: number, parent: Parent) => { | ||
node.data; | ||
node.lang; | ||
node.meta; | ||
if (node.lang === "code-block-escape") { | ||
parent.children.splice(index, 1, { | ||
type: "text", | ||
value: node.value, | ||
}); | ||
} | ||
}); | ||
}; | ||
}; |
5 changes: 5 additions & 0 deletions
5
src/core/rendering/complex-plugins/code-block-escape/types.ts
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,5 @@ | ||
export type CodeBlockProps = { | ||
lang: string; | ||
meta: string; | ||
value: string; | ||
}; |