mirror of
https://github.com/storytold/deckcraft.git
synced 2026-12-04 22:50:29 +00:00
fix: write CRLF in the TXT outline export (#2387)
Signed-off-by: MaheshDesu <[email protected]>
This commit is contained in:
@@ -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<Vec<u8>> {
|
||||
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<Vec<u8>> {
|
||||
}
|
||||
}
|
||||
|
||||
/// 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<u8> {
|
||||
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"
|
||||
|
||||
@@ -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}");
|
||||
|
||||
Reference in New Issue
Block a user