From 04e198c6d440589ed881c3046094f21f071b4372 Mon Sep 17 00:00:00 2001 From: Jonas Leder Date: Fri, 25 Mar 2022 10:18:57 +0100 Subject: [PATCH] add option to set language with attribute --- js/customElements/inline-code.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/js/customElements/inline-code.js b/js/customElements/inline-code.js index 1beb51f..940f276 100644 --- a/js/customElements/inline-code.js +++ b/js/customElements/inline-code.js @@ -1,7 +1,14 @@ class InlineCode extends HTMLElement { constructor() { super(); - this.innerHTML = "" + this.innerHTML + ""; + 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); } }