27 lines
789 B
JavaScript
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
|