Carbon/src/js/events/components.js

20 lines
642 B
JavaScript
Raw Normal View History

2020-10-29 09:42:17 +00:00
const {ElemJS} = require("../basic")
const {lazyLoad} = require("../lazy-load-module")
2020-10-29 09:42:17 +00:00
class HighlightedCode extends ElemJS {
constructor(element) {
super(element)
if (this.element.tagName === "PRE" && this.element.children.length === 1 && this.element.children[0].tagName === "CODE") {
// we shouldn't nest code inside a pre. put the text in the pre directly.
const code = this.element.children[0]
this.clearChildren()
for (const child of code.childNodes) {
this.element.appendChild(child)
}
}
2020-10-31 17:24:05 +00:00
lazyLoad("./static/hljs.js").then(hljs => hljs.highlightBlock(this.element))
2020-10-29 09:42:17 +00:00
}
}
module.exports = {HighlightedCode}