Carbon/src/js/events/components.js

20 lines
642 B
JavaScript

const {ElemJS} = require("../basic")
const {lazyLoad} = require("../lazy-load-module")
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)
}
}
lazyLoad("./static/hljs.js").then(hljs => hljs.highlightBlock(this.element))
}
}
module.exports = {HighlightedCode}