Skip to content

Commit

Permalink
(chore) Rename second_best to secondBest (highlightAuto)
Browse files Browse the repository at this point in the history
Work towards #2558.
  • Loading branch information
joshgoebel committed Apr 5, 2021
1 parent 6d08ee5 commit 3e891f0
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 20 deletions.
2 changes: 1 addition & 1 deletion docs/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ Returns an object with the following properties:
* ``language``: detected language
* ``relevance``: integer value representing the relevance score
* ``value``: HTML string with highlighting markup
* ``second_best``: object with the same structure for second-best heuristically detected language (may be absent)
* ``secondBest``: object with the same structure for second-best heuristically detected language (may be absent)


fixMarkup
Expand Down
14 changes: 7 additions & 7 deletions src/highlight.js
Original file line number Diff line number Diff line change
Expand Up @@ -619,7 +619,7 @@ const HLJS = function(hljs) {
- language (detected language)
- relevance (int)
- value (an HTML string with highlighting markup)
- second_best (object with the same structure for second-best heuristically
- secondBest (object with the same structure for second-best heuristically
detected language, may be absent)
@param {string} code
Expand Down Expand Up @@ -660,7 +660,7 @@ const HLJS = function(hljs) {

/** @type {AutoHighlightResult} */
const result = best;
result.second_best = secondBest;
result.secondBest = secondBest;

return result;
}
Expand Down Expand Up @@ -761,12 +761,12 @@ const HLJS = function(hljs) {
re: result.relevance,
relavance: result.relevance
};
if (result.second_best) {
element.second_best = {
language: result.second_best.language,
if (result.secondBest) {
element.secondBest = {
language: result.secondBest.language,
// TODO: remove with version 11.0
re: result.second_best.relevance,
relavance: result.second_best.relevance
re: result.secondBest.relevance,
relavance: result.secondBest.relevance
};
}
}
Expand Down
16 changes: 8 additions & 8 deletions tools/checkAutoDetect.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,32 +26,32 @@ function testAutoDetection(language, index, languages) {
.forEach(function(content) {
const expected = language,
actual = hljs.highlightAuto(content);
if (actual.language !== expected && actual.second_best.language !== expected) {
if (actual.language !== expected && actual.secondBest.language !== expected) {
return resultTable.push([
expected,
colors.red(actual.language),
actual.relevance ? actual.relevance : colors.grey('None'),
colors.red(actual.second_best.language),
actual.second_best.relevance ? actual.second_best.relevance : colors.grey('None')
colors.red(actual.secondBest.language),
actual.secondBest.relevance ? actual.secondBest.relevance : colors.grey('None')
]);
}
if (actual.language !== expected) {
return resultTable.push([
expected,
colors.yellow(actual.language),
actual.relevance ? actual.relevance : colors.grey('None'),
colors.yellow(actual.second_best.language),
actual.second_best.relevance ? actual.second_best.relevance : colors.grey('None')
colors.yellow(actual.secondBest.language),
actual.secondBest.relevance ? actual.secondBest.relevance : colors.grey('None')
]);
}
// equal relevance is flagged
if (actual.relevance == actual.second_best.relevance) {
if (actual.relevance == actual.secondBest.relevance) {
return resultTable.push([
expected,
actual.language,
actual.relevance ? colors.yellow(actual.relevance) : colors.grey('None'),
actual.second_best.language,
actual.second_best.relevance ? colors.yellow(actual.second_best.relevance) : colors.grey('None'),
actual.secondBest.language,
actual.secondBest.relevance ? colors.yellow(actual.secondBest.relevance) : colors.grey('None'),
"Relevance match."
]);
}
Expand Down
4 changes: 2 additions & 2 deletions tools/developer.html
Original file line number Diff line number Diff line change
Expand Up @@ -215,8 +215,8 @@ <h3>Markup</h3>
vue.language = hljs.getLanguage(language) ? language : '';

var rendering_stats = result.language + ': relevance ' + (result.relevance );
if (result.second_best) {
rendering_stats += ', ' + result.second_best.language + ': ' + (result.second_best.relevance || result.second_best.r);
if (result.secondBest) {
rendering_stats += ', ' + result.secondBest.language + ': ' + (result.secondBest.relevance || result.secondBest.r);
}
editor.find('.rendering_stats').text(rendering_stats);
editor.find('.rendering_time').text(rendering_time);
Expand Down
4 changes: 2 additions & 2 deletions types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ interface HighlightResult {
sofar? : string
errorRaised? : Error
// * for auto-highlight
second_best? : Omit<HighlightResult, 'second_best'>
secondBest? : Omit<HighlightResult, 'secondBest'>
code?: string
}
interface AutoHighlightResult extends HighlightResult {}
Expand Down Expand Up @@ -143,7 +143,7 @@ interface CallbackResponse {
type AnnotatedError = Error & {mode?: Mode | Language, languageName?: string, badRule?: Mode}

type ModeCallback = (match: RegExpMatchArray, response: CallbackResponse) => void
type HighlightedHTMLElement = HTMLElement & {result?: object, second_best?: object, parentNode: HTMLElement}
type HighlightedHTMLElement = HTMLElement & {result?: object, secondBest?: object, parentNode: HTMLElement}
type EnhancedMatch = RegExpMatchArray & {rule: CompiledMode, type: MatchType}
type MatchType = "begin" | "end" | "illegal"

Expand Down

0 comments on commit 3e891f0

Please sign in to comment.