Adding additional plugins
YFM uses markdown-it as a parser, so you can add any plugin from the markdown-it plugin list.
Adding plugins
Before adding a plugin, install the package that contains it using the npm i <plug_name>
command. For example, to install markdown-it-emoji, run:
npm i markdown-it-emoji
-
Add the plugin in your code using the
require()
orimport()
function:const plugin1 = require('<plug_name>');
-
For the
plugins
parameter, add a new plugin to the array:const {result: {html, meta}, logs} = transform(content, {plugins: [<plug_name>]});
Example:
const fs = require('fs');
const transform = require('@diplodoc/transform');
const cut = require('@diplodoc/transform/lib/plugins/cut');
const sup = require('@diplodoc/transform/lib/plugins/sup');
const emoji = require('markdown-it-emoji');
const content = fs.readFileSync(filePath, 'utf');
const {result: {html, meta}, logs} = transform(content, {plugins: [cut, sup, emoji]});
Warning
When overriding the plugins
parameter, you must reconnect YFM plugins. To do this, import them from the @diplodoc/transform
package and pass them in the plugin array.
- Move the installed plugin to the
./plugins
folder in the@diplodoc/cli
package.
Tip
If you don't want to transfer the necessary plugins before each build, build your own Builder:
- Install the source code with GitHub.
- Move the additional plugins to the
./plugins
folder. - Build the Builder by following the GitHub instructions.
Passing parameters
YFM applies unknown parameters from the options
object to all plugins, so to pass parameters, add them to the options
object.