插件
插件本质上是一个纯对象(pure object):
const showAuthor = {
// 插件名称
name: 'showAuthor',
// 扩展核心功能
extend(api) {
api.processMarkdown(text => {
return text.replace(/{author}/g, '> Written by EGOIST')
})
}
}
new Docute({
// ...
plugins: [
showAuthor
]
})
示例:
# Page 标题
{author}
要接收插件中的选项,可以使用工厂函数:
const myPlugin = opts => {
return {
name: 'my-plugin',
extend(api) {
// 使用 `opts` 和 `api` 做点什么
}
}
}
new Docute({
plugins: [
myPlugin({ foo: true })
]
})
欲了解更多如何开发插件的信息,请查阅插件 API。