@@ -443,6 +443,22 @@ const HLJS = function(hljs) {
443443 }
444444 }
445445
446+ // returns a valid highlight result, without actually
447+ // doing any actual work, auto highlight starts with
448+ // this and it's possible for small snippets that
449+ // auto-detection may not find a better match
450+ function justTextHighlightResult ( code ) {
451+ const result = {
452+ relevance : 0 ,
453+ emitter : new options . __emitter ( options ) ,
454+ value : escape ( code ) ,
455+ illegal : false ,
456+ top : PLAINTEXT_LANGUAGE
457+ } ;
458+ result . emitter . addText ( code )
459+ return result ;
460+ }
461+
446462 /*
447463 Highlighting with language detection. Accepts a string with the code to
448464 highlight. Returns an object with the following properties:
@@ -456,11 +472,7 @@ const HLJS = function(hljs) {
456472 */
457473 function highlightAuto ( code , languageSubset ) {
458474 languageSubset = languageSubset || options . languages || Object . keys ( languages ) ;
459- var result = {
460- relevance : 0 ,
461- emitter : new options . __emitter ( options ) ,
462- value : escape ( code )
463- } ;
475+ var result = justTextHighlightResult ( code )
464476 var second_best = result ;
465477 languageSubset . filter ( getLanguage ) . filter ( autoDetection ) . forEach ( function ( name ) {
466478 var current = _highlight ( name , code , false ) ;
@@ -589,7 +601,7 @@ const HLJS = function(hljs) {
589601 window . addEventListener ( 'DOMContentLoaded' , initHighlighting , false ) ;
590602 }
591603
592- var PLAINTEXT_LANGUAGE = { disableAutodetect : true } ;
604+ const PLAINTEXT_LANGUAGE = { disableAutodetect : true , name : 'Plain text' } ;
593605
594606 function registerLanguage ( name , language ) {
595607 var lang ;
0 commit comments