Render enumerate lists in the route-D preview

This commit is contained in:
gloamxun committed 2026-10-20 22:01:02 +08:00
1 parent cea9ccddef
commit edf851438b
4 files changed
+44 -13

No files matched your search

+24 -10
View File
@@ -103,20 +103,34 @@ fn command_body<'a>(text: &'a str, command: &str) -> Option<&'a str> {
}
fn parse_blocks(raw: &str) -> Vec<SourceParagraph> {
if let Some(body) = raw
.strip_prefix("\\begin{itemize}")
.and_then(|text| text.strip_suffix("\\end{itemize}"))
{
for (environment, numbered) in [("itemize", false), ("enumerate", true)] {
let begin = format!("\\begin{{{environment}}}");
let finish = format!("\\end{{{environment}}}");
let Some(body) = raw
.strip_prefix(&begin)
.and_then(|text| text.strip_suffix(&finish))
else {
continue;
};
let mut number = 0;
let items: Vec<SourceParagraph> = body
.split("\\item")
.map(str::trim)
.filter(|item| !item.is_empty())
.map(|item| SourceParagraph {
text: format!("• {item}"),
font: ParagraphFont::Roman,
line_height: 12,
math: false,
left_skip: 12,
.map(|item| {
number += 1;
let prefix = if numbered {
format!("{number}. ")
} else {
"• ".to_string()
};
SourceParagraph {
text: format!("{prefix}{item}"),
font: ParagraphFont::Roman,
line_height: 12,
math: false,
left_skip: 12,
}
})
.collect();
if !items.is_empty() {