diff --git a/CHANGES.md b/CHANGES.md
index 4f9602069c..a36b69e06f 100644
--- a/CHANGES.md
+++ b/CHANGES.md
@@ -1,3 +1,12 @@
+## Version 10.0.1
+
+Parser Engine Changes:
+
+- (bug) Fix sublanguage with no relevance score (#2506) [Josh Goebel][]
+
+[Josh Goebel]: https://github.com/yyyc514
+
+
## Version 10.0.0
New languages:
diff --git a/src/highlight.js b/src/highlight.js
index 9ce4bd97c3..526b509a30 100644
--- a/src/highlight.js
+++ b/src/highlight.js
@@ -443,6 +443,22 @@ const HLJS = function(hljs) {
}
}
+ // returns a valid highlight result, without actually
+ // doing any actual work, auto highlight starts with
+ // this and it's possible for small snippets that
+ // auto-detection may not find a better match
+ function justTextHighlightResult(code) {
+ const result = {
+ relevance: 0,
+ emitter: new options.__emitter(options),
+ value: escape(code),
+ illegal: false,
+ top: PLAINTEXT_LANGUAGE
+ };
+ result.emitter.addText(code)
+ return result;
+ }
+
/*
Highlighting with language detection. Accepts a string with the code to
highlight. Returns an object with the following properties:
@@ -456,11 +472,7 @@ const HLJS = function(hljs) {
*/
function highlightAuto(code, languageSubset) {
languageSubset = languageSubset || options.languages || Object.keys(languages);
- var result = {
- relevance: 0,
- emitter: new options.__emitter(options),
- value: escape(code)
- };
+ var result = justTextHighlightResult(code)
var second_best = result;
languageSubset.filter(getLanguage).filter(autoDetection).forEach(function(name) {
var current = _highlight(name, code, false);
@@ -589,7 +601,7 @@ const HLJS = function(hljs) {
window.addEventListener('DOMContentLoaded', initHighlighting, false);
}
- var PLAINTEXT_LANGUAGE = { disableAutodetect: true };
+ const PLAINTEXT_LANGUAGE = { disableAutodetect: true, name: 'Plain text' };
function registerLanguage(name, language) {
var lang;
diff --git a/test/markup/xml/sublanguage_no_relevancy.expect.txt b/test/markup/xml/sublanguage_no_relevancy.expect.txt
new file mode 100644
index 0000000000..07a82d554a
--- /dev/null
+++ b/test/markup/xml/sublanguage_no_relevancy.expect.txt
@@ -0,0 +1,3 @@
+<script>foo();</script>
+<script>booger</script>
+<script>hjk</script>
diff --git a/test/markup/xml/sublanguage_no_relevancy.txt b/test/markup/xml/sublanguage_no_relevancy.txt
new file mode 100644
index 0000000000..8bfae43974
--- /dev/null
+++ b/test/markup/xml/sublanguage_no_relevancy.txt
@@ -0,0 +1,3 @@
+
+
+