mirror of
https://github.com/boostorg/website-v2-docs.git
synced 2026-01-19 04:42:17 +00:00
feat: enhance C++ syntax highlighting with attribute support (#562)
This commit is contained in:
@@ -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 {
|
||||
|
||||
21
antora-ui/src/js/vendor/cpp-highlight.js
vendored
21
antora-ui/src/js/vendor/cpp-highlight.js
vendored
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user