Let project previews opt into the route-D core

This commit is contained in:
gloamxun committed 2026-10-20 23:09:32 +08:00
1 parent a8e7499ce3
commit fe7fd68321
5 files changed
+59 -7

No files matched your search

+6
View File
@@ -499,6 +499,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::latex_preview_json(&source) {
Ok(json) => respond_json(request, 200, &json),
Err(error) => respond_api_error(request, 422, &error),
};
}
match compiler.preview_json(&source, &file_name) {
Ok(json) => respond_json(request, 200, &json),
Err(error) => respond(
+13
View File
@@ -20,6 +20,19 @@ thread_local! {
static ROUTE_D_SESSION: RefCell<Option<(Document, Engine)>> = const { RefCell::new(None) };
}
/// Build a JSON preview from the document body of a small LaTeX file.
///
/// This is the opt-in M7 bridge for v1 projects: the preamble is discarded and
/// the body is handed to the same route-D paragraph parser used by
/// `/api/route-d/preview`. The v1 semantic pipeline remains the default.
pub fn latex_preview_json(source: &str) -> Result<String, String> {
let body = source
.split_once("\\begin{document}")
.map_or(source, |(_, body)| body);
let body = body.split("\\end{document}").next().unwrap_or(body);
preview_json(body)
}
/// Build a JSON preview from blank-line-separated plain-text paragraphs.
pub fn preview_json(source: &str) -> Result<String, String> {
let paragraphs = paragraphs(source)?;