From cc565adf5411a6eacf389bd8d4f9fb90a05a983f Mon Sep 17 00:00:00 2001 From: Yuki Hattori Date: Sun, 13 Nov 2022 22:29:11 +0900 Subject: [PATCH] Fix invalid example --- api.md | 21 ++++++++++++++------- src/plugin.js | 4 ++-- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/api.md b/api.md index 90722c5..9eefdc5 100644 --- a/api.md +++ b/api.md @@ -24,9 +24,9 @@ import { Element, Marpit, Theme, ThemeSet } from '@marp-team/marpit' ### Modules _(for internal)_ -**Modules** section is documented about internal modules, that is includes plugins of markdown-it and PostCSS. +**Modules** section is documented about internal modules, that includes plugins for markdown-it and PostCSS, for helping to learn Marpit's architecture by contributors and plugin authors. -Basically _Marpit user should not use internal module directly._ +⚠️ **Do not use internal modules directly.** They might be changed the specification without following semantic versioning. --- @@ -42,12 +42,19 @@ Marpit's plugin interface has compatible with [markdown-it](https://github.com/m When plugin was used through [`Marpit.use()`](Marpit.html#use), it can access to current Marpit instance via `marpit` member of the passed markdown-it instance. -`@marp-team/marpit/plugin` provides a helper for creating Marpit plugin. A generated plugin promises an existance of `marpit` member. +`@marp-team/marpit/plugin` provides [a helper for creating Marpit plugin](module-plugin.html). A generated plugin promises an existance of `marpit` member. ```javascript -const plugin = require('@marp-team/marpit/plugin') - -module.exports = plugin(({ marpit }) => { - // Plugin code (Add theme, define custom directives, etc...) +import { marpitPlugin } from '@marp-team/marpit/plugin' + +export default marpitPlugin(({ marpit }) => { + // Add your plugin code here (Add theme, define custom directives, etc...) + /* + marpit.customDirectives.local.yourDirective = (value) => { + return { yourDirective: value } + } + */ }) ``` + +If the user tried to use the generated Marpit plugin from this helper as markdown-it plugin wrongly, the plugin throws an error. Thus, you can mark the plugin as dedicated to Marpit. diff --git a/src/plugin.js b/src/plugin.js index 7f206df..1e56075 100644 --- a/src/plugin.js +++ b/src/plugin.js @@ -9,7 +9,7 @@ * @example * import { marpitPlugin } from '@marp-team/marpit/plugin' * - * export default yourPlugin = marpitPlugin((md) => { + * export default marpitPlugin((md) => { * // Compatible with markdown-it plugin * md.renderer.rules.your_rule = (tokens, idx, options, env, self) => { * // ... @@ -21,7 +21,7 @@ * marpit.customDirectives.local.yourDirective = (value) => { * return { yourDirective: value } * } - * )} + * }) * * @function marpitPlugin * @param {Function} plugin Base plugin for markdown-it.