Skip to content

Commit

Permalink
document the keywords _ident behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
joshgoebel committed Mar 5, 2021
1 parent d591a73 commit 210a91e
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
6 changes: 4 additions & 2 deletions docs/language-guide.rst
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,14 @@ object, each property of which defines its own group of keywords:
{
keywords: {
keyword: 'else for if while',
literal: ['false','true','null']
literal: ['false','true','null'],
_relevance_only: 'one two three four'
}
}

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

To detect keywords, highlight.js breaks the processed chunk of code into separate
words — a process called lexing. By default, "words" are matched with the regexp
Expand Down
5 changes: 3 additions & 2 deletions src/highlight.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,9 @@ const HLJS = function(hljs) {
buf = "";

relevance += keywordRelevance;
if (kind === "_") {
// _ is magic identifier for relevance only, do not highlight
if (kind.startsWith("_")) {
// _ implied for relevance only, do not highlight
// by applying a class name
buf += match[0];
} else {
const cssClass = language.classNameAliases[kind] || kind;
Expand Down
3 changes: 1 addition & 2 deletions src/languages/cpp.js
Original file line number Diff line number Diff line change
Expand Up @@ -237,8 +237,7 @@ export default function(hljs) {
'atomic_ullong new throw return ' +
'and and_eq bitand bitor compl not not_eq or or_eq xor xor_eq',
built_in: '_Bool _Complex _Imaginary',
// used only for relevance
_: COMMON_CPP_HINTS,
_relevance_hints: COMMON_CPP_HINTS,
literal: 'true false nullptr NULL'
};

Expand Down

0 comments on commit 210a91e

Please sign in to comment.