Created
August 17, 2022 15:58
-
-
Save ansidev/5bf2e3d91fdd339b573584552147eb21 to your computer and use it in GitHub Desktop.
Table of Content Builder for Markdown (use with vite-plugin-md)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// src/builders/toc-builder.ts | |
import { createBuilder, PipelineStage } from "@yankeeinlondon/builder-api" | |
import Toc from 'markdown-it-toc-done-right' | |
const tocBuilder = createBuilder('toc', PipelineStage.parser) | |
.options() | |
.initializer() | |
.handler( | |
async (payload, _) => { | |
payload.parser.use(Toc) | |
payload.md = '[[toc]]\n\n' + payload.md | |
return payload | |
} | |
) | |
.meta() | |
export default tocBuilder |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { defineConfig } from 'vite' | |
import Markdown from 'vite-plugin-md' | |
import toc from './src/builders/toc-builder' | |
export default defineConfig({ | |
// Other Vite configs | |
plugins: [ | |
// Other plugin configs | |
// https://github.com/antfu/vite-plugin-vue-markdown | |
Markdown({ | |
// Other plugin options | |
builders: [ | |
// Other builders | |
toc(), | |
], | |
}), | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment