-
-
Notifications
You must be signed in to change notification settings - Fork 352
/
index.js
42 lines (37 loc) · 1.12 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
/**
* @import {Root} from 'mdast'
* @import {Options as FromMarkdownOptions} from 'mdast-util-from-markdown'
* @import {Parser, Processor} from 'unified'
*/
/**
* @typedef {Omit<FromMarkdownOptions, 'extensions' | 'mdastExtensions'>} Options
*/
import {fromMarkdown} from 'mdast-util-from-markdown'
/**
* Aadd support for parsing from markdown.
*
* @param {Readonly<Options> | null | undefined} [options]
* Configuration (optional).
* @returns {undefined}
* Nothing.
*/
export default function remarkParse(options) {
/** @type {Processor<Root>} */
// @ts-expect-error: TS in JSDoc generates wrong types if `this` is typed regularly.
const self = this
self.parser = parser
/**
* @type {Parser<Root>}
*/
function parser(document) {
return fromMarkdown(document, {
...self.data('settings'),
...options,
// Note: these options are not in the readme.
// The goal is for them to be set by plugins on `data` instead of being
// passed by users.
extensions: self.data('micromarkExtensions') || [],
mdastExtensions: self.data('fromMarkdownExtensions') || []
})
}
}