Skip to content

How can I add a custom language for syntax highlighting in code blocks? #422

Answered by yhatt
codethief asked this question in Q&A
Discussion options

You must be logged in to vote

It's often misunderstood thing: Marp's syntax highlighting with highlight.js is not processed on the browser side, but on Node.js. Trying to extend with a <script> tag (for the browser) is meaningless.

To extend Marp syntax highlighter, you should use Marp CLI with the customized engine.

Unfortunately, highlightjs-zig package does not ready to use in Node.js due to incomatible format for importing pure ESM script. Thus, you have to make some tricks:

// engine.js
const { Marp } = require('@marp-team/marp-core')
const hljs = require('highlight.js')

// highlightjs-zig for static web page is required a globally exposed `hljs` to
// extend highlight.js.
globalThis.hljs = hljs

// Run the scri…

Replies: 3 comments 4 replies

Comment options

You must be logged in to vote
0 replies
Answer selected by codethief
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
4 replies
@yhatt
Comment options

yhatt Jul 9, 2023
Maintainer

@j2deme
Comment options

@yhatt
Comment options

yhatt Jul 9, 2023
Maintainer

@j2deme
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants