summaryrefslogtreecommitdiff
path: root/src/build/special_box.mjs
blob: 0b284ec6efb481aff11eb2d45435b78bddc9e52a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import {visit} from 'unist-util-visit';

// This plugin is an example to let users write HTML with directives.
// It’s informative but rather useless.
// See below for others examples.
/** @type {import('unified').Plugin<[], import('mdast').Root>} */
export default function specialBox() {
  return tree => {
    visit(tree, node => {
      if (node.type === 'containerDirective' && (
        node.name === 'attention'
        || node.name === 'question'
        || node.name === 'information')) {
        const data = node.data || (node.data = {});

        data.hName = 'div';
        data.hProperties = {
          className: 'special-box ' + node.name,
        };
      }
    });
  };
}