-
Notifications
You must be signed in to change notification settings - Fork 108
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
Code block treatment breaks compatibility with some rehype plugins? #139
Comments
Yeah, this is the cause of #100 as well. Will be fixed in a future version. Highlighting will also be done by Shiki in a future version now that shikijs/shiki#49 is in. |
I actually ended up finding this https://github.com/SaraVieira/prism-theme-converter which lets you use VSCode themes with prism. Why the switch to Shiki? More language support than prism with that issue you linked to? |
Yeah, you can apply any textmate grammar at all which is better than Prism's non-standard grammar (even though they have some similarities) as you don't need to write a new grammar when you're doing something funky. The other reason is more selfish, the way Prism is built makes it incredibly difficult to work with in various contexts. It is really quite frustrating and makes a mess of my code due to the UMD format that it publishes. |
Makes sense. Thanks for the explanation. |
The See the parent post in #205 for an example of what this might look like. |
I am trying to use https://github.com/shikijs/twoslash which provides syntax highlighting and enriches the JS and TS code with static types (see https://shikijs.github.io/twoslash/ for demo, its really nice). It doesn't work because of some escaping issue I think. Here is the raw markdown:
I get an error coming from twoslash and it shows the code that it received:
We got around this in #212 by providing a custom highlight function and using I created a barebones svelte kit project with this issue happening here: https://github.com/michael0liver/mdsvex-remark-codeblock-issue |
Okay I got around it again by using the custom highlight function 😄 // svelte.config.js
import preprocess from "svelte-preprocess";
import { mdsvex } from "mdsvex";
import {
createShikiHighlighter,
runTwoSlash,
renderCodeToHTML,
} from "shiki-twoslash";
import { readFileSync } from "fs";
// From https://github.com/whizkydee/vscode-palenight-theme/blob/master/themes/palenight.json
const palenightTheme = JSON.parse(readFileSync("./palenight-theme.json"));
const mdsvexPreprocess = mdsvex({
extensions: [".svx", ".md"],
highlight: {
highlighter: async (code, lang, meta) => {
const highlighter = await createShikiHighlighter({
theme: palenightTheme,
});
let twoslashResults = null;
if (meta && meta.includes("twoslash")) {
twoslashResults = runTwoSlash(code, lang, {});
}
const html = renderCodeToHTML(
code,
lang,
meta || [],
{},
highlighter,
twoslashResults
);
return `{@html \`${html}\` }`;
},
},
});
/** @type {import('@sveltejs/kit').Config} */
const config = {
preprocess: [mdsvexPreprocess, preprocess()],
extensions: [".svelte", ".svx"],
kit: {
target: "#svelte",
},
};
export default config; |
I think this is the same as : #304 and more specifically this: #93 (comment) |
Was trying to get https://github.com/rsclarke/rehype-shiki to work. It lets you syntax highlight with any VSCode theme. It wasn't working, so I dug into it: it just walks the tree lookiing for
pre
tags wrapping acode
tag.But, it seems MDsvex is doing something special with
@html
that breaks this https://github.com/pngwn/MDsveX/blob/master/packages/mdsvex/test/it/code_highlighting.test.ts#L64I'm just going to use the built-in syntax highlighting for now, but just making a note of this with this issue
The text was updated successfully, but these errors were encountered: