Skip to content

Commit 210a91e

Browse files
committed
document the keywords _ident behavior
1 parent d591a73 commit 210a91e

File tree

3 files changed

+8
-6
lines changed

3 files changed

+8
-6
lines changed

docs/language-guide.rst

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,12 +87,14 @@ object, each property of which defines its own group of keywords:
8787
{
8888
keywords: {
8989
keyword: 'else for if while',
90-
literal: ['false','true','null']
90+
literal: ['false','true','null'],
91+
_relevance_only: 'one two three four'
9192
}
9293
}
9394

9495
The group name becomes the class name in the generated markup, enabling different
95-
theming for different kinds of keywords.
96+
theming for different kinds of keywords. Any property starting with a ``_`` will
97+
only use those keywords to increase relevance, they will not be highlighted.
9698

9799
To detect keywords, highlight.js breaks the processed chunk of code into separate
98100
words — a process called lexing. By default, "words" are matched with the regexp

src/highlight.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,8 +172,9 @@ const HLJS = function(hljs) {
172172
buf = "";
173173

174174
relevance += keywordRelevance;
175-
if (kind === "_") {
176-
// _ is magic identifier for relevance only, do not highlight
175+
if (kind.startsWith("_")) {
176+
// _ implied for relevance only, do not highlight
177+
// by applying a class name
177178
buf += match[0];
178179
} else {
179180
const cssClass = language.classNameAliases[kind] || kind;

src/languages/cpp.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -237,8 +237,7 @@ export default function(hljs) {
237237
'atomic_ullong new throw return ' +
238238
'and and_eq bitand bitor compl not not_eq or or_eq xor xor_eq',
239239
built_in: '_Bool _Complex _Imaginary',
240-
// used only for relevance
241-
_: COMMON_CPP_HINTS,
240+
_relevance_hints: COMMON_CPP_HINTS,
242241
literal: 'true false nullptr NULL'
243242
};
244243

0 commit comments

Comments
 (0)