diff --git a/README.md b/README.md index 3ab9558..4074ef0 100644 --- a/README.md +++ b/README.md @@ -577,6 +577,6 @@ It accepts blank-line-separated source with a small `\section`/`\textbf`/`\emph` builder, and returns the v1-compatible preview shape plus per-page hashes and SVG. Route-D paragraphs are laid out with CMR10 advances, kerns and ligatures; runs of two or three hyphens become en/em dashes, and the PDF `/W` array reports the same advances, so extracted text keeps word boundaries. `Document::insertion_classes` caps each insertion class to a page fraction and defers overflow to the next page. The v1 `/preview` and project APIs are unchanged and remain the default. -Project previews can opt into the new core with `POST /api/projects/{id}/preview?engine=route-d`; the same project preview without the query keeps the v1 pipeline. The web client exposes this as the `引擎: v1` / `引擎: Route-D` toggle in the preview toolbar; the choice is stored in `localStorage` and only the preview request, not the exported v1 PDF, switches engines. Route-D project previews keep a session, so an unchanged source reports zero recomputed pages and a one-paragraph edit returns the changed/recomputed page set. `POST /api/route-d/edit/{unit}` applies one paragraph edit to the last route-D +Project previews can opt into the new core with `POST /api/projects/{id}/preview?engine=route-d`; the same project preview without the query keeps the v1 pipeline. The web client exposes this as the `引擎: v1` / `引擎: Route-D` toggle in the preview toolbar; the choice is stored in `localStorage` and switches both the preview request and `POST /api/projects/{id}/pdf`, since the PDF handler honors the same `engine=route-d` query. Route-D project previews keep a session, so an unchanged source reports zero recomputed pages and a one-paragraph edit returns the changed/recomputed page set. `POST /api/route-d/edit/{unit}` applies one paragraph edit to the last route-D document and returns the same page list plus `changedPages` and `recomputedPages`, exposing the checkpoint/page-hash diff from the core. diff --git a/src/main.rs b/src/main.rs index 7ef6f7e..ddae48f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -520,6 +520,12 @@ fn handle_project_request( Ok(source) => source, Err(error) => return respond_api_error(request, 422, &error), }; + if query_param(url, "engine").as_deref() == Some("route-d") { + return match route_d::pdf_bytes(&source) { + Ok(pdf) => respond_pdf(request, pdf), + Err(error) => respond(request, 422, "text/plain; charset=utf-8", &error), + }; + } match compiler.compile(&source, &file_name) { Ok(pdf) => respond_pdf(request, pdf), Err(error) => respond(request, 422, "text/plain; charset=utf-8", &error), diff --git a/src/route_d.rs b/src/route_d.rs index 7370d00..0d000ce 100755 --- a/src/route_d.rs +++ b/src/route_d.rs @@ -124,7 +124,7 @@ pub fn preview_json(source: &str) -> Result { /// Render the same checkpointed document as a route-D PDF. pub fn pdf_bytes(source: &str) -> Result, String> { - let paragraphs = paragraphs(source)?; + let paragraphs = paragraphs(latex_body(source))?; let document = build_document(¶graphs); let engine = Engine::layout(&document); let pages: Vec<_> = engine diff --git a/tests/server.rs b/tests/server.rs index ee446de..b1da94a 100644 --- a/tests/server.rs +++ b/tests/server.rs @@ -260,6 +260,23 @@ fn serves_project_api_preview_and_pdf() { let pdf = server.request("POST", "/api/projects/hello/pdf", &[], "application/pdf"); assert_eq!(pdf.status, 200, "{}", String::from_utf8_lossy(&pdf.body)); assert!(pdf.body.starts_with(b"%PDF-"), "missing PDF header"); + + let route_d_pdf = server.request( + "POST", + "/api/projects/hello/pdf?engine=route-d", + &[], + "application/pdf", + ); + assert_eq!( + route_d_pdf.status, + 200, + "{}", + String::from_utf8_lossy(&route_d_pdf.body) + ); + assert!( + route_d_pdf.body.starts_with(b"%PDF-"), + "missing route-D PDF header" + ); } #[test]