mirror of
https://github.com/CopterExpress/clover.git
synced 2026-05-26 21:19:35 +00:00
Implement plugin to convert gitbook rich-quotes to custom containers
This commit is contained in:
@@ -44,6 +44,7 @@ module.exports = {
|
||||
},
|
||||
plugins: [
|
||||
'@vuepress/plugin-search',
|
||||
'vuepress-plugin-copy-code2'
|
||||
'vuepress-plugin-copy-code2',
|
||||
require('./rich-quotes')
|
||||
]
|
||||
}
|
||||
|
||||
37
docs/.vuepress/rich-quotes.js
Normal file
37
docs/.vuepress/rich-quotes.js
Normal file
@@ -0,0 +1,37 @@
|
||||
// Plugin to convert GitBook rich quotes to custom containers
|
||||
|
||||
const types = {
|
||||
info: 'tip',
|
||||
note: 'tip',
|
||||
tag: 'tip',
|
||||
comment: 'tip',
|
||||
hint: 'tip',
|
||||
success: 'tip',
|
||||
warning: 'warning',
|
||||
caution: 'warning',
|
||||
danger: 'danger',
|
||||
quote: 'tip'
|
||||
}
|
||||
|
||||
function replace(src) {
|
||||
return src.replace(/^> \*\*(.*?)\*\* (.*\n(>.*\n)*)/gm, function (match, type, text) {
|
||||
text = text.replace(/^>/gm, '');
|
||||
return `::: ${types[type.toLowerCase()]}\n${text}\n:::`;
|
||||
});
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
name: 'vuepress-plugin-rich-quotes',
|
||||
extendsMarkdown: (md) => {
|
||||
var _render = md.render;
|
||||
|
||||
// TODO: a rough hack to replace rich quotes
|
||||
// TODO: use proper plugin api
|
||||
|
||||
md.render = function(src, env) {
|
||||
src = replace(src);
|
||||
return _render.call(md, src, env);
|
||||
}
|
||||
},
|
||||
|
||||
};
|
||||
Reference in New Issue
Block a user