HljsSelectors

Known highlight.js CSS selector keys used throughout the library.

highlight.js wraps each syntax token in a <span class="hljs-*"> element. These class names are mapped to androidx.compose.ui.text.SpanStyle entries by ThemeParser when parsing a theme CSS file, and looked up by HtmlToAnnotatedString when converting the HTML to an androidx.compose.ui.text.AnnotatedString.

The full set of keys available depends on the theme - different CSS themes define different selectors. The constants below cover all official hljs scopes as documented in the CSS Classes Reference.

Base selector

General purpose selectors

These cover the most common token types. Some (OPERATOR, PUNCTUATION, PROPERTY) are newer scopes and may not be present in all themes:

  • KEYWORD - Language keywords (if, for, fun, def, etc.)

  • BUILT_IN - Built-in or library objects (constants, classes, functions)

  • TYPE - Data types (string, int, array, etc.)

  • LITERAL - Special identifiers for built-in values (true, false, null, etc.)

  • NUMBER - Numbers, including units and modifiers

  • OPERATOR - Operators: +, -, >>, |, == (newer scope, not in all themes)

  • PUNCTUATION - Auxiliary punctuation: parentheses, brackets, etc. (newer scope)

  • PROPERTY - Object properties: obj.prop1.prop2.value (newer scope)

  • REGEXP - Literal regular expressions

  • STRING - Literal strings and characters

  • CHAR - Base character scope (primary key emitted by ThemeParser)

  • CHAR_ESCAPE - Character escape literals (official scope: char.escape_)

  • SUBST - Parsed sections inside literal strings. Important: the hljs theme guide explicitly says "don't forget to style .subst" - it should usually reset to the default text color.

  • SYMBOL - Symbolic constants, interned strings, goto labels

  • VARIABLE - General variables

  • VARIABLE_LANGUAGE - Variables with special meaning (this, window, super, self)

  • VARIABLE_CONSTANT - Constant-value variables (e.g. MAX_FILES)

  • TITLE - Name of a class or function

  • PARAMS - Function arguments/parameters at the place of declaration

  • COMMENT - Comments

  • DOCTAG - Documentation markup within comments (e.g. @param)

Title subscopes

highlight.js outputs space-separated classes like class="hljs-title function_" which are resolved as dot-joined keys by ThemeParser:

Meta selectors

  • META - Flags, modifiers, annotations, preprocessor directives

  • META_KEYWORD - Keywords inside a meta block (nested, hyphenated in CSS)

  • META_STRING - Strings inside a meta block (nested, hyphenated in CSS)

  • META_PROMPT - REPL or shell prompts

Tags, attributes, configs

  • TAG - XML/HTML tags

  • NAME - Name of an XML tag, first word in an s-expression

  • ATTR - Attribute names without language semantics (JSON keys, .ini settings)

  • ATTRIBUTE - Attribute names followed by structured values (e.g. CSS properties)

  • SECTION - Section headings in config files or text markup

CSS selectors

Text markup

Templates

Diff

Other

  • ATRULE - At-rule tokens (found in a small number of themes)

Usage

Use these constants when building color maps for HighlightTheme.fromColorMap to avoid typos and get IDE autocomplete with full KDoc descriptions:

val colorMap = mapOf(
HljsSelectors.BASE to SpanStyle(color = Color(0xFF24292E), background = Color(0xFFFFFFFF)),
HljsSelectors.KEYWORD to SpanStyle(color = Color(0xFFD73A49), fontWeight = FontWeight.Bold),
HljsSelectors.STRING to SpanStyle(color = Color(0xFF032F62)),
HljsSelectors.COMMENT to SpanStyle(color = Color(0xFF6A737D), fontStyle = FontStyle.Italic),
)
val theme = HighlightTheme.fromColorMap(name = "my-theme", colorMap = colorMap)

Internally, HighlightTheme and HtmlToAnnotatedString use BASE to derive the default text and background colors. All other selectors are discovered dynamically from the theme CSS at runtime.

See also

Properties

Link copied to clipboard
const val ADDITION: String

Added or changed lines.

Link copied to clipboard
const val ATRULE: String

At-rule tokens. Found in a small number of themes.

Link copied to clipboard
const val ATTR: String

Attribute names without language-defined semantics (JSON keys, .ini settings), also sub-attributes within another highlighted object.

Link copied to clipboard
const val ATTRIBUTE: String

Attribute names followed by structured values (e.g. CSS properties).

Link copied to clipboard
const val BASE: String

The base/root selector ("hljs").

Link copied to clipboard
const val BUILT_IN: String

Built-in or library objects (constants, classes, functions).

Link copied to clipboard
const val BULLET: String

List item bullets.

Link copied to clipboard
const val CHAR: String

Character literals - base scope. ThemeParser emits this as the primary key when parsing .hljs-char.escape_ (via substringBefore('.')), so both CHAR and CHAR_ESCAPE will resolve to the same style from real theme CSS.

Link copied to clipboard
const val CHAR_ESCAPE: String

Character escape literals (e.g. \n, \t). hljs emits class="hljs-char escape_" which resolves to the compound key hljs-char.escape_. All real theme CSS files use .hljs-char.escape_.

Link copied to clipboard
const val CODE: String

Code blocks.

Link copied to clipboard
const val COMMENT: String

Single-line and multi-line comments.

Link copied to clipboard
const val DELETION: String

Deleted lines.

Link copied to clipboard
const val DOCTAG: String

Documentation markup within comments (e.g. @param).

Link copied to clipboard
const val EMPHASIS: String
Link copied to clipboard
const val FORMULA: String

Mathematical formulas.

Link copied to clipboard
const val KEYWORD: String

Keyword tokens (if, for, fun, def, etc.).

Link copied to clipboard
const val LINK: String

Hyperlinks.

Link copied to clipboard
const val LITERAL: String

Special identifiers for built-in values (true, false, null, None).

Link copied to clipboard
const val META: String

Flags, modifiers, annotations, preprocessor directives.

Link copied to clipboard
const val META_KEYWORD: String

Keywords inside a meta block (nested, hyphenated in CSS).

Link copied to clipboard
const val META_PROMPT: String

REPL or shell prompts.

Link copied to clipboard
const val META_STRING: String

Strings inside a meta block (nested, hyphenated in CSS).

Link copied to clipboard
const val NAME: String

Name of an XML tag, the first word in an s-expression.

Link copied to clipboard
const val NUMBER: String

Numbers, including units and modifiers.

Link copied to clipboard
const val OPERATOR: String

Operators: +, -, >>, |, ==. Newer scope - not present in all themes.

Link copied to clipboard
const val PARAMS: String

Function arguments/parameters at the place of declaration.

Link copied to clipboard
const val PROPERTY: String

Object properties: obj.prop1.prop2.value. Newer scope - not present in all themes.

Link copied to clipboard
const val PUNCTUATION: String

Auxiliary punctuation: parentheses, brackets, etc. Newer scope - not present in all themes.

Link copied to clipboard
const val QUOTE: String

Quotations or blockquotes.

Link copied to clipboard
const val REGEXP: String

Literal regular expressions.

Link copied to clipboard
const val SECTION: String

Section headings in config files or text markup.

Link copied to clipboard

[attr] selectors.

Link copied to clipboard

.class selectors.

Link copied to clipboard
const val SELECTOR_ID: String

#id selectors.

Link copied to clipboard

:pseudo selectors.

Link copied to clipboard
const val SELECTOR_TAG: String

Tag selectors (e.g. div, span).

Link copied to clipboard
const val STRING: String

Literal strings and characters.

Link copied to clipboard
const val STRONG: String

Strong emphasis (typically maps to androidx.compose.ui.text.font.FontWeight.Bold).

Link copied to clipboard
const val SUBST: String

Parsed sections inside literal strings. The hljs theme guide explicitly says "don't forget to style .subst" - it should usually reset to the default text color (e.g. .hljs, .hljs-subst { color: black }).

Link copied to clipboard
const val SYMBOL: String

Symbolic constants, interned strings, goto labels.

Link copied to clipboard
const val TAG: String

XML/HTML tags.

Link copied to clipboard
const val TEMPLATE_TAG: String

Tags of template languages.

Link copied to clipboard

Variables in template languages.

Link copied to clipboard
const val TITLE: String

Name of a class or function.

Link copied to clipboard
const val TITLE_CLASS: String

Name of a class, interface, trait, or module.

Link copied to clipboard

Name of a class being inherited from, extended, etc. hljs emits class="hljs-title class_ inherited__" which resolves to the compound key hljs-title.class_.inherited__ (note: double underscore on inherited__).

Link copied to clipboard

Name of a function.

Link copied to clipboard

Name of a function when being invoked.

Link copied to clipboard
const val TYPE: String

Data types (string, int, array, etc.).

Link copied to clipboard
const val VARIABLE: String

General variables (e.g. $variable in shell scripts).

Link copied to clipboard

Constant-value variables (e.g. MAX_FILES).

Link copied to clipboard

Variables with special meaning in a language: this, window, super, self, etc.