ChapelCon2025-Slides/engine.js
Danila Fedorin 985763d19c Configure Marp to syntax highlight Chapel
Signed-off-by: Danila Fedorin <daniel.fedorin@hpe.com>
2025-10-02 17:52:29 -07:00

27 lines
789 B
JavaScript

// https://github.com/orgs/marp-team/discussions/422#discussioncomment-5268779
const { Marp } = require('@marp-team/marp-core')
const hljs = require('highlight.js')
// highlightjs-chapel for static web page is required a globally exposed `hljs` to
// extend highlight.js.
globalThis.hljs = hljs
require('highlightjs-chapel/dist/chapel.min.js')
// Create extended Marp class from an original Marp Core.
class MarpWithHighlightJSChapel extends Marp {
// Overload highlighter to use highlight.js with extended by highlightjs-chapel.
highlighter(code, lang, _attrs) {
if (lang && hljs.getLanguage(lang)) {
return hljs.highlight(code, {
language: lang,
ignoreIllegals: true,
}).value
}
return ''
}
}
module.exports = MarpWithHighlightJSChapel