diff --git a/lib/index.js b/lib/index.js index 2b24764..d3392cb 100644 --- a/lib/index.js +++ b/lib/index.js @@ -152,8 +152,12 @@ export default function remarkRehype(destination, options) { */ return function (tree, file) { // Cast because root in -> root out. + // To do: in the future, disallow ` || options` fallback. + // With `unified-engine`, `destination` can be `undefined` but + // `options` will be the file set. + // We should not pass that as `options`. return /** @type {HastRoot} */ ( - toHast(tree, {file, ...(options || destination)}) + toHast(tree, {file, ...(destination || options)}) ) } } diff --git a/package.json b/package.json index 8157372..bb5e15b 100644 --- a/package.json +++ b/package.json @@ -46,6 +46,7 @@ "@types/node": "^22.0.0", "c8": "^10.0.0", "prettier": "^3.0.0", + "rehype-slug": "^6.0.0", "rehype-stringify": "^10.0.0", "remark-cli": "^12.0.0", "remark-parse": "^11.0.0", diff --git a/test.js b/test.js index 7cd3b09..37ee527 100644 --- a/test.js +++ b/test.js @@ -1,3 +1,9 @@ +/** + * @import {Text as HastText} from 'hast' + * @import {Handler} from 'mdast-util-to-hast' + * @import {Text as MdastText} from 'mdast' + */ + import assert from 'node:assert/strict' import test from 'node:test' import rehypeStringify from 'rehype-stringify' @@ -23,25 +29,42 @@ test('remarkRehype', async function (t) { .use(remarkParse) .use(remarkRehype) .use(rehypeStringify) - .process('## Hello, world! ##') + .process('# hi') ), - '
hi
') }) }) + +/** + * @type {Handler} + * @param {MdastText} node + * @returns {HastText} + */ +function text(_, node) { + return {type: 'text', value: node.value.toUpperCase()} +}