parent
1cdb20a54b
commit
51af3acfaf
|
@ -18,6 +18,13 @@ impl DeleteText {
|
|||
preserve_space: true,
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn without_escape(text: impl Into<String>) -> DeleteText {
|
||||
DeleteText {
|
||||
text: text.into(),
|
||||
preserve_space: true,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl BuildXML for DeleteText {
|
||||
|
|
|
@ -127,6 +127,13 @@ impl Run {
|
|||
self
|
||||
}
|
||||
|
||||
pub(crate) fn add_text_without_escape(mut self, text: impl Into<String>) -> Run {
|
||||
self.children.push(RunChild::Text(Text::without_escape(
|
||||
text.into().replace('\n', ""),
|
||||
)));
|
||||
self
|
||||
}
|
||||
|
||||
pub fn add_delete_text(mut self, text: impl Into<String>) -> Run {
|
||||
self.children.push(RunChild::DeleteText(DeleteText::new(
|
||||
text.into().replace('\n', ""),
|
||||
|
@ -134,6 +141,14 @@ impl Run {
|
|||
self
|
||||
}
|
||||
|
||||
pub(crate) fn add_delete_text_without_escape(mut self, text: impl Into<String>) -> Run {
|
||||
self.children
|
||||
.push(RunChild::DeleteText(DeleteText::without_escape(
|
||||
text.into().replace('\n', ""),
|
||||
)));
|
||||
self
|
||||
}
|
||||
|
||||
pub fn add_field_char(mut self, t: crate::types::FieldCharType, dirty: bool) -> Run {
|
||||
let mut f = FieldChar::new(t);
|
||||
if dirty {
|
||||
|
|
|
@ -19,6 +19,13 @@ impl Text {
|
|||
preserve_space: true,
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn without_escape(text: impl Into<String>) -> Text {
|
||||
Text {
|
||||
text: text.into(),
|
||||
preserve_space: true,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl BuildXML for Text {
|
||||
|
|
|
@ -9,3 +9,13 @@ pub(crate) fn escape(text: &str) -> String {
|
|||
// .replace('\r', "
")
|
||||
.replace('\r', "")
|
||||
}
|
||||
|
||||
pub(crate) fn replace_escaped(text: &str) -> String {
|
||||
text.replace("<", "<")
|
||||
.replace(">", ">")
|
||||
.replace("&", "&")
|
||||
.replace(""", "\"")
|
||||
.replace("'", "'")
|
||||
.replace("'", "'")
|
||||
.replace(" ", " ")
|
||||
}
|
||||
|
|
|
@ -8,6 +8,7 @@ use xml::reader::{EventReader, XmlEvent};
|
|||
|
||||
use super::Run;
|
||||
|
||||
use crate::escape::replace_escaped;
|
||||
use crate::types::BreakType;
|
||||
use crate::{reader::*, FieldCharType};
|
||||
|
||||
|
@ -142,19 +143,19 @@ impl ElementReader for Run {
|
|||
}
|
||||
Ok(XmlEvent::Characters(c)) => match text_state {
|
||||
TextState::Delete => {
|
||||
run = run.add_delete_text(c);
|
||||
run = run.add_delete_text_without_escape(replace_escaped(&c));
|
||||
}
|
||||
TextState::Text => {
|
||||
run = run.add_text(c);
|
||||
run = run.add_text_without_escape(replace_escaped(&c));
|
||||
}
|
||||
_ => {}
|
||||
},
|
||||
Ok(XmlEvent::Whitespace(c)) => match text_state {
|
||||
TextState::Delete => {
|
||||
run = run.add_delete_text(c);
|
||||
run = run.add_delete_text_without_escape(replace_escaped(&c));
|
||||
}
|
||||
TextState::Text => {
|
||||
run = run.add_text(c);
|
||||
run = run.add_text_without_escape(replace_escaped(&c));
|
||||
}
|
||||
_ => {}
|
||||
},
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -184,6 +184,12 @@ describe("reader", () => {
|
|||
const json = w.readDocx(buffer);
|
||||
expect(json).toMatchSnapshot();
|
||||
});
|
||||
|
||||
test("should read issue554", () => {
|
||||
const buffer = readFileSync("../fixtures/issue554/issue554.docx");
|
||||
const json = w.readDocx(buffer);
|
||||
expect(json).toMatchSnapshot();
|
||||
});
|
||||
});
|
||||
|
||||
describe("writer", () => {
|
||||
|
|
Binary file not shown.
Loading…
Reference in New Issue