Просмотр исходного кода

create remark-plugin for inlinecode

reiji-h 1 год назад
Родитель
Сommit
80ef86c44d
1 измененных файлов с 25 добавлено и 0 удалено
  1. 25 0
      apps/app/src/services/renderer/remark-plugins/inline-codeblock.ts

+ 25 - 0
apps/app/src/services/renderer/remark-plugins/inline-codeblock.ts

@@ -0,0 +1,25 @@
+
+import type { Schema as SanitizeOption } from 'hast-util-sanitize';
+import type { InlineCode } from 'mdast';
+import type { Plugin } from 'unified';
+import { visit } from 'unist-util-visit';
+
+const rewriteNode = (node: InlineCode) => {
+  const data = node.data ?? (node.data = {});
+  data.hName = 'inlinecode';
+};
+
+
+export const remarkPlugin: Plugin = () => {
+  return (tree) => {
+    visit(tree, (node) => {
+      if (node.type === 'inlineCode') {
+        rewriteNode(node as InlineCode);
+      }
+    });
+  };
+};
+
+export const sanitizeOption: SanitizeOption = {
+  tagNames: ['inlinecode'],
+};