Skip to content

Commit 4a7d6d6

Browse files
committed
toc(table-of-contents) support
1 parent 400c37d commit 4a7d6d6

File tree

4 files changed

+24
-103
lines changed

4 files changed

+24
-103
lines changed

packages/example/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"version": "0.1.4",
44
"private": true,
55
"scripts": {
6-
"dev": "yarn webpack-dev-server --config webpack.config.js --open",
6+
"dev": "yarn webpack-dev-server",
77
"lint": "eslint --ext .js,.ts src"
88
},
99
"dependencies": {

packages/example/src/hello.md

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ lang: zh-CN
55

66
# @tianyong90/vue-markdown-loader example
77

8+
[[toc]]
9+
810
## hello world!
911

1012
## paragraph
@@ -20,7 +22,6 @@ Enjoy coding!
2022
| aaaa | bbbbbb | ccccc |
2123
| a | b | c |
2224

23-
2425
## list
2526

2627
- unordered list
@@ -72,3 +73,15 @@ Hello, thanks for using @tianyong90/vue-markdown-loader.
7273
::: danger STOP
7374
Danger zone!
7475
:::
76+
77+
## toc h2
78+
79+
test content
80+
81+
### toc h3 first
82+
83+
hello
84+
85+
### toc h3 second
86+
87+
hello

packages/vue-markdown-loader/src/markdown/index.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,16 @@ import highlightLines from './lib/highlightLines'
66
import preWrapperPlugin from './lib/preWrapper'
77
import lineNumbersPlugin from './lib/lineNumbers'
88
import containersPlugin from './lib/containers'
9-
// import hoistScriptStylePlugin from './lib/hoist'
10-
import tocPlugin from './lib/tableOfContents'
11-
import emojiPlugin from 'markdown-it-emoji'
129
import anchorPlugin from 'markdown-it-anchor'
10+
import emojiPlugin from 'markdown-it-emoji'
11+
import tocPlugin from 'markdown-it-table-of-contents'
1312
import hash from 'hash-sum'
1413
import chalk from 'chalk'
1514
import { logger, slugify } from '../utils'
1615

1716
export default (options: any = {}) => {
1817
const { anchor, toc, plugins, lineNumbers, beforeInstantiate, afterInstantiate } = options
1918

20-
// TODO
21-
// const resolver =
22-
2319
const config = new Config()
2420

2521
config.options
@@ -57,9 +53,14 @@ export default (options: any = {}) => {
5753
])
5854
.end()
5955

60-
// TODO: TOC
6156
.plugin(PLUGINS.TOC)
62-
.use(tocPlugin, [toc])
57+
.use(tocPlugin, [
58+
{
59+
slugify,
60+
includeLevel: [2, 3],
61+
...toc,
62+
},
63+
])
6364
.end()
6465

6566
if (lineNumbers) {

packages/vue-markdown-loader/src/markdown/lib/tableOfContents.ts

Lines changed: 0 additions & 93 deletions
This file was deleted.

0 commit comments

Comments
 (0)