Skip to content

Commit fbbd677

Browse files
committedMay 12, 2019
Revert "feat($markdown): TOC component (close: #1275) (#1375)"
This reverts commit 760f90b.
1 parent 8013417 commit fbbd677

File tree

12 files changed

+16
-243
lines changed

12 files changed

+16
-243
lines changed
 

Diff for: ‎packages/@vuepress/core/lib/client/app.js

-3
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import Content from './components/Content.js'
1616
import ContentSlotsDistributor from './components/ContentSlotsDistributor'
1717
import OutboundLink from './components/OutboundLink.vue'
1818
import ClientOnly from './components/ClientOnly'
19-
import TOC from './components/TOC.vue'
2019

2120
// suggest dev server restart on base change
2221
if (module.hot) {
@@ -47,8 +46,6 @@ Vue.component('ClientOnly', ClientOnly)
4746
// core components
4847
Vue.component('Layout', getLayoutAsyncComponent('Layout'))
4948
Vue.component('NotFound', getLayoutAsyncComponent('NotFound'))
50-
// markdown components
51-
Vue.component('TOC', TOC)
5249

5350
// global helper for adding base path to absolute urls
5451
Vue.prototype.$withBase = function (path) {

Diff for: ‎packages/@vuepress/core/lib/client/components/HeaderList.vue

-20
This file was deleted.

Diff for: ‎packages/@vuepress/core/lib/client/components/TOC.vue

-57
This file was deleted.

Diff for: ‎packages/@vuepress/markdown/index.js

+7-2
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,12 @@ const componentPlugin = require('./lib/component')
1515
const hoistScriptStylePlugin = require('./lib/hoist')
1616
const convertRouterLinkPlugin = require('./lib/link')
1717
const snippetPlugin = require('./lib/snippet')
18-
const tocPlugin = require('./lib/tableOfContents')
1918
const emojiPlugin = require('markdown-it-emoji')
2019
const anchorPlugin = require('markdown-it-anchor')
20+
const tocPlugin = require('markdown-it-table-of-contents')
2121
const {
2222
slugify: _slugify,
23+
parseHeaders,
2324
logger, chalk, hash, normalizeConfig,
2425
moduleResolver: { getMarkdownItResolver }
2526
} = require('@vuepress/shared-utils')
@@ -94,7 +95,11 @@ module.exports = (markdown = {}) => {
9495
.end()
9596

9697
.plugin(PLUGINS.TOC)
97-
.use(tocPlugin, [toc])
98+
.use(tocPlugin, [Object.assign({
99+
slugify,
100+
includeLevel: [2, 3],
101+
format: parseHeaders
102+
}, toc)])
98103
.end()
99104

100105
if (lineNumbers) {

Diff for: ‎packages/@vuepress/markdown/lib/tableOfContents.js

-83
This file was deleted.

Diff for: ‎packages/@vuepress/markdown/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
"markdown-it-anchor": "^5.0.2",
2626
"markdown-it-chain": "^1.3.0",
2727
"markdown-it-emoji": "^1.4.0",
28+
"markdown-it-table-of-contents": "^0.4.0",
2829
"prismjs": "^1.13.0"
2930
},
3031
"devDependencies": {

Diff for: ‎packages/docs/docs/config/README.md

+2-10
Original file line numberDiff line numberDiff line change
@@ -218,17 +218,9 @@ The key and value pair will be added to `<a>` tags that point to an external lin
218218
### markdown.toc
219219

220220
- Type: `Object`
221+
- Default: `{ includeLevel: [2, 3] }`
221222

222-
This attribute will control the behaviour of `[[TOC]]`. It contains the following options:
223-
224-
- includeLevel: [number, number], level of headers to be included, defaults to `[2, 3]`.
225-
- containerClass: string, the class name for the container, defaults to `table-of-contents`.
226-
- markerPattern: RegExp, the regular expression for the marker to be replaced with TOC, defaults to `/^\[\[toc\]\]/im`.
227-
- listType: string or Array, labels for all levels of the list, defaults to `"ul"`.
228-
- containerHeaderHtml: string, an HTML string for container header, defaults to `""`.
229-
- containerFooterHtml: string, an HTML string for container footer, defaults to `""`.
230-
231-
We also provide a [global component TOC](../guide/using-vue.md#toc) which allows for more free control by passing props directly to `<TOC>`.
223+
Options for [markdown-it-table-of-contents](https://github.com/Oktavilla/markdown-it-table-of-contents). (Note: prefer `markdown.slugify` if you want to customize header ids.)
232224

233225
### markdown.plugins
234226

Diff for: ‎packages/docs/docs/guide/markdown.md

+2-8
Original file line numberDiff line numberDiff line change
@@ -105,21 +105,15 @@ A list of all emojis available can be found [here](https://github.com/markdown-i
105105

106106
**Input**
107107

108-
```md
109-
[[toc]]
110108
```
111-
112-
or
113-
114-
```md
115-
<TOC/>
109+
[[toc]]
116110
```
117111

118112
**Output**
119113

120114
[[toc]]
121115

122-
Rendering of TOC can be configured using the [`markdown.toc`](../config/README.md#markdown-toc) option, or as props of [TOC component](./using-vue.md#toc), like `<TOC list-type="ol" :include-level="[2, Infinity]"/>`.
116+
Rendering of TOC can be configured using the [`markdown.toc`](../config/README.md#markdown-toc) option.
123117

124118
## Custom Containers <Badge text="default theme"/>
125119

Diff for: ‎packages/docs/docs/guide/using-vue.md

-21
Original file line numberDiff line numberDiff line change
@@ -224,27 +224,6 @@ Specify a specific slot for a specific page (.md) for rendering. This will be ve
224224
- [Markdown Slot](./markdown-slot.md)
225225
- [Writing a theme > Content Outlet](../theme/writing-a-theme.md#content-outlet)
226226

227-
### TOC <Badge text="1.0.0-alpha.41+"/>
228-
229-
- **Props**:
230-
- `listType` - string or Array, defaults to `"ul"`
231-
- `includeLevel` - [number, number], defaults to `[2, 3]`
232-
233-
- **Slots**: `header`, `footer`
234-
235-
- **Usage**:
236-
237-
You can add a custom table of contents by specify some props to this component. `includeLevel` decides which level of headers should be included. `listType` decides the tags of lists. If specified as an array, the component will take the first element as the first-level list type and so on. If there are not enough values provided, the last value will be used for all the remaining list types.
238-
239-
``` md
240-
<TOC :list-type="['ol', 'ul']">
241-
<p slot="header"><strong>Custom Table of Contents</strong></p>
242-
</TOC>
243-
```
244-
245-
<TOC :list-type="['ol', 'ul']">
246-
<p slot="header"><strong>Custom Table of Contents</strong></p>
247-
</TOC>
248227

249228
### Badge <Badge text="beta" type="warn"/> <Badge text="0.10.1+"/> <Badge text="default theme"/>
250229

Diff for: ‎packages/docs/docs/zh/config/README.md

+2-10
Original file line numberDiff line numberDiff line change
@@ -209,17 +209,9 @@ VuePress 提供了一种添加额外样式的简便方法。你可以创建一
209209
### markdown.toc
210210

211211
- 类型: `Object`
212+
- 默认值: `{ includeLevel: [2, 3] }`
212213

213-
这个值将会控制 `[[TOC]]` 默认行为。它包含下面的选项:
214-
215-
- includeLevel: [number, number],决定哪些级别的标题会被显示在目录中,默认值为 `[2, 3]`
216-
- containerClass: string,决定了目录容器的类名,默认值为 `table-of-contents`
217-
- markerPattern: RegExp,决定了标题匹配的正则表达式,默认值为 `/^\[\[toc\]\]/im`
218-
- listType: string 或 Array,决定了各级列表的标签,默认值为 `"ul"`
219-
- containerHeaderHtml: string,在目录开头插入的 HTML 字符串,默认值为 `""`
220-
- containerFooterHtml: string,在目录结尾插入的 HTML 字符串,默认值为 `""`
221-
222-
此外,我们还提供了[全局组件 TOC](../guide/using-vue.md#toc),可以通过直接向 `<TOC>` 传递属性实现更加自由的控制。
214+
[markdown-it-table-of-contents](https://github.com/Oktavilla/markdown-it-table-of-contents) 的选项。
223215

224216
### markdown.plugins
225217

Diff for: ‎packages/docs/docs/zh/guide/markdown.md

+2-8
Original file line numberDiff line numberDiff line change
@@ -103,21 +103,15 @@ lang: en-US
103103

104104
**输入**
105105

106-
```md
107-
[[toc]]
108106
```
109-
110-
或者
111-
112-
```md
113-
<TOC/>
107+
[[toc]]
114108
```
115109

116110
**输出**
117111

118112
[[toc]]
119113

120-
目录(Table of Contents)的渲染可以通过 [`markdown.toc`](../config/README.md#markdown-toc) 选项来配置,也可以在 [TOC 组件](./using-vue.md#toc)中直接传入,如 `<TOC list-type="ol" :include-level="[2, Infinity]"/>`
114+
目录(Table of Contents)的渲染可以通过 [`markdown.toc`](../config/README.md#markdown-toc) 选项来配置。
121115

122116
## 自定义容器 <Badge text="默认主题"/>
123117

Diff for: ‎packages/docs/docs/zh/guide/using-vue.md

-21
Original file line numberDiff line numberDiff line change
@@ -225,27 +225,6 @@ export default {
225225
- [Markdown 插槽](./markdown-slot.md)
226226
- [开发主题 > 获取渲染内容](../theme/writing-a-theme.md#获取渲染内容)
227227

228-
### TOC <Badge text="1.0.0-alpha.41+"/>
229-
230-
- **Props**:
231-
- `listType` - string 或 Array, 默认值为 `"ul"`
232-
- `includeLevel` - [number, number], 默认值为 `[2, 3]`
233-
234-
- **Slots**: `header`, `footer`
235-
236-
- **Usage**:
237-
238-
你可以通过一些属性来实现一个自定义的目录。`includeLevel` 决定了哪些级别的标题会被显示在目录中。`listType` 决定了所有列表的标签。如果设置为了数组,组件将会使用第一个元素作为第一级列表的标签,以此类推。如果提供的标签不够多,将使用提供的最后一个值作为全部剩下的列表标签。
239-
240-
``` md
241-
<TOC :list-type="['ol', 'ul']">
242-
<p slot="header"><strong>自定义目录</strong></p>
243-
</TOC>
244-
```
245-
246-
<TOC :list-type="['ol', 'ul']">
247-
<p slot="header"><strong>自定义目录</strong></p>
248-
</TOC>
249228

250229
### Badge <Badge text="beta" type="warn"/> <Badge text="0.10.1+"/> <Badge text="默认主题"/>
251230

1 commit comments

Comments
 (1)

lunaceee commented on Aug 18, 2019

@lunaceee

Can I ask why we decided on reverting 760f90b?
I'd like to work on #1750 but I want to understand the context better before I jump in. Thanks! cc @ulivz

Please sign in to comment.