Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(rehype): support lazy load languages #787

Merged
merged 8 commits into from
Sep 26, 2024

Conversation

fuma-nama
Copy link
Contributor

@fuma-nama fuma-nama commented Sep 21, 2024

Description

Support loading languages on demand with Rehype Shiki lazy option.
When disabled (default), the plugin is compatible with sync usage.

With lazy enabled, it loads the language when needed using async highlighter.loadLanguage

Linked Issues

fix #786

Additional context

I noticed the amount of duplicated code increase as I try to support sync usage, so I made a "handler" layer.

the handler extracts information from HAST node and tells highlighter how to highlight the node, the logic for highlighting the code is kept in the original core.ts.

Copy link

netlify bot commented Sep 21, 2024

Deploy Preview for shiki-next ready!

Name Link
🔨 Latest commit 9e67382
🔍 Latest deploy log https://app.netlify.com/sites/shiki-next/deploys/66f5de395d9c6200086d86b6
😎 Deploy Preview https://deploy-preview-787--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 site configuration.

Copy link

netlify bot commented Sep 21, 2024

Deploy Preview for shiki-matsu ready!

Name Link
🔨 Latest commit 9e67382
🔍 Latest deploy log https://app.netlify.com/sites/shiki-matsu/deploys/66f5de39a4ed0c00083da0c6
😎 Deploy Preview https://deploy-preview-787--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 site configuration.

packages/rehype/src/core.ts Outdated Show resolved Hide resolved
@fuma-nama fuma-nama requested a review from antfu September 26, 2024 02:17
@fuma-nama fuma-nama requested a review from antfu September 26, 2024 06:01
@antfu antfu merged commit c449dd1 into shikijs:main Sep 26, 2024
6 checks passed
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.

Lazy load languages on Rehype Shiki
2 participants