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 b0c9ae7
🔍 Latest deploy log https://app.netlify.com/projects/shiki-next/deploys/69117211cb7b910008b5ab19
😎 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 b0c9ae7
🔍 Latest deploy log https://app.netlify.com/projects/shiki-matsu/deploys/691172116ddcd60008231e1c
😎 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 88.35%. Comparing base (5068b26) to head (b0c9ae7).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1112   +/-   ##
=======================================
  Coverage   88.35%   88.35%           
=======================================
  Files          74       74           
  Lines        3322     3322           
  Branches      956      954    -2     
=======================================
  Hits         2935     2935           
  Misses        344      344           
  Partials       43       43           

☔ 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
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