fix: remove \n in text (#461)

main
bokuweb 2022-04-02 00:43:29 +09:00 committed by GitHub
parent 0af4da71b8
commit fbe0d73ecb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 5 deletions

View File

@ -4,11 +4,11 @@ use std::fs::File;
use std::io::{Read, Write}; use std::io::{Read, Write};
pub fn main() { pub fn main() {
let mut file = File::open("./hello.docx").unwrap(); let mut file = File::open("./#3276.docx").unwrap();
let mut buf = vec![]; let mut buf = vec![];
file.read_to_end(&mut buf).unwrap(); 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(); let res = read_docx(&buf).unwrap().json();
file.write_all(res.as_bytes()).unwrap(); file.write_all(res.as_bytes()).unwrap();
file.flush().unwrap(); file.flush().unwrap();

View File

@ -107,13 +107,15 @@ impl Run {
} }
pub fn add_text(mut self, text: impl Into<String>) -> Run { pub fn add_text(mut self, text: impl Into<String>) -> Run {
self.children.push(RunChild::Text(Text::new(text))); self.children
.push(RunChild::Text(Text::new(text.into().replace('\n', ""))));
self self
} }
pub fn add_delete_text(mut self, text: impl Into<String>) -> Run { pub fn add_delete_text(mut self, text: impl Into<String>) -> Run {
self.children self.children.push(RunChild::DeleteText(DeleteText::new(
.push(RunChild::DeleteText(DeleteText::new(text))); text.into().replace('\n', ""),
)));
self self
} }