Comments (2)
Yes because highlighting is sync (required in many integrations), while the loading is async, so it has to be done ahead of time.
If your integration are acceptable for async context, you could do loading yourself
if (!shiki.getLanguages().includes('typescript'))
await shiki.loadLanguage(import('shiki/langs/typescript.mjs'))
const html = shiki.codeToHtml(code, { lang: 'ts' })
from shiki.
Thank you for your response.
I am using this method now and he is working fine.
use(
useMemo(async () => {
async function loadShikiLanguage(language: string, languageModule: any) {
const shiki = codeHighlighter?.codeHighlighter
if (!shiki) return
if (!shiki.getLoadedLanguages().includes(language)) {
await shiki.loadLanguage(await languageModule())
}
}
const { bundledLanguages } = await import('shiki/langs')
if (!language) return
const importFn = (bundledLanguages as any)[language]
if (!importFn) return
return loadShikiLanguage(language || '', importFn)
}, [codeHighlighter?.codeHighlighter, language]),
)
from shiki.
Related Issues (20)
- Doc: `@shikijs/markdown-it` and transformers usage
- Unable to use Color Replacements option in the `Rehype` plugin
- Support for Lit HOT 5
- Decorations API silently fails when `start.line > end.line`
- Code transformers do not work correctly with `rose-pine` theme
- creating a shiki wrapper for nextjs, and rsc HOT 9
- Module not found: Error: Can't resolve 'shiki/wasm' in 'D:\test\node_modules\shiki\dist\chunks' HOT 1
- `@shikijs/transformers` not working with Astro HOT 1
- Make grammar state working with `themes` instead of just `theme` HOT 6
- Cypress test failed with Shiki HOT 1
- Option to exclude themeMatches from explanations HOT 1
- Transformer bug with SQL HOT 4
- common transformers: line markers HOT 1
- Allow overriding/optionalizing background color HOT 2
- Twoslash: `meta` is passed to the popup types codeblock
- `New grammar`: org support HOT 1
- [BUG] @shikijs/monaco bundle size HOT 2
- I need a function that only outputs the class HOT 2
- Next.JS integration docs
- fromHighlighter requires repetitive input of `themes`
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from shiki.