日本語|English

Hooks

Replace

[icon1][notice]

[person][nod nod]
const rules = [
  {
    test: /\[(.+?)\]\[(.+?)\]/,
    match: ([, a, b], h) => {
      return h(
        'div',
        {class: 'balloon'},
        h('img', {src: `./img/${a}.png`}),
        h('span', b),
      );
    },
  },
];

stringify(markdown, {
  partial: true,
  replace: rules,
});
<p><div class="balloon"><img src="./img/icon1.png"><span>Notice</span></div></p>
<p><div class="balloon"><img src="./img/person.png"><span>Nod nod</span></div></p>

Edit plugins

VFMがプロセッサを構築する直前に、内部で組み立てるunifiedプラグイン配列を editPlugins オプションで挿入・削除・置換します。以下はhast (Hypertext AST)段階の末尾へrehype-autolink-headingsを追加する例です。

import { VFM } from '@vivliostyle/vfm';
import rehypeAutolinkHeadings from 'rehype-autolink-headings';

const processor = VFM({
  editPlugins(plugins) {
    return {
      ...plugins,
      hastPlugins: [
        ...plugins.hastPlugins,
        [rehypeAutolinkHeadings, { behavior: 'append' }],
      ],
    };
  },
});

引数 plugins にはVFMが組み立てた組み込みプラグインの一覧が渡されます。

  • mdastPlugins: remark (Markdown AST)プラグイン。
  • mdastToHastHandlers: mdastからhastへの変換で使われるmdast-util-to-hastハンドラー。
  • hastPlugins: rehype (Hypertext AST)プラグイン。

戻り値が組み立て済みパイプラインを置き換えます。マイナー リリース間で挙動が安定しているのは、組み込みリストの先頭への追加と末尾への追加だけです。VFMはマイナーまたはパッチ リリースで組み込みプラグインの並べ替え・削除・挿入を行うことがあります。