-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Allow endusers to modify the shiki configuration #1067
Comments
You can directly pass your highlighter function. |
Took a while to figure this one out - had to add |
Yeah, it's not documented yet. Also, I don't think it'll work with shiki. Shiki's APIs are async, and we are just asking for options.highlight. So unless one can do top-level await in vitepress config file, how will they get the highligher instance?! 👀 How did you do it? |
I defined the following: export async function highlighter() {
const highlighter = await getHighlighter({
theme: 'material-palenight'
})
// Inject another grammar
highlighter.loadLanguage(lc3)
const preRE = /^<pre.*?>/
const vueRE = /-vue$/
return (str: string, lang: string) => {
const vPre = vueRE.test(lang) ? '' : 'v-pre'
lang = lang.replace(vueRE, '')
return highlighter
.codeToHtml(str, { lang, theme: 'material-palenight' })
.replace(preRE, `<pre ${vPre}>`)
}
} I figured out that vitepress loads the configuration by awaiting the config; which allows you to do things such as export default async () => defineConfig({
...
markdown: {
highlight: await highlighter()
},
...
}) From there, I had access to an async context and could do anything. |
Ah, we actually use Vite's |
Is your feature request related to a problem? Please describe.
I've been writing a small website on the side, and am looking to add custom languages (e.g. LC-3) to shiki for the articles.
I've noticed there's no way to configure this within
.vitepress/config.ts
, and I do not want to resort to modifying theshiki
package to do this.Describe the solution you'd like
As described on https://shiki.matsu.io/, custom languages can be loaded during the
getHighlighter
call:Another method is to use
highlighter.loadLanguage(lang)
afterwards.It would be great if we could specify arguments to
shiki.getHighlighter
in.vitepress/config.{js,ts}
as we can withmarkdown-it
,vue
, etc.Describe alternatives you've considered
No response
Additional context
No response
Validations
The text was updated successfully, but these errors were encountered: