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