-
Notifications
You must be signed in to change notification settings - Fork 0
/
highlight-sol.js
29 lines (25 loc) · 981 Bytes
/
highlight-sol.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
const { Marp } = require('@marp-team/marp-core')
const hljs = require('highlight.js')
// highlightjs-solidity for static web page is required a globally exposed `hljs` to
// extend highlight.js.
globalThis.hljs = hljs
// Run the script of `highlightjs-solidity` for static web page.
//
// `highlightjs-solidity` for Node.js is published as ESM only package, but it cannot
// import correctly because it has neither `.mjs` extension or `type: "module"`
// in its `package.json`.
require('highlightjs-solidity/dist/solidity.min.js')
// Create extended Marp class from an original Marp Core.
class MarpWithHighlightJSSolidity extends Marp {
// Overload highlighter to use highlight.js with extended by highlightjs-solidity.
highlighter(code, lang, _attrs) {
if (lang && hljs.getLanguage(lang)) {
return hljs.highlight(code, {
language: lang,
ignoreIllegals: true,
}).value
}
return ''
}
}
module.exports = MarpWithHighlightJSSolidity