From 0174dfccac4f6254f3343d39d50de2e6304ef2cf Mon Sep 17 00:00:00 2001 From: Titus Wormer Date: Thu, 11 Jan 2024 10:50:59 +0100 Subject: [PATCH] Add `file` to options passed to `mdast-util-to-hast` Related-to: remarkjs/remark#1272. Related-to: syntax-tree/mdast-util-to-hast@59ecd14. --- lib/index.js | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/lib/index.js b/lib/index.js index 49c9b4b..4a7eae5 100644 --- a/lib/index.js +++ b/lib/index.js @@ -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} Options + * * @callback TransformBridge * Bridge-mode. * @@ -138,7 +140,9 @@ 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) } } @@ -146,8 +150,10 @@ export default function remarkRehype(destination, options) { /** * @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)}) + ) } }