@@ -130,11 +130,25 @@ void apply_syntax_highlighting(std::string& str) noexcept {
130
130
usize pos;
131
131
auto view = std::string_view (str);
132
132
while (true ) {
133
+ // Find the <pre> tags.
133
134
pos = view.find (" <pre>" , pos);
134
135
if (pos == std::string::npos) break ;
135
- usize end_pos = view.find (" </pre>" , pos + 5u );
136
+ pos += 5u ;
137
+ usize end_pos = view.find (" </pre>" , pos);
136
138
if (end_pos == std::string::npos) break ;
137
139
140
+ // Inside <pre>, find the <code> tags and move inside them.
141
+ pos = [&](usize pos) {
142
+ usize plain = view.find (" <code>" , pos);
143
+ if (plain != std::string::npos) plain += strlen (" <code>" );
144
+ usize with_lang = view.find (" <code class=\" language-cpp\" >" , pos);
145
+ if (with_lang != std::string::npos)
146
+ with_lang += strlen (" <code class=\" language-cpp\" >" );
147
+ return sus::cmp::min (plain, with_lang);
148
+ }(pos);
149
+ if (pos == std::string::npos) break ;
150
+ end_pos = sus::cmp::min (end_pos, usize::from (view.find (" </code>" , pos)));
151
+
138
152
bool in_comment = false ;
139
153
bool in_string = false ;
140
154
bool in_char = false ;
@@ -205,7 +219,7 @@ void apply_syntax_highlighting(std::string& str) noexcept {
205
219
continue ;
206
220
}
207
221
208
- // There's a <pre > tag at the start so we can always look backward one
222
+ // There's a <code > tag at the start so we can always look backward one
209
223
// char.
210
224
sus::check (pos > 0u );
211
225
char before = view[pos - 1u ];
0 commit comments