diff --git a/crates/engine/src/cmd/file.rs b/crates/engine/src/cmd/file.rs index b1600f848..5945c7db6 100644 --- a/crates/engine/src/cmd/file.rs +++ b/crates/engine/src/cmd/file.rs @@ -390,11 +390,12 @@ fn report_damage(s: &mut Session, damaged: &Damage) -> Result<()> { Ok(()) } -/// Encode the presentation in `format` (`deckcraft`, `pptx`, `potx`, `ppsx`, `outline`, `pdf`, `gif`). +/// Encode the presentation in `format` (`deckcraft`, `pptx`, `potx`, `ppsx`, `outline`, `txt`, `pdf`, `gif`). pub fn save_bytes(doc: &Presentation, format: &str) -> Result> { match format { f @ ("pptx" | "potx" | "ppsx") => deckcraft_pptx::export_as(doc, f).map_err(|e| EngineError::Other(e.to_string())), - "outline" | "txt" => Ok(deckcraft_format::slides_to_outline(doc).into_bytes()), + "outline" => Ok(deckcraft_format::slides_to_outline(doc).into_bytes()), + "txt" => Ok(outline_txt_bytes(&deckcraft_format::slides_to_outline(doc))), "rtf" => Ok(deckcraft_format::rtf::slides_to_rtf(doc).into_bytes()), "pdf" => deckcraft_pdf::export(doc, &Default::default()).map_err(|e| EngineError::Other(e.to_string())), "gif" => gif_bytes(doc, &Value::Null), @@ -404,6 +405,14 @@ pub fn save_bytes(doc: &Presentation, format: &str) -> Result> { } } +/// The `.txt` outline bytes: CRLF for the reference app, without doubling a CR that is +/// already in the text. `TextBody::from_text` normalizes CR and CRLF (`text.rs:739`), but +/// imported text can still carry one, so normalize before adding CRLF. Crate-visible so the +/// regression test can feed it a CRLF string directly. +pub(crate) fn outline_txt_bytes(text: &str) -> Vec { + text.replace("\r\n", "\n").replace('\n', "\r\n").into_bytes() +} + /// Paper sizes for notes and handouts, for the UI's Print page. pub use deckcraft_pdf::{PAPERS, paper_size}; @@ -536,7 +545,9 @@ pub fn format_for_path(path: &str) -> &'static str { "pdf" } else if l.ends_with(".gif") { "gif" - } else if l.ends_with(".txt") || l.ends_with(".md") { + } else if l.ends_with(".txt") { + "txt" + } else if l.ends_with(".md") { "outline" } else if l.ends_with(".rtf") { "rtf" diff --git a/crates/engine/src/tests.rs b/crates/engine/src/tests.rs index efe5445a5..0d665bc86 100644 --- a/crates/engine/src/tests.rs +++ b/crates/engine/src/tests.rs @@ -1399,7 +1399,8 @@ fn writable_format_for_path_rejects_formats_deckcraft_does_not_write() { assert_eq!(f("dir/A.PPTX"), Some("pptx")); assert_eq!(f("a.pdf"), Some("pdf")); assert_eq!(f("a.jpg"), Some("jpeg")); - assert_eq!(f("a.txt"), Some("outline")); + assert_eq!(f("a.txt"), Some("txt")); + assert_eq!(f("a.md"), Some("outline")); assert_eq!(f("a.gif"), Some("gif")); for path in ["a.odp", "a.bmp", "a.svg", "a.outline", "a", "dir.v2/a"] { assert_eq!(f(path), None, "{path}");