add option to set language with attribute

This commit is contained in:
Jonas Leder 2022-03-25 10:18:57 +01:00
parent 031cccb475
commit 04e198c6d4
No known key found for this signature in database
GPG key ID: CC3C488E27DFF5CA

View file

@ -1,7 +1,14 @@
class InlineCode extends HTMLElement {
constructor() {
super();
this.innerHTML = "<code class=\"language-text\">" + this.innerHTML + "</code>";
const codeElement = document.createElement("code");
if (this.hasAttribute("language")) {
codeElement.classList.add(this.getAttribute("language"));
} else {
codeElement.classList.add("language-text");
}
codeElement.innerHTML = this.innerHTML;
this.appendChild(codeElement);
}
}