From c85f62d4a69b6bcefe07321fe973e617c70d92a0 Mon Sep 17 00:00:00 2001 From: Shigma <33423008+Shigma@users.noreply.github.com> Date: Sun, 3 Mar 2019 14:51:39 +0800 Subject: [PATCH] fix($theme-default): support slot and v-pre container (close: #1387) (#1389) --- .../@vuepress/core/lib/prepare/AppContext.js | 10 ++++++++++ packages/@vuepress/core/package.json | 1 + packages/@vuepress/markdown/index.js | 5 ----- packages/@vuepress/markdown/lib/constant.js | 2 -- .../markdown/lib/markdownSlotsContainers.js | 12 ------------ packages/@vuepress/plugin-container/index.js | 4 ++-- packages/@vuepress/theme-default/index.js | 7 +------ packages/@vuepress/theme-default/package.json | 1 + .../theme-default/styles/custom-blocks.styl | 17 ----------------- packages/docs/docs/.vuepress/config.js | 2 +- packages/docs/docs/.vuepress/styles/index.styl | 18 +++++++++++++++++- .../docs/plugin/official/plugin-container.md | 4 ++-- .../zh/plugin/official/plugin-container.md | 4 ++-- yarn.lock | 4 ---- 14 files changed, 37 insertions(+), 54 deletions(-) delete mode 100644 packages/@vuepress/markdown/lib/markdownSlotsContainers.js diff --git a/packages/@vuepress/core/lib/prepare/AppContext.js b/packages/@vuepress/core/lib/prepare/AppContext.js index f769842f..e7d71bb5 100755 --- a/packages/@vuepress/core/lib/prepare/AppContext.js +++ b/packages/@vuepress/core/lib/prepare/AppContext.js @@ -149,6 +149,16 @@ module.exports = class AppContext { .use(require('../internal-plugins/transformModule')) .use(require('../internal-plugins/dataBlock')) .use(require('../internal-plugins/frontmatterBlock')) + .use('@vuepress/container', { + type: 'slot', + before: info => `' + }) + .use('@vuepress/container', { + type: 'v-pre', + before: '
', + after: '
' + }) .use('@vuepress/last-updated', !!shouldUseLastUpdated) .use('@vuepress/register-components', { componentsDir: [ diff --git a/packages/@vuepress/core/package.json b/packages/@vuepress/core/package.json index a911d646..ebc88453 100644 --- a/packages/@vuepress/core/package.json +++ b/packages/@vuepress/core/package.json @@ -33,6 +33,7 @@ "@vue/babel-preset-app": "^3.1.1", "@vuepress/markdown": "^1.0.0-alpha.41", "@vuepress/markdown-loader": "^1.0.0-alpha.41", + "@vuepress/plugin-container": "^1.0.0-alpha.41", "@vuepress/plugin-last-updated": "^1.0.0-alpha.41", "@vuepress/plugin-register-components": "^1.0.0-alpha.41", "@vuepress/shared-utils": "^1.0.0-alpha.41", diff --git a/packages/@vuepress/markdown/index.js b/packages/@vuepress/markdown/index.js index 58c6a2a1..dd5271d9 100644 --- a/packages/@vuepress/markdown/index.js +++ b/packages/@vuepress/markdown/index.js @@ -14,7 +14,6 @@ const lineNumbersPlugin = require('./lib/lineNumbers') const componentPlugin = require('./lib/component') const hoistScriptStylePlugin = require('./lib/hoist') const convertRouterLinkPlugin = require('./lib/link') -const markdownSlotsContainersPlugin = require('./lib/markdownSlotsContainers') const snippetPlugin = require('./lib/snippet') const tocPlugin = require('./lib/tableOfContents') const emojiPlugin = require('markdown-it-emoji') @@ -74,10 +73,6 @@ module.exports = (markdown = {}) => { .use(hoistScriptStylePlugin) .end() - .plugin(PLUGINS.MARKDOWN_SLOTS_CONTAINERS) - .use(markdownSlotsContainersPlugin) - .end() - .plugin(PLUGINS.EMOJI) .use(emojiPlugin) .end() diff --git a/packages/@vuepress/markdown/lib/constant.js b/packages/@vuepress/markdown/lib/constant.js index 1334788e..ca9e0416 100644 --- a/packages/@vuepress/markdown/lib/constant.js +++ b/packages/@vuepress/markdown/lib/constant.js @@ -5,8 +5,6 @@ exports.PLUGINS = { SNIPPET: 'snippet', CONVERT_ROUTER_LINK: 'convert-router-link', HOIST_SCRIPT_STYLE: 'hoist-script-style', - CONTAINERS: 'containers', - MARKDOWN_SLOTS_CONTAINERS: 'markdown-slots-containers', ANCHOR: 'anchor', EMOJI: 'emoji', TOC: 'toc', diff --git a/packages/@vuepress/markdown/lib/markdownSlotsContainers.js b/packages/@vuepress/markdown/lib/markdownSlotsContainers.js deleted file mode 100644 index c70101f1..00000000 --- a/packages/@vuepress/markdown/lib/markdownSlotsContainers.js +++ /dev/null @@ -1,12 +0,0 @@ -const container = require('markdown-it-container') - -const SLOT_KEY = 'slot' - -module.exports = md => { - md - .use(container, SLOT_KEY, { - render: (tokens, idx) => tokens[idx].nesting === 1 - ? `' - }) -} diff --git a/packages/@vuepress/plugin-container/index.js b/packages/@vuepress/plugin-container/index.js index 4715ae04..8eefc9ee 100644 --- a/packages/@vuepress/plugin-container/index.js +++ b/packages/@vuepress/plugin-container/index.js @@ -26,8 +26,8 @@ module.exports = (options, context) => ({ if (!render) { if (before !== undefined && after !== undefined) { render = (tokens, index) => { - const token = tokens[index] - return token.nesting === 1 ? call(before, token) : call(after, token) + const info = tokens[index].info.trim().slice(type.length).trim + return tokens[index].nesting === 1 ? call(before, info) : call(after, info) } } else { render = (tokens, index) => { diff --git a/packages/@vuepress/theme-default/index.js b/packages/@vuepress/theme-default/index.js index 0f214621..0bf3d1e8 100644 --- a/packages/@vuepress/theme-default/index.js +++ b/packages/@vuepress/theme-default/index.js @@ -23,11 +23,6 @@ module.exports = (options, ctx) => ({ '@vuepress/plugin-nprogress', ['@vuepress/container', { type: 'tip' }], ['@vuepress/container', { type: 'warning' }], - ['@vuepress/container', { type: 'danger' }], - ['@vuepress/container', { - type: 'v-pre', - before: '
\n', - after: '
\n' - }] + ['@vuepress/container', { type: 'danger' }] ] }) diff --git a/packages/@vuepress/theme-default/package.json b/packages/@vuepress/theme-default/package.json index 0bc33208..96318932 100644 --- a/packages/@vuepress/theme-default/package.json +++ b/packages/@vuepress/theme-default/package.json @@ -31,6 +31,7 @@ "homepage": "https://github.com/vuejs/vuepress/packages/@vuepress/theme-default#readme", "dependencies": { "@vuepress/plugin-active-header-links": "^1.0.0-alpha.41", + "@vuepress/plugin-container": "^1.0.0-alpha.41", "@vuepress/plugin-nprogress": "^1.0.0-alpha.41", "@vuepress/plugin-search": "^1.0.0-alpha.41", "docsearch.js": "^2.5.2", diff --git a/packages/@vuepress/theme-default/styles/custom-blocks.styl b/packages/@vuepress/theme-default/styles/custom-blocks.styl index 33b3e206..2d07835b 100644 --- a/packages/@vuepress/theme-default/styles/custom-blocks.styl +++ b/packages/@vuepress/theme-default/styles/custom-blocks.styl @@ -27,21 +27,4 @@ a color $textColor -pre.vue-container - border-left-width: .5rem; - border-left-style: solid; - border-color: #42b983; - border-radius: 0px; - & > code - font-size: 14px !important; - & > p - margin: -5px 0 -20px 0; - code - background-color: #42b983 !important; - padding: 3px 5px; - border-radius: 3px; - color #000 - em - color #808080 - font-weight light diff --git a/packages/docs/docs/.vuepress/config.js b/packages/docs/docs/.vuepress/config.js index 999cc253..a76f0e22 100755 --- a/packages/docs/docs/.vuepress/config.js +++ b/packages/docs/docs/.vuepress/config.js @@ -81,7 +81,7 @@ module.exports = ctx => ({ }], ['@vuepress/container', { type: 'upgrade', - before: ({ info }) => ``, + before: info => ``, after: '', }], ], diff --git a/packages/docs/docs/.vuepress/styles/index.styl b/packages/docs/docs/.vuepress/styles/index.styl index 9014ba76..596a926f 100644 --- a/packages/docs/docs/.vuepress/styles/index.styl +++ b/packages/docs/docs/.vuepress/styles/index.styl @@ -4,5 +4,21 @@ // font-size 30px; //} - +pre.vue-container + border-left-width: .5rem; + border-left-style: solid; + border-color: #42b983; + border-radius: 0px; + & > code + font-size: 14px !important; + & > p + margin: -5px 0 -20px 0; + code + background-color: #42b983 !important; + padding: 3px 5px; + border-radius: 3px; + color #000 + em + color #808080 + font-weight light diff --git a/packages/docs/docs/plugin/official/plugin-container.md b/packages/docs/docs/plugin/official/plugin-container.md index 994cf2e8..b50794c8 100644 --- a/packages/docs/docs/plugin/official/plugin-container.md +++ b/packages/docs/docs/plugin/official/plugin-container.md @@ -49,14 +49,14 @@ The default title for the container. If no title was provided, `defaultTitle` wi - Type: `string | Function` - Default: `undefined` -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`. +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`. ### after - Type: `string | Function` - Default: `undefined` -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`. +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`. ### validate diff --git a/packages/docs/docs/zh/plugin/official/plugin-container.md b/packages/docs/docs/zh/plugin/official/plugin-container.md index e3d3e5f2..fcf47117 100644 --- a/packages/docs/docs/zh/plugin/official/plugin-container.md +++ b/packages/docs/docs/zh/plugin/official/plugin-container.md @@ -49,14 +49,14 @@ module.exports = { - 类型: `string | Function` - 默认值: `undefined` -要插入在容器前的 HTML。如果设置为一个函数,将传入当前的 `token` 作为第一个参数。如果设置了这个值,它将覆盖 `defaultTitle` 的效果。 +要插入在容器前的 HTML。如果设置为一个函数,将传入当前的 `info` 作为第一个参数。(在上面的例子中,`info` 的值为 `bar`。)如果设置了这个值,它将覆盖 `defaultTitle` 的效果。 ### after - 类型: `string | Function` - 默认值: `undefined` -要插入在容器后的 HTML。如果设置为一个函数,将传入当前的 `token` 作为第一个参数。如果设置了这个值,它将覆盖 `defaultTitle` 的效果。 +要插入在容器后的 HTML。如果设置为一个函数,将传入当前的 `info` 作为第一个参数。(在上面的例子中,`info` 的值为 `bar`。)如果设置了这个值,它将覆盖 `defaultTitle` 的效果。 ### validate diff --git a/yarn.lock b/yarn.lock index c33c127a..2bcf92a0 100644 --- a/yarn.lock +++ b/yarn.lock @@ -6580,10 +6580,6 @@ markdown-it-emoji@^1.4.0: version "1.4.0" resolved "https://registry.yarnpkg.com/markdown-it-emoji/-/markdown-it-emoji-1.4.0.tgz#9bee0e9a990a963ba96df6980c4fddb05dfb4dcc" -markdown-it-table-of-contents@^0.4.0: - version "0.4.0" - resolved "https://registry.yarnpkg.com/markdown-it-table-of-contents/-/markdown-it-table-of-contents-0.4.0.tgz#950541bec9a365a75265f5265a09dc0cb5935909" - markdown-it@^8.4.1: version "8.4.2" resolved "https://registry.yarnpkg.com/markdown-it/-/markdown-it-8.4.2.tgz#386f98998dc15a37722aa7722084f4020bdd9b54" -- GitLab