插件

插件本质上是一个纯对象(pure object):

  1. const showAuthor = {
  2. // 插件名称
  3. name: 'showAuthor',
  4. // 扩展核心功能
  5. extend(api) {
  6. api.processMarkdown(text => {
  7. return text.replace(/{author}/g, '> Written by EGOIST')
  8. })
  9. }
  10. }
  11. new Docute({
  12. // ...
  13. plugins: [
  14. showAuthor
  15. ]
  16. })

示例:

  1. # Page 标题
  2. {author}

要接收插件中的选项,可以使用工厂函数:

  1. const myPlugin = opts => {
  2. return {
  3. name: 'my-plugin',
  4. extend(api) {
  5. // 使用 `opts` 和 `api` 做点什么
  6. }
  7. }
  8. }
  9. new Docute({
  10. plugins: [
  11. myPlugin({ foo: true })
  12. ]
  13. })

欲了解更多如何开发插件的信息,请查阅插件 API