File size: 675 Bytes
b565d01
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
// Transform `:::output ... :::` into a <section class="code-output"> wrapper
// Requires remark-directive to be applied before this plugin

export default function remarkOutputContainer() {
  return (tree) => {
    const visit = (node) => {
      if (!node || typeof node !== 'object') return;

      if (node.type === 'containerDirective' && node.name === 'output') {
        node.data = node.data || {};
        node.data.hName = 'section';
        node.data.hProperties = { className: ['code-output'] };
      }

      const children = Array.isArray(node.children) ? node.children : [];
      for (const child of children) visit(child);
    };

    visit(tree);
  };
}