From b3a6fcdfe29a485dd04ea604e148951ee1221e8a Mon Sep 17 00:00:00 2001 From: "Julio C. Estrada" Date: Mon, 15 Dec 2025 15:33:57 -0500 Subject: [PATCH] feat: enhance C++ syntax highlighting with attribute support (#562) --- antora-ui/src/css/cpp-highlight.css | 9 +++++++-- antora-ui/src/js/vendor/cpp-highlight.js | 21 +++++++++++++++++++++ 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/antora-ui/src/css/cpp-highlight.css b/antora-ui/src/css/cpp-highlight.css index f23f16e..e70a34c 100644 --- a/antora-ui/src/css/cpp-highlight.css +++ b/antora-ui/src/css/cpp-highlight.css @@ -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 */ @@ -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 { diff --git a/antora-ui/src/js/vendor/cpp-highlight.js b/antora-ui/src/js/vendor/cpp-highlight.js index 930a361..7f7756b 100644 --- a/antora-ui/src/js/vendor/cpp-highlight.js +++ b/antora-ui/src/js/vendor/cpp-highlight.js @@ -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 () { @@ -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