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;
|
||||||
mod indent_level;
|
mod indent_level;
|
||||||
mod width;
|
mod width;
|
||||||
|
|
||||||
|
pub use bool_value::*;
|
||||||
pub use indent::*;
|
pub use indent::*;
|
||||||
pub use indent_level::*;
|
pub use indent_level::*;
|
||||||
pub use width::*;
|
pub use width::*;
|
||||||
|
|
|
@ -32,30 +32,24 @@ impl ElementReader for Run {
|
||||||
let e = XMLElement::from_str(&name.local_name).unwrap();
|
let e = XMLElement::from_str(&name.local_name).unwrap();
|
||||||
match e {
|
match e {
|
||||||
XMLElement::Tab => {
|
XMLElement::Tab => {
|
||||||
run = {
|
run = run.add_tab();
|
||||||
if let Some(v) = &attributes.get(0) {
|
|
||||||
if &v.value == "0" {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
run.add_tab()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
XMLElement::Bold => {
|
XMLElement::Bold => {
|
||||||
run = {
|
if !read_bool(&attributes) {
|
||||||
if let Some(v) = &attributes.get(0) {
|
|
||||||
if &v.value == "0" {
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
run = run.bold();
|
||||||
run.bold()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
XMLElement::Highlight => run = run.highlight(attributes[0].value.clone()),
|
XMLElement::Highlight => run = run.highlight(attributes[0].value.clone()),
|
||||||
XMLElement::Color => run = run.color(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::Size => run = run.size(usize::from_str(&attributes[0].value)?),
|
||||||
XMLElement::Underline => run = run.underline(&attributes[0].value.clone()),
|
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::Vanish => run = run.vanish(),
|
||||||
XMLElement::Text => text_state = TextState::Text,
|
XMLElement::Text => text_state = TextState::Text,
|
||||||
XMLElement::DeleteText => text_state = TextState::Delete,
|
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",
|
"name": "docx-wasm",
|
||||||
"version": "0.0.41",
|
"version": "0.0.44",
|
||||||
"main": "dist/node/index.js",
|
"main": "dist/node/index.js",
|
||||||
"browser": "dist/web/index.js",
|
"browser": "dist/web/index.js",
|
||||||
"author": "bokuweb <bokuweb12@gmail.com>",
|
"author": "bokuweb <bokuweb12@gmail.com>",
|
||||||
|
|
Loading…
Reference in New Issue