Skip to content

fix(comark): run default plugin hooks before user plugin hooks - #385

Merged
atinux merged 6 commits into
mainfrom
fix/default-post-hook-order
Aug 26, 2026
Merged

fix(comark): run default plugin hooks before user plugin hooks#385
atinux merged 6 commits into
mainfrom
fix/default-post-hook-order

Conversation

@atinux

@atinux atinux commented Aug 26, 2026

Copy link
Copy Markdown
Contributor

What

Comark now resolves plugins into one canonical order for MarkdownExit registration and pre and post hooks: unchanged defaults first, followed by explicit plugins in user-defined order. An explicit plugin replaces a same-name default at its listed position, and duplicate explicit names keep their first instance; tests and public documentation cover these semantics.

Why

The previous registration and lifecycle orders differed, so a plugin could run in a different position depending on which part of its interface Comark invoked. Using one resolved order makes overrides predictable while ensuring user plugins receive the transformations from defaults they did not replace.

User plugin post hooks previously ran before the default plugins' post
hooks, so tree-consuming plugins saw an un-normalized tree (e.g. GFM
alerts were still plain blockquotes because `alert` had not rewritten
them into `['blockquote', { as }]` yet).

Post hooks now run defaults first, then user plugins. Registration
order is unchanged: user plugins still come first so same-name entries
override defaults via dedupePlugins, and a user override keeps the
default's execution slot. `pre` hooks and `markdownItPlugins` keep
their existing order.
@atinux
atinux requested a review from farnabaz as a code owner August 26, 2026 10:59
@vercel

vercel Bot commented Aug 26, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
comark Ready Ready Preview Aug 26, 2026 3:07pm
comark-json-render Ready Ready Preview Aug 26, 2026 3:07pm
comark-nextjs Ready Ready Preview Aug 26, 2026 3:07pm
comark-nuxt Ready Ready Preview Aug 26, 2026 3:07pm
comark-svelte Ready Ready Preview Aug 26, 2026 3:07pm
comark-sveltekit Ready Ready Preview Aug 26, 2026 3:07pm
comark-twoslash Ready Ready Preview Aug 26, 2026 3:07pm
comark-vue Ready Ready Preview Aug 26, 2026 3:07pm

@pkg-pr-new

pkg-pr-new Bot commented Aug 26, 2026

Copy link
Copy Markdown

Open in StackBlitz

comark

npm i https://pkg.pr.new/comark@385

@comark/angular

npm i https://pkg.pr.new/@comark/angular@385

@comark/ansi

npm i https://pkg.pr.new/@comark/ansi@385

@comark/html

npm i https://pkg.pr.new/@comark/html@385

@comark/nuxt

npm i https://pkg.pr.new/@comark/nuxt@385

@comark/react

npm i https://pkg.pr.new/@comark/react@385

@comark/svelte

npm i https://pkg.pr.new/@comark/svelte@385

@comark/vue

npm i https://pkg.pr.new/@comark/vue@385

commit: d95e871

@github-actions

github-actions Bot commented Aug 26, 2026

Copy link
Copy Markdown
Contributor

✅ Bundle snapshot updated

Committed the new snapshot as 42d1d04, verified by re-running the bundle check against it.

GitHub suppresses the events a workflow commit would normally raise, so the ci check above may
still show the earlier failure. Re-run it to refresh the status — the snapshot itself is confirmed green.

Produced by this run.

Deriving the hoisted names from the registered defaultPlugins array
instead of a hardcoded set removes the duplicated list and makes the
hoisting a natural no-op with registerDefaultPlugins: false, where the
user's explicit registration order rules. Adds a test for that case.
Same rationale as the post-hook ordering: among the defaults only
frontmatter has a pre hook, and running it first gives user pre hooks a
normalized contract — state.markdown without the frontmatter block,
state.frontmatter and state.frontmatterText already populated — instead
of raw text a rewriting plugin could corrupt. One partitioned list now
drives both lifecycle phases; markdownItPlugins keep registration order.
@github-actions

Copy link
Copy Markdown
Contributor

Documentation previews

📚 Preview all documentation changes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants