All files / src/plugins retrieveMeta.ts

50% Statements 4/8
44.44% Branches 4/9
100% Functions 3/3
50% Lines 4/8

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20            1x 4x 4x 10x                    
import type { Plugin } from 'unified';
import type { Root, RootContent } from 'hast';
import { visit } from 'unist-util-visit';
 
export interface RetrieveMetaOptions {}
 
export const retrieveMeta: Plugin<[RetrieveMetaOptions?], Root> = (options = {}) => {
  return (tree) => {
    visit(tree, (node: Root | RootContent) => {
      Iif (node.type === 'element' && node.tagName === 'code' && node.properties && node.properties['dataMeta']) {
        if (!node.data) {
          node.data = {};
        }
        node.data.meta = node.properties['dataMeta'];
        delete node.properties['dataMeta'];
      }
    });
  };
};