Configure Marp to syntax highlight Chapel

Signed-off-by: Danila Fedorin <daniel.fedorin@hpe.com>
This commit is contained in:
Danila Fedorin 2025-10-02 17:52:29 -07:00
parent 59fea61d2d
commit 985763d19c
3 changed files with 1929 additions and 0 deletions

26
engine.js Normal file
View File

@ -0,0 +1,26 @@
// 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

1897
package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

6
package.json Normal file
View File

@ -0,0 +1,6 @@
{
"devDependencies": {
"@marp-team/marp-cli": "^4.2.3",
"highlightjs-chapel": "^0.1.0"
}
}