Skip to content

Commit

Permalink
feat: add remark code block escape template
Browse files Browse the repository at this point in the history
  • Loading branch information
RyoJerryYu committed Apr 29, 2024
1 parent 0c03cae commit 1d08a8c
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 0 deletions.
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);
});
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 src/core/rendering/complex-plugins/code-block-escape/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export type CodeBlockProps = {
lang: string;
meta: string;
value: string;
};

0 comments on commit 1d08a8c

Please sign in to comment.