summaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2024-03-11 12:12:41 +0100
committerGitHub <noreply@github.com>2024-03-11 11:12:41 +0000
commit671b67d43f9b4bbad1076588582823ec92322e3b (patch)
tree8e06ab8dcca283f87ab1c6a31b678e13168a94d6 /crates
parent54f6ee0e5358d1fcb3c9b231ad51b35ff7f2a8bc (diff)
Fix crash with empty raw block (#3619)
Diffstat (limited to 'crates')
-rw-r--r--crates/typst/src/text/raw.rs8
1 files changed, 5 insertions, 3 deletions
diff --git a/crates/typst/src/text/raw.rs b/crates/typst/src/text/raw.rs
index 9e81532f..424adb72 100644
--- a/crates/typst/src/text/raw.rs
+++ b/crates/typst/src/text/raw.rs
@@ -350,14 +350,16 @@ impl Packed<RawElem> {
LinkedNode::new(&root),
synt::Highlighter::new(theme),
&mut |i, _, range, style| {
- // Find start of line.
+ // Find span and start of line.
// Note: Dedent is already applied to the text
+ let span = lines.get(i).map_or_else(Span::detached, |l| l.1);
let span_offset = text[..range.start]
.rfind('\n')
.map_or(0, |i| range.start - (i + 1));
- styled(&text[range], foreground, style, lines[i].1, span_offset)
+ styled(&text[range], foreground, style, span, span_offset)
},
&mut |i, range, line| {
+ let span = lines.get(i).map_or_else(Span::detached, |l| l.1);
seq.push(
Packed::new(RawLine::new(
(i + 1) as i64,
@@ -365,7 +367,7 @@ impl Packed<RawElem> {
EcoString::from(&text[range]),
Content::sequence(line.drain(..)),
))
- .spanned(lines[i].1),
+ .spanned(span),
);
},
)