Files
sgauthier 6e64e138e2
All checks were successful
Publish To Prod / deploy_and_publish (push) Successful in 35s
planning
2024-10-14 09:15:30 +02:00

44 lines
979 B
JavaScript

'use strict'
var mdast2hast = require('mdast-util-to-hast')
module.exports = remark2rehype
// Attacher.
// If a destination is given, runs the destination with the new hast tree
// (bridge mode).
// Without destination, returns the tree: further plugins run on that tree
// (mutate mode).
function remark2rehype(destination, options) {
if (destination && !destination.process) {
options = destination
destination = null
}
return destination ? bridge(destination, options) : mutate(options)
}
// Bridge mode.
// Runs the destination with the new hast tree.
function bridge(destination, options) {
return transformer
function transformer(node, file, next) {
destination.run(mdast2hast(node, options), file, done)
function done(err) {
next(err)
}
}
}
// Mutate-mode.
// Further transformers run on the hast tree.
function mutate(options) {
return transformer
function transformer(node) {
return mdast2hast(node, options)
}
}