Skip to content

Conversation

@Subham-KRLX
Copy link

Fixes the postprocess transformer hook not being called when using @shikijs/rehype.

The issue occurred because @shikijs/rehype uses codeToHast() which returns a HAST tree, but postprocess transformers expect HTML strings. This PR bridges the gap by:

Detecting when postprocess transformers are present
Converting HAST → HTML using toHtml()
Running all postprocess transformer hooks
Parsing HTML back to HAST using fromHtml()
Linked Issues
Fixes #884

@netlify
Copy link

netlify bot commented Nov 8, 2025

Deploy Preview for shiki-next ready!

Name Link
🔨 Latest commit 6e8dcb6
🔍 Latest deploy log https://app.netlify.com/projects/shiki-next/deploys/6927f65c448cee000828f40a
😎 Deploy Preview https://deploy-preview-1112--shiki-next.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@netlify
Copy link

netlify bot commented Nov 8, 2025

Deploy Preview for shiki-matsu ready!

Name Link
🔨 Latest commit 6e8dcb6
🔍 Latest deploy log https://app.netlify.com/projects/shiki-matsu/deploys/6927f65a1925a700089f5780
😎 Deploy Preview https://deploy-preview-1112--shiki-matsu.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@codecov
Copy link

codecov bot commented Nov 8, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94.91%. Comparing base (5068b26) to head (6e8dcb6).
⚠️ Report is 22 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1112      +/-   ##
==========================================
+ Coverage   88.35%   94.91%   +6.56%     
==========================================
  Files          74       90      +16     
  Lines        3322     7828    +4506     
  Branches      956     1641     +685     
==========================================
+ Hits         2935     7430    +4495     
- Misses        344      392      +48     
+ Partials       43        6      -37     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@antfu
Copy link
Member

antfu commented Nov 9, 2025

Emm, I am not sure if this is the efficient way to do it, it's already be noted that postprocess will only be ran in certain conditions:

/**
* Transform the generated HTML string before returning.
* This hook will only be called with `codeToHtml`.
*/

I think maybe instead, we could update the docs of rehype to mention about it, and tell users to use to-html from from-html within the root hook to swap the entire tree if they really want html string operation

@Subham-KRLX
Copy link
Author

Subham-KRLX commented Nov 9, 2025

I have updated the PR to follow your guidance:

Reverted the postprocess hook execution in rehype

Added inline documentation explaining why postprocess only runs with codeToHtml

Provided example code showing how users can achieve HTML-based postprocessing using a root transformer with toHtml/fromHtml

Removed the postprocess test and unused dependencies

@Subham-KRLX Subham-KRLX requested a review from antfu November 9, 2025 13:42
Copy link
Member

@antfu antfu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we do the docs in the documentation markdown instead? And the PR still contains unrelated changes;

@Subham-KRLX
Copy link
Author

@antfu Both concerns addressed in the latest commit. Documentation moved to docs/packages/rehype.md
and unrelated changes removed.

@Subham-KRLX Subham-KRLX requested a review from antfu November 29, 2025 06:52
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.

@shikijs/rehype: transformers in postprocess hook is not run

2 participants