Gracefully handle highlighter bugs in the markdown component

Since tree-house is young and we've seen a few bugs that make it go
backwards, we should handle this case gracefully and just give up on
syntax highlighting with an error log.
pull/13954/head^2
Michael Davis 2025-07-13 13:10:58 -04:00
parent 86f10ae24c
commit 6fd1efd1c2
No known key found for this signature in database
1 changed files with 7 additions and 1 deletions

View File

@ -90,7 +90,13 @@ pub fn highlighted_code_block<'a>(
if pos == start { if pos == start {
continue; continue;
} }
assert!(pos > start); // The highlighter should always move forward.
// If the highlighter malfunctions, bail on syntax highlighting and log an error.
debug_assert!(pos > start);
if pos < start {
log::error!("Failed to highlight '{language}': {text:?}");
return styled_multiline_text(text, code_style);
}
let style = syntax_highlight_stack let style = syntax_highlight_stack
.iter() .iter()