diff --git a/lib/index.js b/lib/index.js index 06f07e1..ccba9fe 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 {(file: VFile, hast: Root | undefined, error: Error | undefined) => unknown} [onComplete] + * Callback when the processor is done processing. */ /** @@ -232,6 +234,7 @@ export function MarkdownHooks(options) { if (!cancelled) { setError(error) setTree(tree) + options.onComplete?.(file, tree, error) } }) @@ -243,7 +246,7 @@ export function MarkdownHooks(options) { cancelled = true } }, - [options.children, processor] + [options.children, processor, options.onComplete] ) if (error) throw error 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( + + ) + + assert.equal(succes, false) + + plugin.resolve() + + await waitFor(function () { + assert.notEqual(succes, false) + }) + + assert.equal(succes, true) + }) + await t.test('should support plugins that error', async function () { const plugin = deferPlugin() const result = render(