Fix whitespace (#45)

* fix: whitespace

* fix: test
main
bokuweb 2020-02-28 11:36:03 +09:00 committed by GitHub
parent d8ea19e7cf
commit 61d42f4d3c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 26 additions and 10 deletions

View File

@ -11,6 +11,7 @@ use crate::types::BreakType;
#[derive(PartialEq, Debug)]
enum TextState {
Idle,
Text,
Delete,
}
@ -21,7 +22,7 @@ impl ElementReader for Run {
_attrs: &[OwnedAttribute],
) -> Result<Self, ReaderError> {
let mut run = Run::new();
let mut text_state = TextState::Text;
let mut text_state = TextState::Idle;
loop {
let e = r.next();
match e {
@ -46,17 +47,32 @@ impl ElementReader for Run {
_ => {}
}
}
Ok(XmlEvent::Characters(c)) => {
if text_state == TextState::Delete {
Ok(XmlEvent::Characters(c)) => match text_state {
TextState::Delete => {
run = run.add_delete_text(c);
} else {
}
TextState::Text => {
run = run.add_text(c);
}
}
_ => {}
},
Ok(XmlEvent::Whitespace(c)) => match text_state {
TextState::Delete => {
run = run.add_delete_text(c);
}
TextState::Text => {
run = run.add_text(c);
}
_ => {}
},
Ok(XmlEvent::EndElement { name, .. }) => {
let e = XMLElement::from_str(&name.local_name).unwrap();
if let XMLElement::Run = e {
return Ok(run);
match e {
XMLElement::Run => {
return Ok(run);
}
XMLElement::DeleteText | XMLElement::Text => text_state = TextState::Idle,
_ => {}
}
}
Err(_) => return Err(ReaderError::XMLReadError),

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -1,6 +1,6 @@
{
"name": "docx-wasm",
"version": "0.0.37",
"version": "0.0.38",
"main": "dist/node/index.js",
"browser": "dist/web/index.js",
"author": "bokuweb <bokuweb12@gmail.com>",