refactor: migrate markdown toc plugin (#1093) (#1207)

pull/1213/head
meteorlxy 2 years ago committed by GitHub
parent 8b6aef7844
commit 0664006e92
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -148,10 +148,8 @@ interface MarkdownOptions extends MarkdownIt.Options {
lineNumbers?: boolean lineNumbers?: boolean
// markdown-it-anchor plugin options. // markdown-it-anchor plugin options.
// See: https://github.com/valeriangalliat/markdown-it-anchor // See: https://github.com/valeriangalliat/markdown-it-anchor#usage
anchor?: { anchor?: anchorPlugin.AnchorOptions
permalink?: anchor.AnchorOptions['permalink']
}
// markdown-it-attrs plugin options. // markdown-it-attrs plugin options.
// See: https://github.com/arve0/markdown-it-attrs // See: https://github.com/arve0/markdown-it-attrs
@ -162,9 +160,9 @@ interface MarkdownOptions extends MarkdownIt.Options {
disable?: boolean disable?: boolean
} }
// markdown-it-toc-done-right plugin options // @mdit-vue/plugin-toc plugin options.
// See: https://github.com/nagaozen/markdown-it-toc-done-right // See: https://github.com/mdit-vue/mdit-vue/tree/main/packages/plugin-toc#options
toc?: any toc?: TocPluginOptions
// Configure the Markdown-it instance. // Configure the Markdown-it instance.
config?: (md: MarkdownIt) => void config?: (md: MarkdownIt) => void

@ -435,12 +435,13 @@ const anchor = require('markdown-it-anchor')
module.exports = { module.exports = {
markdown: { markdown: {
// options for markdown-it-anchor // options for markdown-it-anchor
// https://github.com/valeriangalliat/markdown-it-anchor#permalinks // https://github.com/valeriangalliat/markdown-it-anchor#usage
anchor: { anchor: {
permalink: anchor.permalink.headerLink() permalink: anchor.permalink.headerLink()
}, },
// options for markdown-it-toc-done-right // options for @mdit-vue/plugin-toc
// https://github.com/mdit-vue/mdit-vue/tree/main/packages/plugin-toc#options
toc: { level: [1, 2] }, toc: { level: [1, 2] },
config: (md) => { config: (md) => {

@ -92,7 +92,8 @@
"vue": "^3.2.37" "vue": "^3.2.37"
}, },
"devDependencies": { "devDependencies": {
"@mdit-vue/plugin-component": "^0.9.0", "@mdit-vue/plugin-component": "^0.9.2",
"@mdit-vue/plugin-toc": "^0.9.2",
"@rollup/plugin-alias": "^3.1.9", "@rollup/plugin-alias": "^3.1.9",
"@rollup/plugin-commonjs": "^22.0.2", "@rollup/plugin-commonjs": "^22.0.2",
"@rollup/plugin-json": "^4.1.0", "@rollup/plugin-json": "^4.1.0",
@ -136,7 +137,6 @@
"markdown-it-attrs": "^4.1.4", "markdown-it-attrs": "^4.1.4",
"markdown-it-container": "^3.0.0", "markdown-it-container": "^3.0.0",
"markdown-it-emoji": "^2.0.2", "markdown-it-emoji": "^2.0.2",
"markdown-it-toc-done-right": "^4.2.0",
"micromatch": "^4.0.5", "micromatch": "^4.0.5",
"minimist": "^1.2.6", "minimist": "^1.2.6",
"npm-run-all": "^4.1.5", "npm-run-all": "^4.1.5",

@ -6,7 +6,8 @@ importers:
specifiers: specifiers:
'@docsearch/css': ^3.2.1 '@docsearch/css': ^3.2.1
'@docsearch/js': ^3.2.1 '@docsearch/js': ^3.2.1
'@mdit-vue/plugin-component': ^0.9.0 '@mdit-vue/plugin-component': ^0.9.2
'@mdit-vue/plugin-toc': ^0.9.2
'@rollup/plugin-alias': ^3.1.9 '@rollup/plugin-alias': ^3.1.9
'@rollup/plugin-commonjs': ^22.0.2 '@rollup/plugin-commonjs': ^22.0.2
'@rollup/plugin-json': ^4.1.0 '@rollup/plugin-json': ^4.1.0
@ -54,7 +55,6 @@ importers:
markdown-it-attrs: ^4.1.4 markdown-it-attrs: ^4.1.4
markdown-it-container: ^3.0.0 markdown-it-container: ^3.0.0
markdown-it-emoji: ^2.0.2 markdown-it-emoji: ^2.0.2
markdown-it-toc-done-right: ^4.2.0
micromatch: ^4.0.5 micromatch: ^4.0.5
minimist: ^1.2.6 minimist: ^1.2.6
npm-run-all: ^4.1.5 npm-run-all: ^4.1.5
@ -89,7 +89,8 @@ importers:
vite: 3.0.8 vite: 3.0.8
vue: 3.2.37 vue: 3.2.37
devDependencies: devDependencies:
'@mdit-vue/plugin-component': 0.9.0 '@mdit-vue/plugin-component': 0.9.2
'@mdit-vue/plugin-toc': 0.9.2
'@rollup/plugin-alias': 3.1.9_rollup@2.78.0 '@rollup/plugin-alias': 3.1.9_rollup@2.78.0
'@rollup/plugin-commonjs': 22.0.2_rollup@2.78.0 '@rollup/plugin-commonjs': 22.0.2_rollup@2.78.0
'@rollup/plugin-json': 4.1.0_rollup@2.78.0 '@rollup/plugin-json': 4.1.0_rollup@2.78.0
@ -133,7 +134,6 @@ importers:
markdown-it-attrs: 4.1.4_markdown-it@13.0.1 markdown-it-attrs: 4.1.4_markdown-it@13.0.1
markdown-it-container: 3.0.0 markdown-it-container: 3.0.0
markdown-it-emoji: 2.0.2 markdown-it-emoji: 2.0.2
markdown-it-toc-done-right: 4.2.0
micromatch: 4.0.5 micromatch: 4.0.5
minimist: 1.2.6 minimist: 1.2.6
npm-run-all: 4.1.5 npm-run-all: 4.1.5
@ -394,13 +394,34 @@ packages:
engines: {node: '>=6.9.0'} engines: {node: '>=6.9.0'}
dev: true dev: true
/@mdit-vue/plugin-component/0.9.0: /@mdit-vue/plugin-component/0.9.2:
resolution: {integrity: sha512-HfrIQL8EiIyBeg42aSdTJJ/r2STI88fDFexPv7pI+a/qq1BG5AR0FTHTuzP3vwHn1ysgYB1qk4/hV/hodPYzhQ==} resolution: {integrity: sha512-sTi9SWiakUGUs330zNRfEYSzGAVAXJ7gjbg46e/4HJQXxC8uEBC+Xg6IgsYcTRGHuJpCP65pcHvCLeDoCdWpyQ==}
dependencies: dependencies:
'@types/markdown-it': 12.2.3 '@types/markdown-it': 12.2.3
markdown-it: 13.0.1 markdown-it: 13.0.1
dev: true dev: true
/@mdit-vue/plugin-toc/0.9.2:
resolution: {integrity: sha512-Du3fFz+YezlXex9Syn+bc8ADDRx/kBfBokeHXfd/qCW5XqS7I4THLR/IRqlvi9CgIZ0dx7bJv0avxil9EX1PoQ==}
dependencies:
'@mdit-vue/shared': 0.9.2
'@mdit-vue/types': 0.9.2
'@types/markdown-it': 12.2.3
markdown-it: 13.0.1
dev: true
/@mdit-vue/shared/0.9.2:
resolution: {integrity: sha512-05Nk/o+kJCgeAa7oBGJOIazJq+6n0+VR4jPhzV3LGc9TyuMEqnrH5XzmBoy45vzyyoe7pGxJ/PBDxq4HebQHtQ==}
dependencies:
'@mdit-vue/types': 0.9.2
'@types/markdown-it': 12.2.3
markdown-it: 13.0.1
dev: true
/@mdit-vue/types/0.9.2:
resolution: {integrity: sha512-SuoxzZHS2/9bEqeJ+bjj2xBLjoZhRo6Ww/GVqNZS2ji9rkoM2teA0kbwSmj0X6Kf00K9HnLs6T0dtDtqpBqEHA==}
dev: true
/@nodelib/fs.scandir/2.1.5: /@nodelib/fs.scandir/2.1.5:
resolution: {integrity: sha512-vq24Bq3ym5HEQm2NKCr3yXDwjc7vTsEThRDnkp2DK9p1uqLR+DHurm/NOTo0KG7HYHU7eppKZj3MyqYuMBf62g==} resolution: {integrity: sha512-vq24Bq3ym5HEQm2NKCr3yXDwjc7vTsEThRDnkp2DK9p1uqLR+DHurm/NOTo0KG7HYHU7eppKZj3MyqYuMBf62g==}
engines: {node: '>= 8'} engines: {node: '>= 8'}
@ -2737,10 +2758,6 @@ packages:
resolution: {integrity: sha512-zLftSaNrKuYl0kR5zm4gxXjHaOI3FAOEaloKmRA5hijmJZvSjmxcokOLlzycb/HXlUFWzXqpIEoyEMCE4i9MvQ==} resolution: {integrity: sha512-zLftSaNrKuYl0kR5zm4gxXjHaOI3FAOEaloKmRA5hijmJZvSjmxcokOLlzycb/HXlUFWzXqpIEoyEMCE4i9MvQ==}
dev: true dev: true
/markdown-it-toc-done-right/4.2.0:
resolution: {integrity: sha512-UB/IbzjWazwTlNAX0pvWNlJS8NKsOQ4syrXZQ/C72j+jirrsjVRT627lCaylrKJFBQWfRsPmIVQie8x38DEhAQ==}
dev: true
/markdown-it/13.0.1: /markdown-it/13.0.1:
resolution: {integrity: sha512-lTlxriVoy2criHP0JKRhO2VDG9c2ypWCsT237eDiLqi09rmbKoUetyGHq2uOIRoRS//kfoJckS0eUzzkDR+k2Q==} resolution: {integrity: sha512-lTlxriVoy2criHP0JKRhO2VDG9c2ypWCsT237eDiLqi09rmbKoUetyGHq2uOIRoRS//kfoJckS0eUzzkDR+k2Q==}
hasBin: true hasBin: true

@ -2,10 +2,9 @@ import MarkdownIt from 'markdown-it'
import anchorPlugin from 'markdown-it-anchor' import anchorPlugin from 'markdown-it-anchor'
import attrsPlugin from 'markdown-it-attrs' import attrsPlugin from 'markdown-it-attrs'
import emojiPlugin from 'markdown-it-emoji' import emojiPlugin from 'markdown-it-emoji'
import tocPlugin from 'markdown-it-toc-done-right'
import { componentPlugin } from '@mdit-vue/plugin-component' import { componentPlugin } from '@mdit-vue/plugin-component'
import { tocPlugin, type TocPluginOptions } from '@mdit-vue/plugin-toc'
import { IThemeRegistration } from 'shiki' import { IThemeRegistration } from 'shiki'
import { parseHeader } from '../utils/parseHeader'
import { highlight } from './plugins/highlight' import { highlight } from './plugins/highlight'
import { slugify } from './plugins/slugify' import { slugify } from './plugins/slugify'
import { highlightLinePlugin } from './plugins/highlightLines' import { highlightLinePlugin } from './plugins/highlightLines'
@ -26,9 +25,7 @@ export type ThemeOptions =
export interface MarkdownOptions extends MarkdownIt.Options { export interface MarkdownOptions extends MarkdownIt.Options {
lineNumbers?: boolean lineNumbers?: boolean
config?: (md: MarkdownIt) => void config?: (md: MarkdownIt) => void
anchor?: { anchor?: anchorPlugin.AnchorOptions
permalink?: anchorPlugin.AnchorOptions['permalink']
}
attrs?: { attrs?: {
leftDelimiter?: string leftDelimiter?: string
rightDelimiter?: string rightDelimiter?: string
@ -36,8 +33,7 @@ export interface MarkdownOptions extends MarkdownIt.Options {
disable?: boolean disable?: boolean
} }
theme?: ThemeOptions theme?: ThemeOptions
// https://github.com/nagaozen/markdown-it-toc-done-right toc?: TocPluginOptions
toc?: any
externalLinks?: Record<string, string> externalLinks?: Record<string, string>
} }
@ -95,15 +91,11 @@ export const createMarkdownRenderer = async (
slugify, slugify,
permalink: anchorPlugin.permalink.ariaHidden({}), permalink: anchorPlugin.permalink.ariaHidden({}),
...options.anchor ...options.anchor
}) } as anchorPlugin.AnchorOptions)
.use(tocPlugin, { .use(tocPlugin, {
slugify, slugify,
level: [2, 3],
format: (x: string, htmlencode: (s: string) => string) =>
htmlencode(parseHeader(x)),
listType: 'ul',
...options.toc ...options.toc
}) } as TocPluginOptions)
.use(emojiPlugin) .use(emojiPlugin)
// apply user config // apply user config

Loading…
Cancel
Save