-
Notifications
You must be signed in to change notification settings - Fork 8
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
Support syntax highlight for pm-
tabs
#45
Comments
It seems for custom components they implemented kinda of the same way in nuxt/ui -> https://github.com/nuxt/ui/blob/dev/docs/composables/useShikiHighlighter.ts |
Let's see if we can fix it once for all and all of us! nuxt-modules/mdc#148 nuxt/ui#1361 |
I would also mention they use plugins and also use shiki re-hype etc. I don't if it's good to create ways to implement these within |
Also not mention another layer that antfu was working up could be releated but could be merged in with Kinda all over the place assuming a bunch of deps of shiki :) |
Feel free to open issues in repo or make PRs to help on it :) |
Just for my reference of the current tree:
@nuxt/mdcContains the main code for the parser and rehype. @nuxt/contentNuxt content uses mdc to run the shiki code. @nuxt/uiCreates a |
As I checked the repo, I'm suggesting not to run shiki separately. We can achieve with a simple remark plugin to convert // mdc.config.ts
import { defineConfig } from '@nuxtjs/mdc/config'
import { visit } from 'unist-util-visit'
export const packageManagers = [
{ name: 'npm', command: 'npm', install: 'i', run: 'run ', x: 'npx' },
{ name: 'yarn', command: 'yarn', install: 'add', run: '', x: 'yarn dlx' },
{ name: 'pnpm', command: 'pnpm', install: 'i', run: '', x: 'pnpx' },
{ name: 'bun', command: 'bun', install: 'i', run: 'run ', x: 'bunx' },
] as const
export default defineConfig({
unified: {
pre: (stream) => {
stream.use(() => {
return (tree) => visit(tree, (node) => node.name === 'pm-x', (node) => {
node.name = 'code-group'
node.children = packageManagers.map((pm) => {
return {
type: 'code',
lang: 'bash',
meta: `[${pm.command}]`,
value: `${pm.x} ${node.attributes.command}`,
}
})
})
})
return stream
}
}
}) This mean that As for UI Docs, The use case is totally different, in UI Docs we needed to highlight dynamic code in runtime, based on user inputs. Shiki should run in client side. But here we need to highlight codes only at built time. |
Thanks but i prefer a real simple way to a real simple problem not making it more complex this way! Code group does not allows rendering single markdown renderer not even additional comment blocks inside it work (a limitation with UI pro) and MDC does not exposes shiki utils (that’s why made nuxt-shiki module to be able to reuse) |
I don't suggest using As for shiki utils, we can improve mdc module to simplify usage. |
(it seems mission impossible today to fix this in a proper way, i give up) |
Example usage: https://github.com/unjs/undocs/blob/main/layers/core/app/components/global/Pm-x.vue
Relavant PR #41
/cc @farnabaz @benjamincanac if you have any ideas how to properly use UI+MDC to highlight with programmatic tabs that would be really appreciated if can help 🙏🏼
The text was updated successfully, but these errors were encountered: