icon

nazo6.dev

一覧に戻る
2023/7/3 1 min read

remarkのプラグイン例


remarkプラグイン用テンプレート

import { Plugin, unified } from "unified";
import remarkParse from "remark-parse";
import remarkStringify from "remark-stringify";
import remarkFrontmatter from "remark-frontmatter";
import remarkParseFrontmatter from "remark-parse-frontmatter";
import { visit } from "unist-util-visit";
import { Root } from "mdast";
import * as fs from "fs/promises";
 
const remarkPlugin: Plugin<[], Root> = () => {
  return (tree) => {
    visit(tree, (node) => {
      console.log(node);
    });
  };
};
 
main();
 
async function main() {
  const file = await unified()
    .use(remarkParse)
    .use(remarkPlugin)
    .use(remarkStringify)
    .use(remarkFrontmatter, ["yaml", "toml"])
    .use(remarkParseFrontmatter)
    .process(await fs.readFile("./home.md", { encoding: "utf8" }));
 
  console.log(String(file));
}
 
Share this article:
一覧に戻る

© 2025 nazo6. All rights reserved.