diff --git a/docs/language-guide.rst b/docs/language-guide.rst index 7ec0d62053..5e622be1af 100644 --- a/docs/language-guide.rst +++ b/docs/language-guide.rst @@ -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 diff --git a/src/highlight.js b/src/highlight.js index 0278465da1..49d974af18 100644 --- a/src/highlight.js +++ b/src/highlight.js @@ -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; diff --git a/src/languages/cpp.js b/src/languages/cpp.js index 8a1146a6b2..4838a3b3c5 100644 --- a/src/languages/cpp.js +++ b/src/languages/cpp.js @@ -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' };