Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions antora-ui/src/css/cpp-highlight.css
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@
* This replaces highlight.js's C++ highlighting for consistent styling
*/

/* C++ Keywords - blue, bold */
/* C++ Keywords - blue */
code.cpp-highlight .cpp-keyword,
.doc pre.highlight code.cpp-highlight .cpp-keyword {
color: #00f;
font-weight: bold;
}

/* C++ Strings - dark red */
Expand All @@ -29,6 +28,12 @@ code.cpp-highlight .cpp-comment,
font-style: italic;
}

/* C++ Attributes - gray */
code.cpp-highlight .cpp-attribute,
.doc pre.highlight code.cpp-highlight .cpp-attribute {
color: #9e9e9e;
}

/* Base text in C++ blocks - plain black (identifiers, function names, etc.) */
code.cpp-highlight,
.doc pre.highlight code.cpp-highlight {
Expand Down
21 changes: 21 additions & 0 deletions antora-ui/src/js/vendor/cpp-highlight.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* - string : String and character literals
* - preprocessor: Preprocessor directives (#include, #define, etc.)
* - comment : C and C++ style comments
* - attribute : C++ attributes ([[nodiscard]], [[noreturn]], etc.)
*/

const CppHighlight = (function () {
Expand Down Expand Up @@ -59,6 +60,26 @@ const CppHighlight = (function () {
const n = code.length

while (i < n) {
// C++ attributes [[...]] with nesting support
if (code[i] === '[' && code[i + 1] === '[') {
const start = i
i += 2
let depth = 1
while (i < n && depth > 0) {
if (code[i] === '[' && code[i + 1] === '[') {
depth++
i += 2
} else if (code[i] === ']' && code[i + 1] === ']') {
depth--
i += 2
} else {
i++
}
}
result.push(span('attribute', code.slice(start, i)))
continue
}

// Line comment
if (code[i] === '/' && code[i + 1] === '/') {
let end = i + 2
Expand Down
Loading