diff --git a/README.md b/README.md index a7ea5cf..590d872 100644 --- a/README.md +++ b/README.md @@ -117,12 +117,13 @@ Parse a markdown string using the current options and return HTML. ### Options -| Option | Type | Default | Description | -| --------------- | --------- | ---------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| `dlx2html` | Object | [See documentation here.][dlx2html] | Options to pass to `dlx2html` (the library that converts interlinear examples to HTML). If options are provided in a YAML header within fenced code blocks, those options override these ones. | -| `markdown` | Object |
{
html: true,
typographer: true
}
| Options to pass to `markdown-it`. `typographer` and `html` are enabled by default. |
-| `translations` | `span\|q` | `span` | Whether to use `` or a `` element for translations. ``s will wrap the inner text in single quotes. | -| `scription2dlx` | Object | [See documentation here.][scription2html] | Options to pass to `scription2html` (the library that parses interlinear examples). If options are provided in a YAML header within fenced code blocks, those options override these ones. | +| Option | Type | Default | Description | +| --------------- | --------- | ---------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| `dlx2html` | Object | [See documentation here.][dlx2html] | Options to pass to `dlx2html` (the library that converts interlinear examples to HTML). If options are provided in a YAML header within fenced code blocks, those options override these ones. | +| `markdown` | Object || Options to pass to `markdown-it`. `typographer` and `html` are enabled by default. | +| `plugins` | Object | `{}` | Options to pass to any of the `markdown-it` plugins. Each key should be the name of the plugin, and the value is the options to pass to it. Example: `{ '@mdit/plugin-alert': { /* options */ } }` You can see a complete list of the `markdown-it` plugins that are used in this library in the source code [here][source]. | +| `translations` | `span\|q` | `span` | Whether to use `` or a `{
html: true,
typographer: true
}` element for translations. ``s will wrap the inner text in single quotes. | +| `scription2dlx` | Object | [See documentation here.][scription2html] | Options to pass to `scription2html` (the library that parses interlinear examples). If options are provided in a YAML header within fenced code blocks, those options override these ones. | [alert]: https://docs.github.com/en/get-started/writing-on-github/getting-started-with-writing-and-formatting-on-github/basic-writing-and-formatting-syntax#alerts @@ -137,6 +138,7 @@ Parse a markdown string using the current options and return HTML. [Scription]: https://scription.digitallinguistics.io/ [scription2html]: https://github.com/digitallinguistics/scription2html [spec]: https://github.com/digitallinguistics/ling-markdown-spec +[source]: https://github.com/digitallinguistics/ling-md/blob/main/index.js [summary-details]: https://www.npmjs.com/package/markdown-it-collapsible [table-captions]: https://github.com/martinring/markdown-it-table-captions [tables]: https://www.markdownguide.org/extended-syntax/#tables diff --git a/index.js b/index.js index 893cba4..3e10243 100644 --- a/index.js +++ b/index.js @@ -44,6 +44,7 @@ export default class Parser { constructor({ dlx2html = {}, markdown = defaultMarkdownOptions, + plugins = {}, scription2dlx = {}, translations = `span`, } = {}) { @@ -53,20 +54,20 @@ export default class Parser { this.engine = createMarkdownParser(markdownOptions) this.engine - .use(alert) - .use(attributes) // Must come before headerAnchors + .use(alert, plugins[`@mdit/plugin-alert`]) + .use(attributes, plugins[`markdown-it-attrs`]) // Must come before headerAnchors .use(boldItalic) .use(bracketedSpans) .use(defLists) .use(footnotes) .use(fractions) .use(glosses) - .use(headerAnchors) + .use(headerAnchors, plugins[`markdown-it-anchor`]) .use(inlineTranslations, { tag: translations }) .use(insertedText) .use(interlinears, { dlx2html, scription2dlx }) .use(markedText) - .use(mathjax, createMathjaxInstance()) + .use(mathjax, createMathjaxInstance(plugins[`@mdit/plugin-mathjax`])) .use(ordinals) .use(orthographic) .use(phonemic) @@ -74,8 +75,8 @@ export default class Parser { .use(subscript) .use(superscript) .use(tableCaptions) - .use(tasklist) - .use(toc) + .use(tasklist, plugins[`@mdit/plugin-tasklist`]) + .use(toc, plugins[`markdown-it-table-of-contents`]) } diff --git a/index.test.js b/index.test.js index 98580b7..48ef891 100644 --- a/index.test.js +++ b/index.test.js @@ -254,4 +254,12 @@ I love you }) + it(`option: plugins`, function() { + const options = { plugins: { 'markdown-it-anchor': { permalink: false } } } + const md = `# Header` + const parser = new Parser(options) + const html = parser.parse(md) + expect(html).to.equal(`Header
\n`) + }) + })