parent
aa549bd5cf
commit
042cdc58f4
|
@ -0,0 +1,10 @@
|
|||
use xml::attribute::OwnedAttribute;
|
||||
|
||||
pub fn read_bool(attrs: &[OwnedAttribute]) -> bool {
|
||||
if let Some(v) = attrs.get(0) {
|
||||
if &v.value == "0" || &v.value == "false" {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
true
|
||||
}
|
|
@ -1,7 +1,9 @@
|
|||
mod bool_value;
|
||||
mod indent;
|
||||
mod indent_level;
|
||||
mod width;
|
||||
|
||||
pub use bool_value::*;
|
||||
pub use indent::*;
|
||||
pub use indent_level::*;
|
||||
pub use width::*;
|
||||
|
|
|
@ -32,30 +32,24 @@ impl ElementReader for Run {
|
|||
let e = XMLElement::from_str(&name.local_name).unwrap();
|
||||
match e {
|
||||
XMLElement::Tab => {
|
||||
run = {
|
||||
if let Some(v) = &attributes.get(0) {
|
||||
if &v.value == "0" {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
run.add_tab()
|
||||
}
|
||||
run = run.add_tab();
|
||||
}
|
||||
XMLElement::Bold => {
|
||||
run = {
|
||||
if let Some(v) = &attributes.get(0) {
|
||||
if &v.value == "0" {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
run.bold()
|
||||
if !read_bool(&attributes) {
|
||||
continue;
|
||||
}
|
||||
run = run.bold();
|
||||
}
|
||||
XMLElement::Highlight => run = run.highlight(attributes[0].value.clone()),
|
||||
XMLElement::Color => run = run.color(attributes[0].value.clone()),
|
||||
XMLElement::Size => run = run.size(usize::from_str(&attributes[0].value)?),
|
||||
XMLElement::Underline => run = run.underline(&attributes[0].value.clone()),
|
||||
XMLElement::Italic => run = run.italic(),
|
||||
XMLElement::Italic => {
|
||||
if !read_bool(&attributes) {
|
||||
continue;
|
||||
}
|
||||
run = run.italic();
|
||||
}
|
||||
XMLElement::Vanish => run = run.vanish(),
|
||||
XMLElement::Text => text_state = TextState::Text,
|
||||
XMLElement::DeleteText => text_state = TextState::Delete,
|
||||
|
@ -218,4 +212,64 @@ mod tests {
|
|||
}
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_read_italic_false() {
|
||||
let c = r#"<w:document xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main">
|
||||
<w:r><w:rPr>
|
||||
<w:b w:val="true"/>
|
||||
<w:i w:val="false"/>
|
||||
</w:rPr></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![],
|
||||
run_property: RunProperty {
|
||||
sz: None,
|
||||
sz_cs: None,
|
||||
color: None,
|
||||
highlight: None,
|
||||
underline: None,
|
||||
bold: Some(Bold::new()),
|
||||
bold_cs: Some(BoldCs::new()),
|
||||
italic: None,
|
||||
italic_cs: None,
|
||||
vanish: None,
|
||||
},
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_read_italic_0() {
|
||||
let c = r#"<w:document xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main">
|
||||
<w:r><w:rPr>
|
||||
<w:b w:val="1"/>
|
||||
<w:i w:val="0"/>
|
||||
</w:rPr></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![],
|
||||
run_property: RunProperty {
|
||||
sz: None,
|
||||
sz_cs: None,
|
||||
color: None,
|
||||
highlight: None,
|
||||
underline: None,
|
||||
bold: Some(Bold::new()),
|
||||
bold_cs: Some(BoldCs::new()),
|
||||
italic: None,
|
||||
italic_cs: None,
|
||||
vanish: None,
|
||||
},
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "docx-wasm",
|
||||
"version": "0.0.41",
|
||||
"version": "0.0.44",
|
||||
"main": "dist/node/index.js",
|
||||
"browser": "dist/web/index.js",
|
||||
"author": "bokuweb <bokuweb12@gmail.com>",
|
||||
|
|
Loading…
Reference in New Issue