Skip to content

Commit 0664006

Browse files
authored
refactor: migrate markdown toc plugin (#1093) (#1207)
1 parent 8b6aef7 commit 0664006

File tree

5 files changed

+42
-34
lines changed

5 files changed

+42
-34
lines changed

docs/config/app-configs.md

+5-7
Original file line numberDiff line numberDiff line change
@@ -148,10 +148,8 @@ interface MarkdownOptions extends MarkdownIt.Options {
148148
lineNumbers?: boolean
149149

150150
// markdown-it-anchor plugin options.
151-
// See: https://github.com/valeriangalliat/markdown-it-anchor
152-
anchor?: {
153-
permalink?: anchor.AnchorOptions['permalink']
154-
}
151+
// See: https://github.com/valeriangalliat/markdown-it-anchor#usage
152+
anchor?: anchorPlugin.AnchorOptions
155153

156154
// markdown-it-attrs plugin options.
157155
// See: https://github.com/arve0/markdown-it-attrs
@@ -162,9 +160,9 @@ interface MarkdownOptions extends MarkdownIt.Options {
162160
disable?: boolean
163161
}
164162

165-
// markdown-it-toc-done-right plugin options
166-
// See: https://github.com/nagaozen/markdown-it-toc-done-right
167-
toc?: any
163+
// @mdit-vue/plugin-toc plugin options.
164+
// See: https://github.com/mdit-vue/mdit-vue/tree/main/packages/plugin-toc#options
165+
toc?: TocPluginOptions
168166

169167
// Configure the Markdown-it instance.
170168
config?: (md: MarkdownIt) => void

docs/guide/markdown.md

+3-2
Original file line numberDiff line numberDiff line change
@@ -435,12 +435,13 @@ const anchor = require('markdown-it-anchor')
435435
module.exports = {
436436
markdown: {
437437
// options for markdown-it-anchor
438-
// https://github.com/valeriangalliat/markdown-it-anchor#permalinks
438+
// https://github.com/valeriangalliat/markdown-it-anchor#usage
439439
anchor: {
440440
permalink: anchor.permalink.headerLink()
441441
},
442442

443-
// options for markdown-it-toc-done-right
443+
// options for @mdit-vue/plugin-toc
444+
// https://github.com/mdit-vue/mdit-vue/tree/main/packages/plugin-toc#options
444445
toc: { level: [1, 2] },
445446

446447
config: (md) => {

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,8 @@
9292
"vue": "^3.2.37"
9393
},
9494
"devDependencies": {
95-
"@mdit-vue/plugin-component": "^0.9.0",
95+
"@mdit-vue/plugin-component": "^0.9.2",
96+
"@mdit-vue/plugin-toc": "^0.9.2",
9697
"@rollup/plugin-alias": "^3.1.9",
9798
"@rollup/plugin-commonjs": "^22.0.2",
9899
"@rollup/plugin-json": "^4.1.0",
@@ -136,7 +137,6 @@
136137
"markdown-it-attrs": "^4.1.4",
137138
"markdown-it-container": "^3.0.0",
138139
"markdown-it-emoji": "^2.0.2",
139-
"markdown-it-toc-done-right": "^4.2.0",
140140
"micromatch": "^4.0.5",
141141
"minimist": "^1.2.6",
142142
"npm-run-all": "^4.1.5",

pnpm-lock.yaml

+27-10
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/node/markdown/markdown.ts

+5-13
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,9 @@ import MarkdownIt from 'markdown-it'
22
import anchorPlugin from 'markdown-it-anchor'
33
import attrsPlugin from 'markdown-it-attrs'
44
import emojiPlugin from 'markdown-it-emoji'
5-
import tocPlugin from 'markdown-it-toc-done-right'
65
import { componentPlugin } from '@mdit-vue/plugin-component'
6+
import { tocPlugin, type TocPluginOptions } from '@mdit-vue/plugin-toc'
77
import { IThemeRegistration } from 'shiki'
8-
import { parseHeader } from '../utils/parseHeader'
98
import { highlight } from './plugins/highlight'
109
import { slugify } from './plugins/slugify'
1110
import { highlightLinePlugin } from './plugins/highlightLines'
@@ -26,18 +25,15 @@ export type ThemeOptions =
2625
export interface MarkdownOptions extends MarkdownIt.Options {
2726
lineNumbers?: boolean
2827
config?: (md: MarkdownIt) => void
29-
anchor?: {
30-
permalink?: anchorPlugin.AnchorOptions['permalink']
31-
}
28+
anchor?: anchorPlugin.AnchorOptions
3229
attrs?: {
3330
leftDelimiter?: string
3431
rightDelimiter?: string
3532
allowedAttributes?: string[]
3633
disable?: boolean
3734
}
3835
theme?: ThemeOptions
39-
// https://github.com/nagaozen/markdown-it-toc-done-right
40-
toc?: any
36+
toc?: TocPluginOptions
4137
externalLinks?: Record<string, string>
4238
}
4339

@@ -95,15 +91,11 @@ export const createMarkdownRenderer = async (
9591
slugify,
9692
permalink: anchorPlugin.permalink.ariaHidden({}),
9793
...options.anchor
98-
})
94+
} as anchorPlugin.AnchorOptions)
9995
.use(tocPlugin, {
10096
slugify,
101-
level: [2, 3],
102-
format: (x: string, htmlencode: (s: string) => string) =>
103-
htmlencode(parseHeader(x)),
104-
listType: 'ul',
10597
...options.toc
106-
})
98+
} as TocPluginOptions)
10799
.use(emojiPlugin)
108100

109101
// apply user config

0 commit comments

Comments
 (0)