-
-
Notifications
You must be signed in to change notification settings - Fork 84
/
index.js
31 lines (27 loc) · 830 Bytes
/
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
/**
* @typedef {import('hast').Root} Root
* @typedef {import('hast-util-to-html').Options} Options
* @typedef {import('unified').Compiler<Root, string>} Compiler
*/
import {toHtml} from 'hast-util-to-html'
/**
* Plugin to add support for serializing as HTML.
*
* @param {Options | null | undefined} [options]
* Configuration (optional).
* @returns {undefined}
* Nothing.
*/
export default function rehypeStringify(options) {
/** @type {import('unified').Processor<undefined, undefined, undefined, Root, string>} */
// @ts-expect-error: TS in JSDoc generates wrong types if `this` is typed regularly.
const self = this
const settings = {...self.data('settings'), ...options}
self.compiler = compiler
/**
* @type {Compiler}
*/
function compiler(tree) {
return toHtml(tree, settings)
}
}