forked from vrm-c/vrm.dev
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rehype_plugin.ts
54 lines (48 loc) · 1.33 KB
/
rehype_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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import unified from "unified";
import { Paragraph } from "mdast";
import { Node, Parent } from "unist";
import { VFileCompatible, VFile } from "vfile";
import { inspect } from "unist-util-inspect";
import { visit } from "unist-util-visit";
// ESM port of https://github.com/tkhquang/gridsome-remark-figure-caption
import { whitespace } from "hast-util-whitespace";
import { remove } from "unist-util-remove";
import { fromMarkdown } from "mdast-util-from-markdown";
// https://github.com/josestg/rehype-figure
function rehype_figure(
node: any, // this is mdx node
index: number,
parent: Parent | undefined
) {
if (node.type != 'mdxJsxTextElement') {
return;
}
if (node.name == 'img') {
return;
}
// if(node.tagName!="img"){
// return;
// }
console.log(inspect(node));
}
// [unified を使って Markdown を拡張する](https://zenn.dev/januswel/articles/745787422d425b01e0c1)
const nop: unified.Plugin = () => {
return (tree: Node, file: VFileCompatible) => {
// @ts-ignore
const path = file.path;
if (!path) {
console.log(inspect(file));
return;
}
if (!path.endsWith("univrm_export.md")) {
// debug
console.log(file, inspect(tree));
return;
}
// process
console.log(inspect(tree));
// @type-ignore
visit(tree, rehype_figure);
}
};
export default nop