Skip to content

Commit

Permalink
feat($markdown): markdown slot shortcut
Browse files Browse the repository at this point in the history
  • Loading branch information
ulivz committed Oct 22, 2018
1 parent 704031f commit bde4ac4
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
12 changes: 12 additions & 0 deletions packages/@vuepress/markdown/lib/contentSlotsContainers.js
Original file line number Diff line number Diff line change
@@ -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
? `<template slot="${tokens[idx].info.trim().slice(SLOT_KEY.length).trim()}">`
: '</template>'
})
}
5 changes: 5 additions & 0 deletions packages/@vuepress/markdown/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -75,6 +76,10 @@ module.exports = ({
.use(containersPlugin)
.end()

.plugin('content-slots-containers')
.use(contentSlotsContainersPlugin)
.end()

.plugin('emoji')
.use(emojiPlugin)
.end()
Expand Down

0 comments on commit bde4ac4

Please sign in to comment.