Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
24 changes: 18 additions & 6 deletions src/highlight.js
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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);
Expand Down Expand Up @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions test/markup/xml/sublanguage_no_relevancy.expect.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<span class="hljs-tag">&lt;<span class="hljs-name">script</span>&gt;</span>foo();<span class="hljs-tag">&lt;/<span class="hljs-name">script</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">script</span>&gt;</span>booger<span class="hljs-tag">&lt;/<span class="hljs-name">script</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">script</span>&gt;</span>hjk<span class="hljs-tag">&lt;/<span class="hljs-name">script</span>&gt;</span>
3 changes: 3 additions & 0 deletions test/markup/xml/sublanguage_no_relevancy.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<script>foo();</script>
<script>booger</script>
<script>hjk</script>