File tree Expand file tree Collapse file tree 2 files changed +28
-2
lines changed
Expand file tree Collapse file tree 2 files changed +28
-2
lines changed Original file line number Diff line number Diff line change 33 * This replaces highlight.js's C++ highlighting for consistent styling
44 */
55
6- /* C++ Keywords - blue, bold */
6+ /* C++ Keywords - blue */
77code .cpp-highlight .cpp-keyword ,
88.doc pre .highlight code .cpp-highlight .cpp-keyword {
99 color : # 00f ;
10- font-weight : bold;
1110}
1211
1312/* C++ Strings - dark red */
@@ -29,6 +28,12 @@ code.cpp-highlight .cpp-comment,
2928 font-style : italic;
3029}
3130
31+ /* C++ Attributes - gray */
32+ code .cpp-highlight .cpp-attribute ,
33+ .doc pre .highlight code .cpp-highlight .cpp-attribute {
34+ color : # 9e9e9e ;
35+ }
36+
3237/* Base text in C++ blocks - plain black (identifiers, function names, etc.) */
3338code .cpp-highlight ,
3439.doc pre .highlight code .cpp-highlight {
Original file line number Diff line number Diff line change 66 * - string : String and character literals
77 * - preprocessor: Preprocessor directives (#include, #define, etc.)
88 * - comment : C and C++ style comments
9+ * - attribute : C++ attributes ([[nodiscard]], [[noreturn]], etc.)
910 */
1011
1112const CppHighlight = ( function ( ) {
@@ -59,6 +60,26 @@ const CppHighlight = (function () {
5960 const n = code . length
6061
6162 while ( i < n ) {
63+ // C++ attributes [[...]] with nesting support
64+ if ( code [ i ] === '[' && code [ i + 1 ] === '[' ) {
65+ const start = i
66+ i += 2
67+ let depth = 1
68+ while ( i < n && depth > 0 ) {
69+ if ( code [ i ] === '[' && code [ i + 1 ] === '[' ) {
70+ depth ++
71+ i += 2
72+ } else if ( code [ i ] === ']' && code [ i + 1 ] === ']' ) {
73+ depth --
74+ i += 2
75+ } else {
76+ i ++
77+ }
78+ }
79+ result . push ( span ( 'attribute' , code . slice ( start , i ) ) )
80+ continue
81+ }
82+
6283 // Line comment
6384 if ( code [ i ] === '/' && code [ i + 1 ] === '/' ) {
6485 let end = i + 2
You can’t perform that action at this time.
0 commit comments