-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Feature Request: Inline Syntax Highlight #3093
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
Comments
Shiki for Rehype supports the similar, can we have this? |
Not sure why this issue and the associated PR were closed, seeing as it is a very simple addition. In your style.css: .vp-doc span.inline-code-highlight > code {
border-radius: 4px;
padding: 3px 6px;
white-space: normal;
background-color: var(--vp-code-block-bg);
font-size: var(--vp-code-font-size);
}
.vp-doc div[class*="language-"], .vp-doc span.inline-code-highlight > code {
border: 1px solid var(--vp-code-bg);
} In your config.mjs: import { inlineHighlightPlugin } from './inline-highlight.js';
export default defineConfig({
markdown: {
config: md => {
md.use(inlineHighlightPlugin);
}
},
} inline-highlight.js (fixed the HTML string replacement): export const inlineHighlightPlugin = (md) => {
const codeRender = md.renderer.rules.code_inline
md.renderer.rules.code_inline = (...args) => {
const [tokens, idx, options] = args
const token = tokens[idx]
if (token.attrs == null) {
return codeRender(...args)
} else {
const lang = token.attrs[0][0]
if (options.highlight) {
const htmlStr = options.highlight(token.content, lang, '')
return htmlStr.replace(/^<pre class="/, '<span class="inline-code-highlight ').replace(/<\/pre>$/, "</span>")
} else {
return codeRender(...args)
}
}
}
} Then you just do
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Is your feature request related to a problem? Please describe.
Support syntax highlight on inline code in docs.
The picture below is from an HTML code snippet using Prism and a syntax like this:
And the picture below is the same writing with Vitepress:
As you see the Syntax Highlighting is gone. Could be cool to have an automatic inline Syntax Highlighting for md docs.
Here is another example for a CSS code snippet. On the left using markdown and viteperss, and on the right, using html and prism:
Describe the solution you'd like
There'v been some suggestions before on vitepress: #1343 and vuepress: vuejs/vuepress#1212 on how the syntax could look like. I personally do not have a preference. But I believe this syntax:
allows for future expansions:
Describe alternatives you've considered
Have not tried anything yet. Just faced this requirement while trying out vitepress. If I ever came up with a solution that did or did not work will share here.
Additional context
There was already 1 issue about this: #1343, but was closed as "Not seeing any demand for this". So I re-created this issue as a demand.
Validations
The text was updated successfully, but these errors were encountered: