-
Notifications
You must be signed in to change notification settings - Fork 4.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Custom Containers with more options #536
Comments
How about override the default style in |
I don't want to override the style, I also want to continue to use the default style. |
You can create your custom container by extending the Closing as this can be done in userland and we don't plan to add built-in support for it. |
This is nearly a direct copy paste of the code used by Vuepress to generate custom containers (some minor changes so that our internal linting rules and style checks pass): const container = require('markdown-it-container')
function createContainer(type, defaultTitle) {
return [container, type, {
render(tokens, idx) {
const token = tokens[idx]
const info = token.info.trim().slice(type.length).trim()
const title = info || defaultTitle
if (token.nesting === 1) {
return `<div class="${type} custom-block"><p class="custom-block-title">${title}</p>\n`
} else {
return `</div>\n`
}
}
}]
}
// md needs to be an instance of markdown-it (in our case, the one used by mavonEditor)
module.exports = (md) => {
md
.use(...createContainer('tip', 'TIP') )
.use(...createContainer('warning', 'WARNING') )
.use(...createContainer('danger', 'WARNING') )
} To create your own custom container that you can style how you like, just create another one like: Now you can style is with Update: just noticed Vue has updated custom containers to explicitly escape Vue syntax - follow the link and see if you also need that for your own custom containers. |
@GrayedFox I can't seem to open the link you attached anymore, could you please explain a bit more about how you implemented this in your code? Where shall I add the function? I'm new to VuePress, thanks! |
@lunaceee For now you can try @vuepress/plugin-container. |
Thanks @shigma Didn't realize it's part of the 1.x feature. :) |
@shigma I installed the plugin, got the |
Our default theme has provided styles for If you want to define your own custom blocks, you should provide styles by yourself. |
I'm stuck here. I've installed the plugin, used it in config, but still. It doesn't work. I don't know what I'm doing wrong. Look: ['@vuepress-plugin-container', {
type: 'warning',
defaultTitle: 'WARNING',
}],
['@vuepress-plugin-container', {
type: 'tip',
defaultTitle: 'TIP',
}],
['@vuepress-plugin-container', {
type: 'theorem',
before: tip => `<div class="theorem"><p class="title">${tip}</p>`,
after: '</div>',
}], |
Hi @germanbobadilla ,You don't need to manually install nor config |
Feature request
First
vuepress/lib/markdown/containers.js
Line 22 in cd8ee42
Sometimes l just want
Custom Containers
without title.Second
And is it possible that I can customize its class? So I can simply create a custom container with custom css.
The text was updated successfully, but these errors were encountered: