From bde4ac4b7ccc5c23cb4cbebd537ee7f631b0347c Mon Sep 17 00:00:00 2001 From: ULIVZ <472590061@qq.com> Date: Tue, 23 Oct 2018 02:20:37 +0800 Subject: [PATCH] feat($markdown): markdown slot shortcut --- .../@vuepress/markdown/lib/contentSlotsContainers.js | 12 ++++++++++++ packages/@vuepress/markdown/lib/index.js | 5 +++++ 2 files changed, 17 insertions(+) create mode 100644 packages/@vuepress/markdown/lib/contentSlotsContainers.js diff --git a/packages/@vuepress/markdown/lib/contentSlotsContainers.js b/packages/@vuepress/markdown/lib/contentSlotsContainers.js new file mode 100644 index 0000000000..c70101f122 --- /dev/null +++ b/packages/@vuepress/markdown/lib/contentSlotsContainers.js @@ -0,0 +1,12 @@ +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/markdown/lib/index.js b/packages/@vuepress/markdown/lib/index.js index 2b44e8c25d..e11c324a13 100644 --- a/packages/@vuepress/markdown/lib/index.js +++ b/packages/@vuepress/markdown/lib/index.js @@ -13,6 +13,7 @@ const componentPlugin = require('./component') const hoistScriptStylePlugin = require('./hoist') const convertRouterLinkPlugin = require('./link') const containersPlugin = require('./containers') +const contentSlotsContainersPlugin = require('./contentSlotsContainers') const snippetPlugin = require('./snippet') const emojiPlugin = require('markdown-it-emoji') const anchorPlugin = require('markdown-it-anchor') @@ -75,6 +76,10 @@ module.exports = ({ .use(containersPlugin) .end() + .plugin('content-slots-containers') + .use(contentSlotsContainersPlugin) + .end() + .plugin('emoji') .use(emojiPlugin) .end()