@mdit-vue/plugin-toc 0.3.0 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +14 -0
- package/README.md +1 -0
- package/dist/index.d.ts +19 -1
- package/package.json +4 -4
- package/src/index.ts +1 -0
- package/src/types.ts +18 -1
- package/tests/__snapshots__/toc-plugin.spec.ts.snap +12 -12
- package/tests/toc-plugin.spec.ts +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,20 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
# [0.5.0](https://github.com/mdit-vue/mdit-vue/compare/v0.4.0...v0.5.0) (2022-07-06)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package @mdit-vue/plugin-toc
|
|
9
|
+
|
|
10
|
+
# [0.4.0](https://github.com/mdit-vue/mdit-vue/compare/v0.3.1...v0.4.0) (2022-07-02)
|
|
11
|
+
|
|
12
|
+
**Note:** Version bump only for package @mdit-vue/plugin-toc
|
|
13
|
+
|
|
14
|
+
## [0.3.1](https://github.com/mdit-vue/mdit-vue/compare/v0.3.0...v0.3.1) (2022-06-25)
|
|
15
|
+
|
|
16
|
+
### Bug Fixes
|
|
17
|
+
|
|
18
|
+
- **plugin-toc:** export types ([310320e](https://github.com/mdit-vue/mdit-vue/commit/310320eb12087b0296ed8840b5d581887568b15f))
|
|
19
|
+
|
|
6
20
|
# [0.3.0](https://github.com/mdit-vue/mdit-vue/compare/v0.2.0...v0.3.0) (2022-06-25)
|
|
7
21
|
|
|
8
22
|
### Features
|
package/README.md
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
# @mdit-vue/plugin-toc
|
|
2
2
|
|
|
3
3
|
[](https://www.npmjs.com/package/@mdit-vue/plugin-toc)
|
|
4
|
+
[](https://github.com/mdit-vue/mdit-vue/blob/main/LICENSE)
|
|
4
5
|
|
|
5
6
|
A [markdown-it](https://github.com/markdown-it/markdown-it) plugin to generate table-of-contents (TOC) that compatible with [Vue.js](https://vuejs.org).
|
|
6
7
|
|
package/dist/index.d.ts
CHANGED
|
@@ -8,6 +8,8 @@ import { PluginWithOptions } from 'markdown-it';
|
|
|
8
8
|
interface TocPluginOptions {
|
|
9
9
|
/**
|
|
10
10
|
* The pattern serving as the TOC placeholder in your markdown
|
|
11
|
+
*
|
|
12
|
+
* @default /^\[\[toc\]\]$/i
|
|
11
13
|
*/
|
|
12
14
|
pattern?: RegExp;
|
|
13
15
|
/**
|
|
@@ -26,34 +28,50 @@ interface TocPluginOptions {
|
|
|
26
28
|
*
|
|
27
29
|
* Should be a subset of markdown-it-anchor's `level` option
|
|
28
30
|
* to ensure the link is existed
|
|
31
|
+
*
|
|
32
|
+
* @default [2,3]
|
|
29
33
|
*/
|
|
30
34
|
level?: number[];
|
|
31
35
|
/**
|
|
32
36
|
* HTML tag of the TOC container
|
|
37
|
+
*
|
|
38
|
+
* @default 'nav'
|
|
33
39
|
*/
|
|
34
40
|
containerTag?: string;
|
|
35
41
|
/**
|
|
36
42
|
* The class for the TOC container
|
|
43
|
+
*
|
|
44
|
+
* @default 'table-of-contents'
|
|
37
45
|
*/
|
|
38
46
|
containerClass?: string;
|
|
39
47
|
/**
|
|
40
48
|
* HTML tag of the TOC list
|
|
49
|
+
*
|
|
50
|
+
* @default 'ul'
|
|
41
51
|
*/
|
|
42
52
|
listTag?: 'ul' | 'ol';
|
|
43
53
|
/**
|
|
44
54
|
* The class for the TOC list
|
|
55
|
+
*
|
|
56
|
+
* @default ''
|
|
45
57
|
*/
|
|
46
58
|
listClass?: string;
|
|
47
59
|
/**
|
|
48
60
|
* The class for the `<li>` tag
|
|
61
|
+
*
|
|
62
|
+
* @default ''
|
|
49
63
|
*/
|
|
50
64
|
itemClass?: string;
|
|
51
65
|
/**
|
|
52
66
|
* The tag of the link inside `<li>` tag
|
|
67
|
+
*
|
|
68
|
+
* @default 'a'
|
|
53
69
|
*/
|
|
54
70
|
linkTag?: 'a' | 'router-link';
|
|
55
71
|
/**
|
|
56
72
|
* The class for the link inside the `<li>` tag
|
|
73
|
+
*
|
|
74
|
+
* @default ''
|
|
57
75
|
*/
|
|
58
76
|
linkClass?: string;
|
|
59
77
|
}
|
|
@@ -80,4 +98,4 @@ declare const createTocBlockRule: ({ pattern, containerTag, containerClass, }: P
|
|
|
80
98
|
*/
|
|
81
99
|
declare const tocPlugin: PluginWithOptions<TocPluginOptions>;
|
|
82
100
|
|
|
83
|
-
export { createRenderHeaders, createTocBlockRule, tocPlugin };
|
|
101
|
+
export { TocPluginOptions, createRenderHeaders, createTocBlockRule, tocPlugin };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mdit-vue/plugin-toc",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"description": "A markdown-it plugin to generate table-of-contents that compatible with Vue.js",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"markdown-it",
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
"test": "vitest"
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"@mdit-vue/shared": "0.
|
|
37
|
+
"@mdit-vue/shared": "0.5.0",
|
|
38
38
|
"@types/markdown-it": "^12.2.3",
|
|
39
39
|
"markdown-it": "^13.0.1"
|
|
40
40
|
},
|
|
@@ -42,10 +42,10 @@
|
|
|
42
42
|
"c8": "^7.11.3",
|
|
43
43
|
"markdown-it-anchor": "^8.6.4",
|
|
44
44
|
"unbuild": "^0.7.4",
|
|
45
|
-
"vitest": "^0.
|
|
45
|
+
"vitest": "^0.17.0"
|
|
46
46
|
},
|
|
47
47
|
"publishConfig": {
|
|
48
48
|
"access": "public"
|
|
49
49
|
},
|
|
50
|
-
"gitHead": "
|
|
50
|
+
"gitHead": "33671b4a15611ea35b065269526449129eef99d6"
|
|
51
51
|
}
|
package/src/index.ts
CHANGED
package/src/types.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Options of @mdit-vue/plugin-toc
|
|
3
3
|
*/
|
|
4
|
-
|
|
5
4
|
export interface TocPluginOptions {
|
|
6
5
|
/**
|
|
7
6
|
* The pattern serving as the TOC placeholder in your markdown
|
|
7
|
+
*
|
|
8
|
+
* @default /^\[\[toc\]\]$/i
|
|
8
9
|
*/
|
|
9
10
|
pattern?: RegExp;
|
|
10
11
|
|
|
@@ -26,41 +27,57 @@ export interface TocPluginOptions {
|
|
|
26
27
|
*
|
|
27
28
|
* Should be a subset of markdown-it-anchor's `level` option
|
|
28
29
|
* to ensure the link is existed
|
|
30
|
+
*
|
|
31
|
+
* @default [2,3]
|
|
29
32
|
*/
|
|
30
33
|
level?: number[];
|
|
31
34
|
|
|
32
35
|
/**
|
|
33
36
|
* HTML tag of the TOC container
|
|
37
|
+
*
|
|
38
|
+
* @default 'nav'
|
|
34
39
|
*/
|
|
35
40
|
containerTag?: string;
|
|
36
41
|
|
|
37
42
|
/**
|
|
38
43
|
* The class for the TOC container
|
|
44
|
+
*
|
|
45
|
+
* @default 'table-of-contents'
|
|
39
46
|
*/
|
|
40
47
|
containerClass?: string;
|
|
41
48
|
|
|
42
49
|
/**
|
|
43
50
|
* HTML tag of the TOC list
|
|
51
|
+
*
|
|
52
|
+
* @default 'ul'
|
|
44
53
|
*/
|
|
45
54
|
listTag?: 'ul' | 'ol';
|
|
46
55
|
|
|
47
56
|
/**
|
|
48
57
|
* The class for the TOC list
|
|
58
|
+
*
|
|
59
|
+
* @default ''
|
|
49
60
|
*/
|
|
50
61
|
listClass?: string;
|
|
51
62
|
|
|
52
63
|
/**
|
|
53
64
|
* The class for the `<li>` tag
|
|
65
|
+
*
|
|
66
|
+
* @default ''
|
|
54
67
|
*/
|
|
55
68
|
itemClass?: string;
|
|
56
69
|
|
|
57
70
|
/**
|
|
58
71
|
* The tag of the link inside `<li>` tag
|
|
72
|
+
*
|
|
73
|
+
* @default 'a'
|
|
59
74
|
*/
|
|
60
75
|
linkTag?: 'a' | 'router-link';
|
|
61
76
|
|
|
62
77
|
/**
|
|
63
78
|
* The class for the link inside the `<li>` tag
|
|
79
|
+
*
|
|
80
|
+
* @default ''
|
|
64
81
|
*/
|
|
65
82
|
linkClass?: string;
|
|
66
83
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// Vitest Snapshot v1
|
|
2
2
|
|
|
3
|
-
exports[`@
|
|
3
|
+
exports[`@mdit-vue/plugin-toc > toc-plugin > should render class name correctly > complexTree 1`] = `
|
|
4
4
|
"<nav><ul class=\\"toc-list\\"><li class=\\"toc-item\\" class=\\"toc-item\\"><a class=\\"toc-link\\" href=\\"#s1-1\\">s1-1</a><ul class=\\"toc-list\\"><li class=\\"toc-item\\" class=\\"toc-item\\"><a class=\\"toc-link\\" href=\\"#s1-1-1\\">s1-1-1</a></li><li class=\\"toc-item\\" class=\\"toc-item\\"><a class=\\"toc-link\\" href=\\"#s1-1-2\\">s1-1-2</a></li><li class=\\"toc-item\\" class=\\"toc-item\\"><a class=\\"toc-link\\" href=\\"#s1-1-3\\">s1-1-3</a></li></ul></li><li class=\\"toc-item\\" class=\\"toc-item\\"><a class=\\"toc-link\\" href=\\"#s1-2\\">s1-2</a></li><li class=\\"toc-item\\" class=\\"toc-item\\"><a class=\\"toc-link\\" href=\\"#s1-3\\">s1-3</a><ul class=\\"toc-list\\"><li class=\\"toc-item\\" class=\\"toc-item\\"><a class=\\"toc-link\\" href=\\"#s1-3-2\\">s1-3-2</a></li></ul></li></ul></nav>
|
|
5
5
|
<h1>s1</h1>
|
|
6
6
|
<h2>s1-1</h2>
|
|
@@ -18,7 +18,7 @@ exports[`@vuepress/markdown > plugins > tocPlugin > should render class name cor
|
|
|
18
18
|
"
|
|
19
19
|
`;
|
|
20
20
|
|
|
21
|
-
exports[`@
|
|
21
|
+
exports[`@mdit-vue/plugin-toc > toc-plugin > should render class name correctly > reversedTree 1`] = `
|
|
22
22
|
"<nav><ul class=\\"toc-list\\"><li class=\\"toc-item\\" class=\\"toc-item\\"><a class=\\"toc-link\\" href=\\"#h3\\">h3</a></li><li class=\\"toc-item\\" class=\\"toc-item\\"><a class=\\"toc-link\\" href=\\"#h2\\">h2</a></li></ul></nav>
|
|
23
23
|
<h6>h6</h6>
|
|
24
24
|
<h5>h5</h5>
|
|
@@ -29,7 +29,7 @@ exports[`@vuepress/markdown > plugins > tocPlugin > should render class name cor
|
|
|
29
29
|
"
|
|
30
30
|
`;
|
|
31
31
|
|
|
32
|
-
exports[`@
|
|
32
|
+
exports[`@mdit-vue/plugin-toc > toc-plugin > should render class name correctly > simpleTree 1`] = `
|
|
33
33
|
"<nav><ul class=\\"toc-list\\"><li class=\\"toc-item\\" class=\\"toc-item\\"><a class=\\"toc-link\\" href=\\"#h2\\">h2</a><ul class=\\"toc-list\\"><li class=\\"toc-item\\" class=\\"toc-item\\"><a class=\\"toc-link\\" href=\\"#h3\\">h3</a></li></ul></li></ul></nav>
|
|
34
34
|
<h1>h1</h1>
|
|
35
35
|
<h2>h2</h2>
|
|
@@ -40,7 +40,7 @@ exports[`@vuepress/markdown > plugins > tocPlugin > should render class name cor
|
|
|
40
40
|
"
|
|
41
41
|
`;
|
|
42
42
|
|
|
43
|
-
exports[`@
|
|
43
|
+
exports[`@mdit-vue/plugin-toc > toc-plugin > should render toc (h1, h2, h3, h4) > complexTree 1`] = `
|
|
44
44
|
"<nav class=\\"table-of-contents\\"><ul><li><a href=\\"#s1\\">s1</a><ul><li><a href=\\"#s1-1\\">s1-1</a><ul><li><a href=\\"#s1-1-1\\">s1-1-1</a><ul><li><a href=\\"#s1-1-1-1\\">s1-1-1-1</a></li></ul></li><li><a href=\\"#s1-1-2\\">s1-1-2</a></li><li><a href=\\"#s1-1-3\\">s1-1-3</a><ul><li><a href=\\"#s1-1-3-1\\">s1-1-3-1</a></li></ul></li></ul></li><li><a href=\\"#s1-2\\">s1-2</a></li><li><a href=\\"#s1-3\\">s1-3</a><ul><li><a href=\\"#s1-3-2\\">s1-3-2</a><ul><li><a href=\\"#s1-3-2-1\\">s1-3-2-1</a></li></ul></li></ul></li></ul></li></ul></nav>
|
|
45
45
|
<h1>s1</h1>
|
|
46
46
|
<h2>s1-1</h2>
|
|
@@ -58,7 +58,7 @@ exports[`@vuepress/markdown > plugins > tocPlugin > should render toc (h1, h2, h
|
|
|
58
58
|
"
|
|
59
59
|
`;
|
|
60
60
|
|
|
61
|
-
exports[`@
|
|
61
|
+
exports[`@mdit-vue/plugin-toc > toc-plugin > should render toc (h1, h2, h3, h4) > reversedTree 1`] = `
|
|
62
62
|
"<nav class=\\"table-of-contents\\"><ul><li><a href=\\"#h4\\">h4</a></li><li><a href=\\"#h3\\">h3</a></li><li><a href=\\"#h2\\">h2</a></li><li><a href=\\"#h1\\">h1</a></li></ul></nav>
|
|
63
63
|
<h6>h6</h6>
|
|
64
64
|
<h5>h5</h5>
|
|
@@ -69,7 +69,7 @@ exports[`@vuepress/markdown > plugins > tocPlugin > should render toc (h1, h2, h
|
|
|
69
69
|
"
|
|
70
70
|
`;
|
|
71
71
|
|
|
72
|
-
exports[`@
|
|
72
|
+
exports[`@mdit-vue/plugin-toc > toc-plugin > should render toc (h1, h2, h3, h4) > simpleTree 1`] = `
|
|
73
73
|
"<nav class=\\"table-of-contents\\"><ul><li><a href=\\"#h1\\">h1</a><ul><li><a href=\\"#h2\\">h2</a><ul><li><a href=\\"#h3\\">h3</a><ul><li><a href=\\"#h4\\">h4</a></li></ul></li></ul></li></ul></li></ul></nav>
|
|
74
74
|
<h1>h1</h1>
|
|
75
75
|
<h2>h2</h2>
|
|
@@ -80,7 +80,7 @@ exports[`@vuepress/markdown > plugins > tocPlugin > should render toc (h1, h2, h
|
|
|
80
80
|
"
|
|
81
81
|
`;
|
|
82
82
|
|
|
83
|
-
exports[`@
|
|
83
|
+
exports[`@mdit-vue/plugin-toc > toc-plugin > should render toc with RouterLink > complexTree 1`] = `
|
|
84
84
|
"<nav class=\\"table-of-contents\\"><ul><li><RouterLink href=\\"#s1-1\\">s1-1</RouterLink><ul><li><RouterLink href=\\"#s1-1-1\\">s1-1-1</RouterLink></li><li><RouterLink href=\\"#s1-1-2\\">s1-1-2</RouterLink></li><li><RouterLink href=\\"#s1-1-3\\">s1-1-3</RouterLink></li></ul></li><li><RouterLink href=\\"#s1-2\\">s1-2</RouterLink></li><li><RouterLink href=\\"#s1-3\\">s1-3</RouterLink><ul><li><RouterLink href=\\"#s1-3-2\\">s1-3-2</RouterLink></li></ul></li></ul></nav>
|
|
85
85
|
<h1>s1</h1>
|
|
86
86
|
<h2>s1-1</h2>
|
|
@@ -98,7 +98,7 @@ exports[`@vuepress/markdown > plugins > tocPlugin > should render toc with Route
|
|
|
98
98
|
"
|
|
99
99
|
`;
|
|
100
100
|
|
|
101
|
-
exports[`@
|
|
101
|
+
exports[`@mdit-vue/plugin-toc > toc-plugin > should render toc with RouterLink > reversedTree 1`] = `
|
|
102
102
|
"<nav class=\\"table-of-contents\\"><ul><li><RouterLink href=\\"#h3\\">h3</RouterLink></li><li><RouterLink href=\\"#h2\\">h2</RouterLink></li></ul></nav>
|
|
103
103
|
<h6>h6</h6>
|
|
104
104
|
<h5>h5</h5>
|
|
@@ -109,7 +109,7 @@ exports[`@vuepress/markdown > plugins > tocPlugin > should render toc with Route
|
|
|
109
109
|
"
|
|
110
110
|
`;
|
|
111
111
|
|
|
112
|
-
exports[`@
|
|
112
|
+
exports[`@mdit-vue/plugin-toc > toc-plugin > should render toc with RouterLink > simpleTree 1`] = `
|
|
113
113
|
"<nav class=\\"table-of-contents\\"><ul><li><RouterLink href=\\"#h2\\">h2</RouterLink><ul><li><RouterLink href=\\"#h3\\">h3</RouterLink></li></ul></li></ul></nav>
|
|
114
114
|
<h1>h1</h1>
|
|
115
115
|
<h2>h2</h2>
|
|
@@ -120,7 +120,7 @@ exports[`@vuepress/markdown > plugins > tocPlugin > should render toc with Route
|
|
|
120
120
|
"
|
|
121
121
|
`;
|
|
122
122
|
|
|
123
|
-
exports[`@
|
|
123
|
+
exports[`@mdit-vue/plugin-toc > toc-plugin > should render toc with default option (h2, h3) > complexTree 1`] = `
|
|
124
124
|
"<nav class=\\"table-of-contents\\"><ul><li><a href=\\"#s1-1\\">s1-1</a><ul><li><a href=\\"#s1-1-1\\">s1-1-1</a></li><li><a href=\\"#s1-1-2\\">s1-1-2</a></li><li><a href=\\"#s1-1-3\\">s1-1-3</a></li></ul></li><li><a href=\\"#s1-2\\">s1-2</a></li><li><a href=\\"#s1-3\\">s1-3</a><ul><li><a href=\\"#s1-3-2\\">s1-3-2</a></li></ul></li></ul></nav>
|
|
125
125
|
<h1>s1</h1>
|
|
126
126
|
<h2>s1-1</h2>
|
|
@@ -138,7 +138,7 @@ exports[`@vuepress/markdown > plugins > tocPlugin > should render toc with defau
|
|
|
138
138
|
"
|
|
139
139
|
`;
|
|
140
140
|
|
|
141
|
-
exports[`@
|
|
141
|
+
exports[`@mdit-vue/plugin-toc > toc-plugin > should render toc with default option (h2, h3) > reversedTree 1`] = `
|
|
142
142
|
"<nav class=\\"table-of-contents\\"><ul><li><a href=\\"#h3\\">h3</a></li><li><a href=\\"#h2\\">h2</a></li></ul></nav>
|
|
143
143
|
<h6>h6</h6>
|
|
144
144
|
<h5>h5</h5>
|
|
@@ -149,7 +149,7 @@ exports[`@vuepress/markdown > plugins > tocPlugin > should render toc with defau
|
|
|
149
149
|
"
|
|
150
150
|
`;
|
|
151
151
|
|
|
152
|
-
exports[`@
|
|
152
|
+
exports[`@mdit-vue/plugin-toc > toc-plugin > should render toc with default option (h2, h3) > simpleTree 1`] = `
|
|
153
153
|
"<nav class=\\"table-of-contents\\"><ul><li><a href=\\"#h2\\">h2</a><ul><li><a href=\\"#h3\\">h3</a></li></ul></li></ul></nav>
|
|
154
154
|
<h1>h1</h1>
|
|
155
155
|
<h2>h2</h2>
|
package/tests/toc-plugin.spec.ts
CHANGED
|
@@ -41,7 +41,7 @@ const fixtures = {
|
|
|
41
41
|
`,
|
|
42
42
|
};
|
|
43
43
|
|
|
44
|
-
describe('@
|
|
44
|
+
describe('@mdit-vue/plugin-toc > toc-plugin', () => {
|
|
45
45
|
describe('should render toc with default option (h2, h3)', () => {
|
|
46
46
|
const md = MarkdownIt().use(tocPlugin);
|
|
47
47
|
|