From fbe0d73ecb64f786a9442760cf7a35b9e6c86b78 Mon Sep 17 00:00:00 2001 From: bokuweb Date: Sat, 2 Apr 2022 00:43:29 +0900 Subject: [PATCH] fix: remove \n in text (#461) --- docx-core/examples/reader.rs | 4 ++-- docx-core/src/documents/elements/run.rs | 8 +++++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/docx-core/examples/reader.rs b/docx-core/examples/reader.rs index 3410672..b2baf30 100644 --- a/docx-core/examples/reader.rs +++ b/docx-core/examples/reader.rs @@ -4,11 +4,11 @@ use std::fs::File; use std::io::{Read, Write}; pub fn main() { - let mut file = File::open("./hello.docx").unwrap(); + let mut file = File::open("./#3276.docx").unwrap(); let mut buf = vec![]; file.read_to_end(&mut buf).unwrap(); - let mut file = File::create("./hello.json").unwrap(); + let mut file = File::create("./#3276.json").unwrap(); let res = read_docx(&buf).unwrap().json(); file.write_all(res.as_bytes()).unwrap(); file.flush().unwrap(); diff --git a/docx-core/src/documents/elements/run.rs b/docx-core/src/documents/elements/run.rs index 8b07795..772ae63 100644 --- a/docx-core/src/documents/elements/run.rs +++ b/docx-core/src/documents/elements/run.rs @@ -107,13 +107,15 @@ impl Run { } pub fn add_text(mut self, text: impl Into) -> Run { - self.children.push(RunChild::Text(Text::new(text))); + self.children + .push(RunChild::Text(Text::new(text.into().replace('\n', "")))); self } pub fn add_delete_text(mut self, text: impl Into) -> Run { - self.children - .push(RunChild::DeleteText(DeleteText::new(text))); + self.children.push(RunChild::DeleteText(DeleteText::new( + text.into().replace('\n', ""), + ))); self }