Skip to content

Commit c85f62d

Browse files
shigmaulivz
authored andcommitted
fix($theme-default): support slot and v-pre container (close: #1387) (#1389)
1 parent 7557262 commit c85f62d

File tree

14 files changed

+37
-54
lines changed

14 files changed

+37
-54
lines changed

packages/@vuepress/core/lib/prepare/AppContext.js

+10
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,16 @@ module.exports = class AppContext {
149149
.use(require('../internal-plugins/transformModule'))
150150
.use(require('../internal-plugins/dataBlock'))
151151
.use(require('../internal-plugins/frontmatterBlock'))
152+
.use('@vuepress/container', {
153+
type: 'slot',
154+
before: info => `<template slot="${info}">`,
155+
after: '</template>'
156+
})
157+
.use('@vuepress/container', {
158+
type: 'v-pre',
159+
before: '<div v-pre>',
160+
after: '</div>'
161+
})
152162
.use('@vuepress/last-updated', !!shouldUseLastUpdated)
153163
.use('@vuepress/register-components', {
154164
componentsDir: [

packages/@vuepress/core/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
"@vue/babel-preset-app": "^3.1.1",
3434
"@vuepress/markdown": "^1.0.0-alpha.41",
3535
"@vuepress/markdown-loader": "^1.0.0-alpha.41",
36+
"@vuepress/plugin-container": "^1.0.0-alpha.41",
3637
"@vuepress/plugin-last-updated": "^1.0.0-alpha.41",
3738
"@vuepress/plugin-register-components": "^1.0.0-alpha.41",
3839
"@vuepress/shared-utils": "^1.0.0-alpha.41",

packages/@vuepress/markdown/index.js

-5
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ const lineNumbersPlugin = require('./lib/lineNumbers')
1414
const componentPlugin = require('./lib/component')
1515
const hoistScriptStylePlugin = require('./lib/hoist')
1616
const convertRouterLinkPlugin = require('./lib/link')
17-
const markdownSlotsContainersPlugin = require('./lib/markdownSlotsContainers')
1817
const snippetPlugin = require('./lib/snippet')
1918
const tocPlugin = require('./lib/tableOfContents')
2019
const emojiPlugin = require('markdown-it-emoji')
@@ -74,10 +73,6 @@ module.exports = (markdown = {}) => {
7473
.use(hoistScriptStylePlugin)
7574
.end()
7675

77-
.plugin(PLUGINS.MARKDOWN_SLOTS_CONTAINERS)
78-
.use(markdownSlotsContainersPlugin)
79-
.end()
80-
8176
.plugin(PLUGINS.EMOJI)
8277
.use(emojiPlugin)
8378
.end()

packages/@vuepress/markdown/lib/constant.js

-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ exports.PLUGINS = {
55
SNIPPET: 'snippet',
66
CONVERT_ROUTER_LINK: 'convert-router-link',
77
HOIST_SCRIPT_STYLE: 'hoist-script-style',
8-
CONTAINERS: 'containers',
9-
MARKDOWN_SLOTS_CONTAINERS: 'markdown-slots-containers',
108
ANCHOR: 'anchor',
119
EMOJI: 'emoji',
1210
TOC: 'toc',

packages/@vuepress/markdown/lib/markdownSlotsContainers.js

-12
This file was deleted.

packages/@vuepress/plugin-container/index.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ module.exports = (options, context) => ({
2626
if (!render) {
2727
if (before !== undefined && after !== undefined) {
2828
render = (tokens, index) => {
29-
const token = tokens[index]
30-
return token.nesting === 1 ? call(before, token) : call(after, token)
29+
const info = tokens[index].info.trim().slice(type.length).trim
30+
return tokens[index].nesting === 1 ? call(before, info) : call(after, info)
3131
}
3232
} else {
3333
render = (tokens, index) => {

packages/@vuepress/theme-default/index.js

+1-6
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,6 @@ module.exports = (options, ctx) => ({
2323
'@vuepress/plugin-nprogress',
2424
['@vuepress/container', { type: 'tip' }],
2525
['@vuepress/container', { type: 'warning' }],
26-
['@vuepress/container', { type: 'danger' }],
27-
['@vuepress/container', {
28-
type: 'v-pre',
29-
before: '<div v-pre>\n',
30-
after: '</div>\n'
31-
}]
26+
['@vuepress/container', { type: 'danger' }]
3227
]
3328
})

packages/@vuepress/theme-default/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
"homepage": "https://github.com/vuejs/vuepress/packages/@vuepress/theme-default#readme",
3232
"dependencies": {
3333
"@vuepress/plugin-active-header-links": "^1.0.0-alpha.41",
34+
"@vuepress/plugin-container": "^1.0.0-alpha.41",
3435
"@vuepress/plugin-nprogress": "^1.0.0-alpha.41",
3536
"@vuepress/plugin-search": "^1.0.0-alpha.41",
3637
"docsearch.js": "^2.5.2",

packages/@vuepress/theme-default/styles/custom-blocks.styl

-17
Original file line numberDiff line numberDiff line change
@@ -27,21 +27,4 @@
2727
a
2828
color $textColor
2929

30-
pre.vue-container
31-
border-left-width: .5rem;
32-
border-left-style: solid;
33-
border-color: #42b983;
34-
border-radius: 0px;
35-
& > code
36-
font-size: 14px !important;
37-
& > p
38-
margin: -5px 0 -20px 0;
39-
code
40-
background-color: #42b983 !important;
41-
padding: 3px 5px;
42-
border-radius: 3px;
43-
color #000
44-
em
45-
color #808080
46-
font-weight light
4730

packages/docs/docs/.vuepress/config.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ module.exports = ctx => ({
8181
}],
8282
['@vuepress/container', {
8383
type: 'upgrade',
84-
before: ({ info }) => `<UpgradePath title="${info.trim().slice(7).trim()}">`,
84+
before: info => `<UpgradePath title="${info}">`,
8585
after: '</UpgradePath>',
8686
}],
8787
],

packages/docs/docs/.vuepress/styles/index.styl

+17-1
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,21 @@
44
// font-size 30px;
55
//}
66

7-
7+
pre.vue-container
8+
border-left-width: .5rem;
9+
border-left-style: solid;
10+
border-color: #42b983;
11+
border-radius: 0px;
12+
& > code
13+
font-size: 14px !important;
14+
& > p
15+
margin: -5px 0 -20px 0;
16+
code
17+
background-color: #42b983 !important;
18+
padding: 3px 5px;
19+
border-radius: 3px;
20+
color #000
21+
em
22+
color #808080
23+
font-weight light
824

packages/docs/docs/plugin/official/plugin-container.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,14 @@ The default title for the container. If no title was provided, `defaultTitle` wi
4949
- Type: `string | Function`
5050
- Default: `undefined`
5151

52-
String to be placed before the block. If specified as a function, a argument `token` will be passed to it. If specified, it will override `defaultTitle`.
52+
String to be placed before the block. If specified as a function, a argument `info` will be passed to it. (In the example above, `info` will be `bar`.) If specified, it will override `defaultTitle`.
5353

5454
### after
5555

5656
- Type: `string | Function`
5757
- Default: `undefined`
5858

59-
String to be placed after the block. If specified as a function, a argument `token` will be passed to it. If specified, it will override `defaultTitle`.
59+
String to be placed after the block. If specified as a function, a argument `info` will be passed to it. (In the example above, `info` will be `bar`.) If specified, it will override `defaultTitle`.
6060

6161
### validate
6262

packages/docs/docs/zh/plugin/official/plugin-container.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,14 @@ module.exports = {
4949
- 类型: `string | Function`
5050
- 默认值: `undefined`
5151

52-
要插入在容器前的 HTML。如果设置为一个函数,将传入当前的 `token` 作为第一个参数。如果设置了这个值,它将覆盖 `defaultTitle` 的效果。
52+
要插入在容器前的 HTML。如果设置为一个函数,将传入当前的 `info` 作为第一个参数。(在上面的例子中,`info` 的值为 `bar`。)如果设置了这个值,它将覆盖 `defaultTitle` 的效果。
5353

5454
### after
5555

5656
- 类型: `string | Function`
5757
- 默认值: `undefined`
5858

59-
要插入在容器后的 HTML。如果设置为一个函数,将传入当前的 `token` 作为第一个参数。如果设置了这个值,它将覆盖 `defaultTitle` 的效果。
59+
要插入在容器后的 HTML。如果设置为一个函数,将传入当前的 `info` 作为第一个参数。(在上面的例子中,`info` 的值为 `bar`。)如果设置了这个值,它将覆盖 `defaultTitle` 的效果。
6060

6161
### validate
6262

yarn.lock

-4
Original file line numberDiff line numberDiff line change
@@ -6580,10 +6580,6 @@ markdown-it-emoji@^1.4.0:
65806580
version "1.4.0"
65816581
resolved "https://registry.yarnpkg.com/markdown-it-emoji/-/markdown-it-emoji-1.4.0.tgz#9bee0e9a990a963ba96df6980c4fddb05dfb4dcc"
65826582

6583-
markdown-it-table-of-contents@^0.4.0:
6584-
version "0.4.0"
6585-
resolved "https://registry.yarnpkg.com/markdown-it-table-of-contents/-/markdown-it-table-of-contents-0.4.0.tgz#950541bec9a365a75265f5265a09dc0cb5935909"
6586-
65876583
markdown-it@^8.4.1:
65886584
version "8.4.2"
65896585
resolved "https://registry.yarnpkg.com/markdown-it/-/markdown-it-8.4.2.tgz#386f98998dc15a37722aa7722084f4020bdd9b54"

0 commit comments

Comments
 (0)