-
-
Notifications
You must be signed in to change notification settings - Fork 133
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 for prism js #194
Comments
We had tried to replace the highlgihter to Prism.js once by an other reason: has less bundle size than highlight.js if we had not bundled unpopular languages. It's popular also in other markdown processors so we think using Prism.js in Marp has a worth. If you have already tried to use custom engine of Marp CLI, you can try to replace the highlighter to Prism.js manually. Override Here is the example to override highlighter. It's for highlight.js plugin but still useful in Prism.js. |
Thank you! And what's the best way to add CSS? |
Include Prism's CSS in Marp's theme CSS. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Agreed, sorry for disturbing. Let this issue be about replacement highlightjs with prism. Thank you for help! |
By discussion in marp-team/marp#103, we are more likely to take better highlighter instead of highlight.js in future. It can provide easy to customize the color scheme by combination with CSS variables. This change may break existing slide style so the new highlighter would be adopted in the future major update of Marp Core. |
Hello @yhatt, I am wondering if you already know https://shiki.matsu.io/. Looks like some static site generators are switching to this at the moment, withastro/astro#1212. Thanks for your work! |
Yes, I know! Shiki is completely ready for server-side highlighting, and already used in other Markdown slide tool Slidev. An only blocker is what markdown-it Markdown processor used by Marp is not compatible with Promise (async/await). This fact actually makes difficult to integrate Shiki highlighter with Marp. https://github.com/markdown-it/markdown-it/blob/master/docs/development.md#i-need-async-rule-how-to-do-it To accept more highlighters, we are planning the next-gen engine of Marpit framework that is supporting asynchronous Markdown parsing. |
Great to see it is on your roadmap :) It looks like the folks from slidev also use markdown-it and wrote a shiki plugin which is using a workaround to handle
Anyway, I am not too into the codebase. Might be that it works for them as they are starting a whole webserver with vite and co.. |
Nice. markdown-it-shiki is already working in Marp, and // engine.js
const { default: markdownItShiki } = require('markdown-it-shiki');
module.exports = ({ marp }) =>
marp.use(markdownItShiki, { theme: 'css-variables' })
This integration looks like promising than old-fashioned Prism. |
Let us discuss continously about new highlighter architecture at #296. Marp Core still keeps highlighter changeable via markdown-it plugins. Prism.js integration would be better to do as Marp/markdown-it plugin (e.g. https://www.npmjs.com/package/markdown-it-prism). |
For what it is worth: I was able to switch to PrismJS by changing the highlighter in the npm i @marp-team/marp-core prismjs // engine.js
const { Marp } = require('@marp-team/marp-core')
const Prism = require('prismjs');
// you may need to load the language you want to use
// see: https://prismjs.com/#supported-languages
const loadLanguages = require('prismjs/components/');
loadLanguages(['jsx', 'tsx']);
function getLanguageConfig(lang) {
if (lang && Prism.languages[lang]) {
return [Prism.languages[lang], lang]
}
return [Prism.languages.plaintext, 'plaintext']
}
module.exports = (opts) => {
const marp = new Marp(opts)
marp.highlighter = (code, lang) => Prism.highlight(code, ...getLanguageConfig(lang))
return marp
} Hooking the CSS up was as easy as copying one of Note: I had a hard time getting |
I'm wondering whether this approach still works in the latest marp-cli (v3.4.0)? I have tried this example but the code block are not getting rendered. |
markdown-it-shiki has been deprecated. Try the official markdown-it plugin https://shiki.style/packages/markdown-it instead. |
Please, add option to replace highlightjs with prism for highlighting.
It adds much more useful and consistent highlighting for kotlin, current state may be found in this repo: https://github.com/asm0dey/kotlin-spark/
Sometimes code blocks are almost not highlighted and sometimes they are being highlighted inconsistently.
Prismjs has lots of plugins and support for lots of languages.
The text was updated successfully, but these errors were encountered: