From b71867348d51dd5fb5fe671c9ecd2b5e95a5c72e Mon Sep 17 00:00:00 2001 From: Titus Wormer Date: Sun, 3 Oct 2021 17:29:48 +0200 Subject: [PATCH] Fix support for explicit nullish `processor` Closes GH-21. --- index.js | 4 ++-- test.js | 11 +++++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 62f029c..444a59c 100644 --- a/index.js +++ b/index.js @@ -26,12 +26,12 @@ import {toHast} from 'mdast-util-to-hast' * Options passed to `mdast-util-to-hast`. */ const remarkRehype = - /** @type {(import('unified').Plugin<[Processor, Options?]|[Options]|[], MdastRoot>)} */ + /** @type {(import('unified').Plugin<[Processor, Options?]|[null|undefined, Options?]|[Options]|[], MdastRoot>)} */ ( function (destination, options) { return destination && 'run' in destination ? bridge(destination, options) - : mutate(destination) + : mutate(destination || options) } ) diff --git a/test.js b/test.js index e9e1a65..260a094 100644 --- a/test.js +++ b/test.js @@ -28,6 +28,17 @@ test('remarkRehype', (t) => { 'should mutate with options' ) + t.equal( + unified() + .use(remarkParse) + .use(remarkRehype, null, {allowDangerousHtml: true}) + .use(rehypeStringify, {allowDangerousHtml: true}) + .processSync('## Hello, world! ##') + .toString(), + '

Hello, world!

', + 'should mutate with `processor: null` and options' + ) + t.equal( unified() .use(remarkParse)