From caa1748fe6b2473212f6eec3f68b1d19a559508b Mon Sep 17 00:00:00 2001 From: Black Ram <67595890+BlackRam-oss@users.noreply.github.com> Date: Tue, 6 May 2025 17:51:35 +0000 Subject: [PATCH 1/5] Add onComplete callback for completing processing in MarkdownHooks --- lib/index.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/index.js b/lib/index.js index 06f07e1..ed191b4 100644 --- a/lib/index.js +++ b/lib/index.js @@ -82,6 +82,8 @@ * Configuration specifically for {@linkcode MarkdownHooks}. * @property {ReactNode | null | undefined} [fallback] * Content to render while the processor processing the markdown (optional). + * @property {function(): void | null | undefined} [onComplete] + * Callback when the processor is done processing. */ /** @@ -232,6 +234,7 @@ export function MarkdownHooks(options) { if (!cancelled) { setError(error) setTree(tree) + options.onComplete?.() } }) From 6ade36e8d1f8c5e2ceccb9b09e944405e4dc783f Mon Sep 17 00:00:00 2001 From: Black Ram <67595890+BlackRam-oss@users.noreply.github.com> Date: Tue, 6 May 2025 17:53:10 +0000 Subject: [PATCH 2/5] Update the onComplete callback type to include the node and error --- lib/index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/index.js b/lib/index.js index ed191b4..626906d 100644 --- a/lib/index.js +++ b/lib/index.js @@ -82,7 +82,7 @@ * Configuration specifically for {@linkcode MarkdownHooks}. * @property {ReactNode | null | undefined} [fallback] * Content to render while the processor processing the markdown (optional). - * @property {function(): void | null | undefined} [onComplete] + * @property {function(Root | undefined, Error | undefined): void | null | undefined} [onComplete] * Callback when the processor is done processing. */ @@ -234,7 +234,7 @@ export function MarkdownHooks(options) { if (!cancelled) { setError(error) setTree(tree) - options.onComplete?.() + options.onComplete?.(tree, error) } }) From 747c23a1659ac9633b3c75c9772cd757ccd83b3c Mon Sep 17 00:00:00 2001 From: Black Ram <67595890+BlackRam-oss@users.noreply.github.com> Date: Wed, 7 May 2025 10:28:33 +0000 Subject: [PATCH 3/5] Add onComplete to Markdown hook to handle processing completion --- lib/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/index.js b/lib/index.js index 626906d..ea8426d 100644 --- a/lib/index.js +++ b/lib/index.js @@ -246,7 +246,7 @@ export function MarkdownHooks(options) { cancelled = true } }, - [options.children, processor] + [options.children, processor, options.onComplete] ) if (error) throw error From debec9e00a41f5ee3744ea02954252d10d3dd517 Mon Sep 17 00:00:00 2001 From: Black Ram <67595890+BlackRam-oss@users.noreply.github.com> Date: Wed, 7 May 2025 12:37:11 +0000 Subject: [PATCH 4/5] Update the onComplete callback type to include file, tree, and error --- lib/index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/index.js b/lib/index.js index ea8426d..ccba9fe 100644 --- a/lib/index.js +++ b/lib/index.js @@ -82,7 +82,7 @@ * Configuration specifically for {@linkcode MarkdownHooks}. * @property {ReactNode | null | undefined} [fallback] * Content to render while the processor processing the markdown (optional). - * @property {function(Root | undefined, Error | undefined): void | null | undefined} [onComplete] + * @property {(file: VFile, hast: Root | undefined, error: Error | undefined) => unknown} [onComplete] * Callback when the processor is done processing. */ @@ -234,7 +234,7 @@ export function MarkdownHooks(options) { if (!cancelled) { setError(error) setTree(tree) - options.onComplete?.(tree, error) + options.onComplete?.(file, tree, error) } }) From e2c1dcfda01dc34b3910d99b03c1e5db1249cb5d Mon Sep 17 00:00:00 2001 From: Black Ram <67595890+BlackRam-oss@users.noreply.github.com> Date: Thu, 8 May 2025 08:02:02 +0000 Subject: [PATCH 5/5] Add test for `onComplete` support in MarkdownHooks --- test.jsx | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/test.jsx b/test.jsx index 1b254db..3134491 100644 --- a/test.jsx +++ b/test.jsx @@ -1167,6 +1167,30 @@ test('MarkdownHooks', async function (t) { assert.equal(result.container.innerHTML, '
a
') }) + await t.test('should support `onComplete`', async function () { + const plugin = deferPlugin() + let succes = false + render( +