From edf851438bf2ec7473f36f630538a37bf9daecd7 Mon Sep 17 00:00:00 2001 From: GloamXun Date: Tue, 20 Oct 2026 22:01:02 +0800 Subject: [PATCH] Render enumerate lists in the route-D preview --- README.md | 2 +- docs/TEX_CORE.md | 4 ++-- src/route_d.rs | 34 ++++++++++++++++++++++++---------- tests/server.rs | 17 +++++++++++++++++ 4 files changed, 44 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index dc45878..dc6bd0d 100644 --- a/README.md +++ b/README.md @@ -564,7 +564,7 @@ paragraph builder, CMR10 metrics extracted from `cmr10.tfm`, and a matching pdfT default until the new core reaches layout parity. See `docs/TEX_CORE.md`. The first M7 service integration is available as `POST /api/route-d/preview`, with PDF export at `POST /api/route-d/pdf`. -It accepts blank-line-separated source with a small `\section`/`\textbf`/`\emph`/display-math/itemize subset, lays it out with the route-D page +It accepts blank-line-separated source with a small `\section`/`\textbf`/`\emph`/display-math/list subset, lays it out with the route-D page builder, and returns the v1-compatible preview shape plus per-page hashes and SVG. The v1 `/preview` and project APIs are unchanged and remain the default. diff --git a/docs/TEX_CORE.md b/docs/TEX_CORE.md index e497b6b..708c388 100755 --- a/docs/TEX_CORE.md +++ b/docs/TEX_CORE.md @@ -232,7 +232,7 @@ for a later overlaid slash. | M4 math | partial | atoms, scripts, fractions, roots, delimiters, accents, operators, classes, braces, boxed, negated; no math painter/shrink wrapping | | M5 NFSS/TFM | partial | runtime `cmr10.tfm` widths/heights/depths/kern pairs and ff/fi/fl/ffi/ffl ligatures; all five text faces embed Liberation Serif/Mono as Type0 CID fonts with Identity-H, ToUnicode and `/W` glyph widths; no Base-14 dependency; SVG carries family/weight/style | | M6 specials/XObject | partial | raw specials, RGB image XObjects, URI link annotations; class/package execution absent | -| M7 incremental integration | partial | route-D preview/PDF/edit endpoints with content-based page hashes and basic section/emphasis/display-math/itemize mapping; editor integration pending | +| M7 incremental integration | partial | route-D preview/PDF/edit endpoints with content-based page hashes and basic section/emphasis/display-math/itemize/enumerate mapping; editor integration pending | v1 remains the production renderer; the route-D core is additive and tested independently. @@ -262,7 +262,7 @@ M3 (partial): `Unit::halign` normalizes column widths, intercolumn gaps, row hei Math coverage includes fractions/roots, scripts, `\left...\right` with body-scaled delimiters, `\middle`, `\big`/`\Big`/`\bigg`/`\Bigg` and their `l`/`r` forms, control-sequence delimiters, accents (dot/check/breve/acute/grave/ring), `\text`/`\mathrm`, `\overbrace`/`\underbrace`, `\overset`/`\underset`, `\binom`, `\cancel`/`\bcancel`/`\xcancel`, `\bmod`/`\pmod`, fence symbols, `\operatorname*` and `\mathop` limits. -The crate currently has 138 unit tests plus one route-D integration test. Workspace verification: `cargo fmt --all -- --check`; `cargo test --workspace --offline` runs 226 tests (138 route-D unit, 1 route-D integration, 71 v1 integration, 11 server, 4 v1 unit, 1 doctest). v1 remains the live server path. +The crate currently has 138 unit tests plus one route-D integration test. Workspace verification: `cargo fmt --all -- --check`; `cargo test --workspace --offline` runs 227 tests (138 route-D unit, 1 route-D integration, 71 v1 integration, 12 server, 4 v1 unit, 1 doctest). v1 remains the live server path. ### M0 incremental demo diff --git a/src/route_d.rs b/src/route_d.rs index af0cbff..aba325f 100755 --- a/src/route_d.rs +++ b/src/route_d.rs @@ -103,20 +103,34 @@ fn command_body<'a>(text: &'a str, command: &str) -> Option<&'a str> { } fn parse_blocks(raw: &str) -> Vec { - 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 = 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() { diff --git a/tests/server.rs b/tests/server.rs index f995e7a..39e3c98 100644 --- a/tests/server.rs +++ b/tests/server.rs @@ -441,6 +441,23 @@ fn route_d_renders_itemize_lists() { assert!(svg.contains(">•")); } +#[test] +fn route_d_renders_enumerate_lists() { + let server = TestServer::start("route-d-enumerate"); + let response = server.request( + "POST", + "/api/route-d/preview", + b"\\begin{enumerate}\\item First\\item Second\\end{enumerate}", + "text/plain", + ); + assert_eq!(response.status, 200, "{}", response.text()); + let value: Value = serde_json::from_slice(&response.body).expect("route-D JSON"); + let svg = value["pages"][0]["svg"].as_str().unwrap(); + assert!(svg.contains(">1")); + assert!(svg.contains(">2")); + assert!(svg.contains(">F")); +} + #[test] fn edits_route_d_preview_pages() { let server = TestServer::start("route-d-edit");