diff --git a/README.md b/README.md index a8707f4..a7ea5cf 100644 --- a/README.md +++ b/README.md @@ -32,12 +32,12 @@ The library enables the following features by default: ### Linguistics -| Feature | Markdown | HTML | -| ------------------- | --------------------------------- | ------------------------------------------------ | -| grammatical glosses | `^^fut^^` | `fut` | -| inline examples | `The word *perro* is Spanish.` | `

The word perro is Spanish.

` | -| inline translations | `The word *perro* means ''dog''.` | `

The word perro means dog.

` | -| interlinear glosses |
\```igl
ninakupenda
ni-na-ku-pend-a
1sg.SUBJ-PRES-2sg.OBJ-love-IND
I love you
```
| [See documentation here.][dlx2html] | +| Feature | Markdown | HTML | +| ------------------- | ------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------ | +| grammatical glosses | `^^fut^^` | `fut` | +| inline examples | `The word *perro* is Spanish.` | `

The word perro is Spanish.

` | +| inline translations | `The word *perro* means ''dog''.` | `

The word perro means dog.

` | +| interlinear glosses |
\```igl
ninakupenda
ni-na-ku-pend-a
1sg.SUBJ-PRES-2sg.OBJ-love-IND
I love you
```
| [See documentation here.][dlx2html] | ### General @@ -117,10 +117,12 @@ Parse a markdown string using the current options and return HTML. ### Options -| Option | Type | Default | Description | -| -------------- | --------- | ---------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------- | -| `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. | +| 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. | [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 @@ -133,6 +135,7 @@ Parse a markdown string using the current options and return HTML. [i]: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/i [markdown-it]: https://github.com/markdown-it/markdown-it#readme [Scription]: https://scription.digitallinguistics.io/ +[scription2html]: https://github.com/digitallinguistics/scription2html [spec]: https://github.com/digitallinguistics/ling-markdown-spec [summary-details]: https://www.npmjs.com/package/markdown-it-collapsible [table-captions]: https://github.com/martinring/markdown-it-table-captions diff --git a/index.js b/index.js index 16309ba..7e533b3 100644 --- a/index.js +++ b/index.js @@ -39,8 +39,10 @@ export default class Parser { * Create a new linguistics markdown parser instance. */ constructor({ - markdown = defaultMarkdownOptions, - translations = `span`, + dlx2html = {}, + markdown = defaultMarkdownOptions, + scription2dlx = {}, + translations = `span`, } = {}) { const markdownOptions = Object.assign({}, defaultMarkdownOptions, markdown) @@ -59,7 +61,7 @@ export default class Parser { .use(headerAnchors) .use(inlineTranslations, { tag: translations }) .use(insertedText) - .use(interlinears) + .use(interlinears, { dlx2html, scription2dlx }) .use(markedText) .use(mathjax, createMathjaxInstance()) .use(ordinals) diff --git a/plugins/interlinears.js b/plugins/interlinears.js index 4b2f793..335b242 100644 --- a/plugins/interlinears.js +++ b/plugins/interlinears.js @@ -4,7 +4,15 @@ import scription2dlx from '@digitallinguistics/scription2dlx' const yamlHeaderRegExp = /^---\n(?
.*?)\n---\n/sv -export default function InterlinearsPlugin(md) { +const defaultOptions = { + dlx2html: { + glosses: true, + tag: `li`, + }, + scription2dlx: {}, +} + +export default function InterlinearsPlugin(md, pluginOptions = {}) { const originalRenderer = md.renderer.rules.fence @@ -16,11 +24,13 @@ export default function InterlinearsPlugin(md) { if (lang === `igl`) { - const header = token.content.match(yamlHeaderRegExp)?.groups?.header - const options = header ? jsYaml.load(header) : {} - const scription = token.content.replace(yamlHeaderRegExp, ``) - const data = scription2dlx(scription, options.scription2dlx) - const html = dlx2html(data, options.dlx2html) + const header = token.content.match(yamlHeaderRegExp)?.groups?.header + const yamlOptions = header ? jsYaml.load(header) : {} + const scription = token.content.replace(yamlHeaderRegExp, ``) + const scription2dlxOptions = Object.assign({}, defaultOptions.scription2dlx, pluginOptions.scription2dlx, yamlOptions.scription2dlx) + const data = scription2dlx(scription, scription2dlxOptions) + const dlx2htmlOptions = Object.assign({}, defaultOptions.dlx2html, pluginOptions.dlx2html, yamlOptions.dlx2html) + const html = dlx2html(data, dlx2htmlOptions) return html