Continue highlights across code block lines.
This commit is contained in:
parent
75a763569b
commit
41927764fc
4
TODO.org
4
TODO.org
@ -1,4 +1,4 @@
|
|||||||
* Things to do [3/14]
|
* Things to do [4/14]
|
||||||
** DONE If the paragraph only contains an image, text-align center
|
** DONE If the paragraph only contains an image, text-align center
|
||||||
** DONE Syntax highlighting for code blocks
|
** DONE Syntax highlighting for code blocks
|
||||||
** TODO Render gnuplot
|
** TODO Render gnuplot
|
||||||
@ -14,4 +14,4 @@
|
|||||||
** TODO Add highlighting for languages [0/2]
|
** TODO Add highlighting for languages [0/2]
|
||||||
*** TODO bash
|
*** TODO bash
|
||||||
*** TODO gnuplot
|
*** TODO gnuplot
|
||||||
** TODO Bug: carry over highlight starts when breaking lines
|
** DONE Bug: carry over highlight starts when breaking lines
|
||||||
|
@ -169,6 +169,7 @@ where
|
|||||||
|
|
||||||
let mut highlighted_text: Vec<ISrcLine> = Vec::with_capacity(lines.len());
|
let mut highlighted_text: Vec<ISrcLine> = Vec::with_capacity(lines.len());
|
||||||
let mut current_line = ISrcLine::new();
|
let mut current_line = ISrcLine::new();
|
||||||
|
let mut highlight_stack: Vec<&str> = Vec::new();
|
||||||
for event in highlights {
|
for event in highlights {
|
||||||
match event.unwrap() {
|
match event.unwrap() {
|
||||||
HighlightEvent::Source { start, end } => {
|
HighlightEvent::Source { start, end } => {
|
||||||
@ -178,8 +179,22 @@ where
|
|||||||
current_line
|
current_line
|
||||||
.children
|
.children
|
||||||
.push(ISrcSegment::RawText(first_line.to_owned()));
|
.push(ISrcSegment::RawText(first_line.to_owned()));
|
||||||
|
current_line.children.extend(
|
||||||
|
highlight_stack
|
||||||
|
.iter()
|
||||||
|
.map(|_name| ISrcSegment::HighlightEnd),
|
||||||
|
);
|
||||||
highlighted_text.push(current_line);
|
highlighted_text.push(current_line);
|
||||||
current_line = ISrcLine::new();
|
current_line = ISrcLine::new();
|
||||||
|
current_line
|
||||||
|
.children
|
||||||
|
.extend(
|
||||||
|
highlight_stack
|
||||||
|
.iter()
|
||||||
|
.map(|name| ISrcSegment::HighlightStart {
|
||||||
|
name: (*name).into(),
|
||||||
|
}),
|
||||||
|
);
|
||||||
span = &span[(line_break_index + 1)..];
|
span = &span[(line_break_index + 1)..];
|
||||||
}
|
}
|
||||||
if !span.is_empty() {
|
if !span.is_empty() {
|
||||||
@ -189,16 +204,20 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
HighlightEvent::HighlightStart(s) => {
|
HighlightEvent::HighlightStart(s) => {
|
||||||
|
highlight_stack.push(highlight_names[s.0]);
|
||||||
current_line.children.push(ISrcSegment::HighlightStart {
|
current_line.children.push(ISrcSegment::HighlightStart {
|
||||||
name: highlight_names[s.0].into(),
|
name: highlight_names[s.0].into(),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
HighlightEvent::HighlightEnd => {
|
HighlightEvent::HighlightEnd => {
|
||||||
|
highlight_stack.pop();
|
||||||
current_line.children.push(ISrcSegment::HighlightEnd);
|
current_line.children.push(ISrcSegment::HighlightEnd);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
debug_assert!(highlight_stack.is_empty());
|
||||||
|
|
||||||
Ok(highlighted_text)
|
Ok(highlighted_text)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user