fix: ignore change property to import diff docx (#85)
parent
7f22cc546e
commit
b464873e68
|
@ -0,0 +1,20 @@
|
||||||
|
use std::io::Read;
|
||||||
|
use std::str::FromStr;
|
||||||
|
|
||||||
|
use xml::reader::{EventReader, XmlEvent};
|
||||||
|
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
pub(crate) fn ignore_element<R: Read>(el: XMLElement, ignore: XMLElement, r: &mut EventReader<R>) {
|
||||||
|
if ignore == el {
|
||||||
|
loop {
|
||||||
|
let e = r.next();
|
||||||
|
if let Ok(XmlEvent::EndElement { name, .. }) = e {
|
||||||
|
let e = XMLElement::from_str(&name.local_name).unwrap();
|
||||||
|
if e == ignore {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -7,6 +7,7 @@ mod document_rels;
|
||||||
mod drawing;
|
mod drawing;
|
||||||
mod errors;
|
mod errors;
|
||||||
mod from_xml;
|
mod from_xml;
|
||||||
|
mod ignore;
|
||||||
mod insert;
|
mod insert;
|
||||||
mod level;
|
mod level;
|
||||||
mod level_override;
|
mod level_override;
|
||||||
|
|
|
@ -22,6 +22,9 @@ impl ElementReader for Paragraph {
|
||||||
attributes, name, ..
|
attributes, name, ..
|
||||||
}) => {
|
}) => {
|
||||||
let e = XMLElement::from_str(&name.local_name).unwrap();
|
let e = XMLElement::from_str(&name.local_name).unwrap();
|
||||||
|
|
||||||
|
ignore::ignore_element(e.clone(), XMLElement::ParagraphPropertyChange, r);
|
||||||
|
|
||||||
match e {
|
match e {
|
||||||
XMLElement::Run => {
|
XMLElement::Run => {
|
||||||
let run = Run::read(r, attrs)?;
|
let run = Run::read(r, attrs)?;
|
||||||
|
|
|
@ -18,6 +18,10 @@ impl ElementReader for Table {
|
||||||
attributes, name, ..
|
attributes, name, ..
|
||||||
}) => {
|
}) => {
|
||||||
let e = XMLElement::from_str(&name.local_name).unwrap();
|
let e = XMLElement::from_str(&name.local_name).unwrap();
|
||||||
|
|
||||||
|
ignore::ignore_element(e.clone(), XMLElement::TablePropertyChange, r);
|
||||||
|
ignore::ignore_element(e.clone(), XMLElement::TableGridChange, r);
|
||||||
|
|
||||||
match e {
|
match e {
|
||||||
XMLElement::TableRow => {
|
XMLElement::TableRow => {
|
||||||
t = t.add_row(TableRow::read(r, &attributes)?);
|
t = t.add_row(TableRow::read(r, &attributes)?);
|
||||||
|
|
|
@ -30,6 +30,13 @@ impl ElementReader for TableCell {
|
||||||
attributes, name, ..
|
attributes, name, ..
|
||||||
}) => {
|
}) => {
|
||||||
let e = XMLElement::from_str(&name.local_name).unwrap();
|
let e = XMLElement::from_str(&name.local_name).unwrap();
|
||||||
|
|
||||||
|
ignore::ignore_element(
|
||||||
|
e.clone(),
|
||||||
|
XMLElement::TableCellPropertyChange,
|
||||||
|
r,
|
||||||
|
);
|
||||||
|
|
||||||
match e {
|
match e {
|
||||||
XMLElement::TableCellWidth => {
|
XMLElement::TableCellWidth => {
|
||||||
let mut w = 0;
|
let mut w = 0;
|
||||||
|
|
|
@ -16,6 +16,9 @@ impl ElementReader for TableRow {
|
||||||
attributes, name, ..
|
attributes, name, ..
|
||||||
}) => {
|
}) => {
|
||||||
let e = XMLElement::from_str(&name.local_name).unwrap();
|
let e = XMLElement::from_str(&name.local_name).unwrap();
|
||||||
|
|
||||||
|
ignore::ignore_element(e.clone(), XMLElement::TableRowPropertyChange, r);
|
||||||
|
|
||||||
if let XMLElement::TableCell = e {
|
if let XMLElement::TableCell = e {
|
||||||
cells.push(TableCell::read(r, &attributes)?);
|
cells.push(TableCell::read(r, &attributes)?);
|
||||||
continue;
|
continue;
|
||||||
|
|
|
@ -6,7 +6,7 @@ use xml::reader::EventReader;
|
||||||
|
|
||||||
use crate::reader::ReaderError;
|
use crate::reader::ReaderError;
|
||||||
|
|
||||||
#[derive(PartialEq, Debug)]
|
#[derive(PartialEq, Debug, Clone)]
|
||||||
pub enum XMLElement {
|
pub enum XMLElement {
|
||||||
Body,
|
Body,
|
||||||
Paragraph,
|
Paragraph,
|
||||||
|
@ -26,6 +26,7 @@ pub enum XMLElement {
|
||||||
Break,
|
Break,
|
||||||
Tab,
|
Tab,
|
||||||
ParagraphStyle,
|
ParagraphStyle,
|
||||||
|
ParagraphPropertyChange,
|
||||||
Indent,
|
Indent,
|
||||||
Name,
|
Name,
|
||||||
Alignment,
|
Alignment,
|
||||||
|
@ -53,6 +54,11 @@ pub enum XMLElement {
|
||||||
TableWidth,
|
TableWidth,
|
||||||
TableIndent,
|
TableIndent,
|
||||||
TableBorders,
|
TableBorders,
|
||||||
|
// Change
|
||||||
|
TableGridChange,
|
||||||
|
TablePropertyChange,
|
||||||
|
TableRowPropertyChange,
|
||||||
|
TableCellPropertyChange,
|
||||||
Top,
|
Top,
|
||||||
Right,
|
Right,
|
||||||
Left,
|
Left,
|
||||||
|
@ -158,6 +164,7 @@ impl FromStr for XMLElement {
|
||||||
"szCs" => Ok(XMLElement::SizeCs),
|
"szCs" => Ok(XMLElement::SizeCs),
|
||||||
"u" => Ok(XMLElement::Underline),
|
"u" => Ok(XMLElement::Underline),
|
||||||
"pStyle" => Ok(XMLElement::ParagraphStyle),
|
"pStyle" => Ok(XMLElement::ParagraphStyle),
|
||||||
|
"pPrChange" => Ok(XMLElement::ParagraphPropertyChange),
|
||||||
"highlight" => Ok(XMLElement::Highlight),
|
"highlight" => Ok(XMLElement::Highlight),
|
||||||
"b" => Ok(XMLElement::Bold),
|
"b" => Ok(XMLElement::Bold),
|
||||||
"bCs" => Ok(XMLElement::BoldCs),
|
"bCs" => Ok(XMLElement::BoldCs),
|
||||||
|
@ -200,6 +207,10 @@ impl FromStr for XMLElement {
|
||||||
"insideV" => Ok(XMLElement::InsideV),
|
"insideV" => Ok(XMLElement::InsideV),
|
||||||
"tblCellMar" => Ok(XMLElement::TableCellMargin),
|
"tblCellMar" => Ok(XMLElement::TableCellMargin),
|
||||||
"tblGrid" => Ok(XMLElement::TableGrid),
|
"tblGrid" => Ok(XMLElement::TableGrid),
|
||||||
|
"tblPrChange" => Ok(XMLElement::TablePropertyChange),
|
||||||
|
"trPrChange" => Ok(XMLElement::TableRowPropertyChange),
|
||||||
|
"tcPrChange" => Ok(XMLElement::TableCellPropertyChange),
|
||||||
|
"tblGridChange" => Ok(XMLElement::TableGridChange),
|
||||||
"gridCol" => Ok(XMLElement::GridCol),
|
"gridCol" => Ok(XMLElement::GridCol),
|
||||||
"style" => Ok(XMLElement::Style),
|
"style" => Ok(XMLElement::Style),
|
||||||
"basedOn" => Ok(XMLElement::BasedOn),
|
"basedOn" => Ok(XMLElement::BasedOn),
|
||||||
|
|
Loading…
Reference in New Issue