Continue highlights across code block lines.
This commit is contained in:
@@ -169,6 +169,7 @@ where
|
||||
|
||||
let mut highlighted_text: Vec<ISrcLine> = Vec::with_capacity(lines.len());
|
||||
let mut current_line = ISrcLine::new();
|
||||
let mut highlight_stack: Vec<&str> = Vec::new();
|
||||
for event in highlights {
|
||||
match event.unwrap() {
|
||||
HighlightEvent::Source { start, end } => {
|
||||
@@ -178,8 +179,22 @@ where
|
||||
current_line
|
||||
.children
|
||||
.push(ISrcSegment::RawText(first_line.to_owned()));
|
||||
current_line.children.extend(
|
||||
highlight_stack
|
||||
.iter()
|
||||
.map(|_name| ISrcSegment::HighlightEnd),
|
||||
);
|
||||
highlighted_text.push(current_line);
|
||||
current_line = ISrcLine::new();
|
||||
current_line
|
||||
.children
|
||||
.extend(
|
||||
highlight_stack
|
||||
.iter()
|
||||
.map(|name| ISrcSegment::HighlightStart {
|
||||
name: (*name).into(),
|
||||
}),
|
||||
);
|
||||
span = &span[(line_break_index + 1)..];
|
||||
}
|
||||
if !span.is_empty() {
|
||||
@@ -189,16 +204,20 @@ where
|
||||
}
|
||||
}
|
||||
HighlightEvent::HighlightStart(s) => {
|
||||
highlight_stack.push(highlight_names[s.0]);
|
||||
current_line.children.push(ISrcSegment::HighlightStart {
|
||||
name: highlight_names[s.0].into(),
|
||||
});
|
||||
}
|
||||
HighlightEvent::HighlightEnd => {
|
||||
highlight_stack.pop();
|
||||
current_line.children.push(ISrcSegment::HighlightEnd);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
debug_assert!(highlight_stack.is_empty());
|
||||
|
||||
Ok(highlighted_text)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user