blob: f1631b6c5fe9ef69e31345127ba4dcd7e543e657 (
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
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
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 === "note" ||
node.name === "information")
) {
const data = node.data || (node.data = {});
data.hName = "div";
data.hProperties = {
className: "special-box " + node.name,
};
}
if (node.type === "containerDirective" && node.name === "details") {
if (node.children.length > 0 && node.children[0].type == "paragraph") {
node.children[0] = {
type: "containerDirective",
data: {
hName: "summary",
},
children: node.children[0].children,
};
const data = node.data || (node.data = {});
data.hName = "details";
}
}
});
};
}
|