Fix breaking (#46)

* fix: brealing

* 0.0.40
main
bokuweb 2020-02-28 13:42:28 +09:00 committed by GitHub
parent 61d42f4d3c
commit 0697404b40
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 36 additions and 7 deletions

View File

@ -3,7 +3,7 @@ use std::fs::*;
use std::io::Read;
pub fn main() {
let mut file = File::open("./10.docx").unwrap();
let mut file = File::open("./2.docx").unwrap();
let mut buf = vec![];
file.read_to_end(&mut buf).unwrap();
dbg!(read_docx(&buf).unwrap().json());

View File

@ -42,7 +42,11 @@ impl ElementReader for Run {
XMLElement::Text => text_state = TextState::Text,
XMLElement::DeleteText => text_state = TextState::Delete,
XMLElement::Break => {
run = run.add_break(BreakType::from_str(&attributes[0].value)?)
if let Some(a) = &attributes.get(0) {
run = run.add_break(BreakType::from_str(&a.value)?)
} else {
run = run.add_break(BreakType::TextWrapping)
}
}
_ => {}
}
@ -118,8 +122,7 @@ mod tests {
#[test]
fn test_read_tab() {
let c =
r#"<w:document xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main">
let c = r#"<w:document xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main">
<w:r><w:tab /></w:r>
</w:document>"#;
let mut parser = EventReader::new(c.as_bytes());
@ -146,8 +149,7 @@ mod tests {
#[test]
fn test_read_br() {
let c =
r#"<w:document xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main">
let c = r#"<w:document xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main">
<w:r><w:br w:type="page" /></w:r>
</w:document>"#;
let mut parser = EventReader::new(c.as_bytes());
@ -171,4 +173,31 @@ mod tests {
}
);
}
#[test]
fn test_read_empty_br() {
let c = r#"<w:document xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main">
<w:r><w:br /></w:r>
</w:document>"#;
let mut parser = EventReader::new(c.as_bytes());
let run = Run::read(&mut parser, &[]).unwrap();
assert_eq!(
run,
Run {
children: vec![RunChild::Break(Break::new(BreakType::TextWrapping))],
run_property: RunProperty {
sz: None,
sz_cs: None,
color: None,
highlight: None,
underline: None,
bold: None,
bold_cs: None,
italic: None,
italic_cs: None,
vanish: None,
},
}
);
}
}

View File

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