@@ -26,6 +26,10 @@ var codeInput = {
26
26
}
27
27
// Update code
28
28
result_element . innerHTML = this . escape_html ( text ) ;
29
+ if ( this . autodetect ) { // Autodetection
30
+ result_element . className = "" ; // CODE
31
+ result_element . parentElement . className = "" ; // PRE
32
+ }
29
33
// Syntax Highlight
30
34
if ( this . template . includeCodeInputInHighlightFunc ) this . template . highlight ( result_element , this ) ;
31
35
else this . template . highlight ( result_element ) ;
@@ -140,8 +144,13 @@ var codeInput = {
140
144
pre . append ( code ) ;
141
145
this . append ( pre ) ;
142
146
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
+
145
154
/* Add code from value attribute - useful for loading from backend */
146
155
this . update ( value , this ) ;
147
156
}
@@ -189,6 +198,9 @@ var codeInput = {
189
198
if ( newValue != undefined && newValue != "" ) {
190
199
code . classList . add ( "language-" + newValue ) ;
191
200
console . log ( "ADD" , "language-" + newValue ) ;
201
+ } else {
202
+ // Autodetect - works with HLJS
203
+ this . autodetect = true ;
192
204
}
193
205
194
206
if ( textarea . placeholder == oldValue ) textarea . placeholder = newValue ;
0 commit comments