-
Notifications
You must be signed in to change notification settings - Fork 3
/
plugin.ts
28 lines (24 loc) · 950 Bytes
/
plugin.ts
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
import type { Blockquote, Parent } from "mdast";
import type { ContainerDirective } from "mdast-util-directive";
import type { Plugin } from "unified";
import { visit } from "unist-util-visit";
import { mapGithubAlertTypeToDirectiveName } from "./map-github-alert-type-to-directive-name.js";
import { parseGithubAlertBlockquote } from "./parse-github-alert-blockquote.js";
export const remarkGithubAdmonitionsToDirectives: Plugin = () => {
return (tree) => {
visit(
tree,
"blockquote",
(node: Blockquote, index: number, parent: Parent) => {
const githubAlert = parseGithubAlertBlockquote(node);
if (githubAlert === false) return;
const directive: ContainerDirective = {
type: "containerDirective",
name: mapGithubAlertTypeToDirectiveName(githubAlert.type),
children: githubAlert.children,
};
parent.children[index] = directive;
},
);
};
};