Render description lists in the route-D preview

This commit is contained in:
gloamxun committed 2026-10-20 22:03:19 +08:00
1 parent edf851438b
commit 4772985ffe
3 files changed
+50 -2

No files matched your search

+32
View File
@@ -137,6 +137,38 @@ fn parse_blocks(raw: &str) -> Vec<SourceParagraph> {
return items;
}
}
if let Some(body) = raw
.strip_prefix("\\begin{description}")
.and_then(|text| text.strip_suffix("\\end{description}"))
{
let items: Vec<SourceParagraph> = body
.split("\\item")
.map(str::trim)
.filter(|item| !item.is_empty())
.map(|item| {
let (term, rest) = item
.strip_prefix('[')
.and_then(|text| text.split_once(']'))
.map(|(term, rest)| (term.trim(), rest.trim()))
.unwrap_or(("", item));
let text = if term.is_empty() {
rest.to_string()
} else {
format!("{term} — {rest}")
};
SourceParagraph {
text,
font: ParagraphFont::Roman,
line_height: 12,
math: false,
left_skip: 12,
}
})
.collect();
if !items.is_empty() {
return items;
}
}
vec![parse_paragraph(raw)]
}