Skip to content

Commit 33af3e5

Browse files
committed
Add autodetection throughout editing if no lang - #7
1 parent bb91ee8 commit 33af3e5

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

code-input.js

+14-2
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ var codeInput = {
2626
}
2727
// Update code
2828
result_element.innerHTML = this.escape_html(text);
29+
if(this.autodetect) { // Autodetection
30+
result_element.className = ""; // CODE
31+
result_element.parentElement.className = ""; // PRE
32+
}
2933
// Syntax Highlight
3034
if(this.template.includeCodeInputInHighlightFunc) this.template.highlight(result_element, this);
3135
else this.template.highlight(result_element);
@@ -140,8 +144,13 @@ var codeInput = {
140144
pre.append(code);
141145
this.append(pre);
142146

143-
if(this.template.isCode && lang != undefined) code.classList.add("language-" + lang);
144-
147+
if(this.template.isCode) {
148+
if(lang != undefined && lang != "") {
149+
code.classList.add("language-" + lang);
150+
}
151+
else this.autodetect = true // No lang attribute
152+
}
153+
145154
/* Add code from value attribute - useful for loading from backend */
146155
this.update(value, this);
147156
}
@@ -189,6 +198,9 @@ var codeInput = {
189198
if(newValue != undefined && newValue != "") {
190199
code.classList.add("language-" + newValue);
191200
console.log("ADD", "language-" + newValue);
201+
} else {
202+
// Autodetect - works with HLJS
203+
this.autodetect = true;
192204
}
193205

194206
if(textarea.placeholder == oldValue) textarea.placeholder = newValue;

0 commit comments

Comments
 (0)