Skip to content

Commit

Permalink
Add file to options passed to mdast-util-to-hast
Browse files Browse the repository at this point in the history
  • Loading branch information
wooorm committed Jan 11, 2024
1 parent cf87ade commit 0174dfc
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@
/**
* @typedef {import('hast').Root} HastRoot
* @typedef {import('mdast').Root} MdastRoot
* @typedef {import('mdast-util-to-hast').Options} Options
* @typedef {import('mdast-util-to-hast').Options} ToHastOptions
* @typedef {import('unified').Processor} Processor
* @typedef {import('vfile').VFile} VFile
*/

/**
* @typedef {Omit<ToHastOptions, 'file'>} Options
*
* @callback TransformBridge
* Bridge-mode.
*
Expand Down Expand Up @@ -138,16 +140,20 @@ export default function remarkRehype(destination, options) {
*/
return async function (tree, file) {
// Cast because root in -> root out.
const hastTree = /** @type {HastRoot} */ (toHast(tree, options))
const hastTree = /** @type {HastRoot} */ (
toHast(tree, {file, ...options})
)
await destination.run(hastTree, file)
}
}

/**
* @type {TransformMutate}
*/
return function (tree) {
return function (tree, file) {
// Cast because root in -> root out.
return /** @type {HastRoot} */ (toHast(tree, options || destination))
return /** @type {HastRoot} */ (
toHast(tree, {file, ...(options || destination)})
)
}
}

0 comments on commit 0174dfc

Please sign in to comment.