inline-codeblock.ts 594 B

12345678910111213141516171819202122232425
  1. import type { Schema as SanitizeOption } from 'hast-util-sanitize';
  2. import type { InlineCode } from 'mdast';
  3. import type { Plugin } from 'unified';
  4. import { visit } from 'unist-util-visit';
  5. const rewriteNode = (node: InlineCode) => {
  6. const data = node.data ?? (node.data = {});
  7. data.hName = 'inlinecode';
  8. };
  9. export const remarkPlugin: Plugin = () => {
  10. return (tree) => {
  11. visit(tree, (node) => {
  12. if (node.type === 'inlineCode') {
  13. rewriteNode(node as InlineCode);
  14. }
  15. });
  16. };
  17. };
  18. export const sanitizeOption: SanitizeOption = {
  19. tagNames: ['inlinecode'],
  20. };