kjelsrud.dev/node_modules/rehype-stringify/lib/index.js
2023-07-19 21:31:30 +02:00

22 lines
652 B
JavaScript

/**
* @typedef {import('hast').Root} Root
* @typedef {Root|Root['children'][number]} Node
* @typedef {import('hast-util-to-html').Options} Options
*/
import {toHtml} from 'hast-util-to-html'
/** @type {import('unified').Plugin<[Options?]|Array<void>, Node, string>} */
export default function rehypeStringify(config) {
const processorSettings = /** @type {Options} */ (this.data('settings'))
const settings = Object.assign({}, processorSettings, config)
Object.assign(this, {Compiler: compiler})
/**
* @type {import('unified').CompilerFunction<Node, string>}
*/
function compiler(tree) {
return toHtml(tree, settings)
}
}