Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion swift-shifter/src/converter/document/conversion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use crate::converter::document::llm::*;
use crate::converter::document::pdf;
use crate::converter::document::types::*;
use crate::converter::document::utils::*;
use crate::converter::graph::normalize_ext;
use std::path::Path;
use tauri::Emitter;

Expand Down Expand Up @@ -369,7 +370,7 @@ pub async fn convert_document(

// typst → pdf is best served by `typst compile` directly: it's the native
// toolchain, needs no LaTeX/PDF engine, and renders faster than pandoc.
if input_ext == "typst" && target_format == "pdf" {
if normalize_ext(&input_ext) == "typst" && target_format == "pdf" {
return convert_typst_to_pdf(app, path, output_dir).await;
}

Expand Down
16 changes: 13 additions & 3 deletions swift-shifter/src/converter/document/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ pub fn ext_to_pandoc_format(ext: &str) -> &str {
"md" | "markdown" => "markdown",
"txt" => "plain",
"tex" | "latex" => "latex",
"typst" => "typst",
"typ" | "typst" => "typst",
"epub" => "epub",
"pdf" => "pdf",
_ => ext,
Expand All @@ -79,10 +79,12 @@ pub fn ext_to_pandoc_input_format(ext: &str) -> &str {
}
}

/// Output file extension for a given target format keyword.
/// Output file extension for a given target format keyword. Typst output is
/// written as `.typ`, the extension `typst compile` and editors expect.
pub fn target_to_ext(target: &str) -> &str {
match target {
"latex" => "tex",
"typst" => "typ",
_ => target,
}
}
Expand All @@ -101,8 +103,16 @@ mod tests {

#[test]
fn input_format_matches_output_for_non_txt() {
for ext in ["md", "tex", "latex", "typst", "epub", "pdf"] {
for ext in ["md", "tex", "latex", "typ", "typst", "epub", "pdf"] {
assert_eq!(ext_to_pandoc_input_format(ext), ext_to_pandoc_format(ext));
}
}

#[test]
fn typst_reads_from_typ_and_writes_typ() {
assert_eq!(ext_to_pandoc_input_format("typ"), "typst");
assert_eq!(target_to_ext("typst"), "typ");
assert_eq!(target_to_ext("latex"), "tex");
assert_eq!(target_to_ext("md"), "md");
}
}
1 change: 1 addition & 0 deletions swift-shifter/src/converter/graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ pub fn normalize_ext(ext: &str) -> &str {
"tif" => "tiff",
"markdown" => "md",
"latex" => "tex",
"typ" => "typst",
"heif" => "heic",
other => other,
}
Expand Down
8 changes: 8 additions & 0 deletions swift-shifter/src/converter/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ fn test_detect_output_formats_snapshot() {
("/x.tex", &["md", "html", "pdf", "typst"]),
("/x.latex", &["md", "html", "pdf", "typst"]),
("/x.typst", &["md", "html", "pdf", "tex"]),
("/x.typ", &["md", "html", "pdf", "tex"]),
("/x.epub", &["pdf", "mobi", "md", "html"]),
("/x.mobi", &["epub", "pdf", "html", "md"]),
("/x.pdf", &["epub", "mobi", "html", "md"]),
Expand Down Expand Up @@ -220,6 +221,13 @@ fn test_find_path_normalizes_aliases() {
assert_eq!(p, vec!["jpg".to_string(), "png".to_string()]);
}

#[test]
fn test_find_path_accepts_typ_extension() {
// `.typ` is Typst's real extension; it must route like `.typst`.
let p = crate::converter::graph::find_path("typ", "pdf").unwrap();
assert_eq!(p, vec!["typst".to_string(), "pdf".to_string()]);
}

#[test]
fn test_find_path_unreachable_returns_none() {
assert!(crate::converter::graph::find_path("csv", "toml").is_none());
Expand Down
Loading