it works! produces the exact same xml as the python version
Some checks failed
/ test (push) Failing after 24s
Some checks failed
/ test (push) Failing after 24s
This commit is contained in:
parent
73c45323c8
commit
9bf15dc9d0
2 changed files with 22 additions and 3 deletions
|
|
@ -3838,7 +3838,14 @@ fn main_inner() -> Result<(), Error> {
|
||||||
parser.parse_pdf(ctx, file_name, page_numbers, dump_mupdf_page_xml)?;
|
parser.parse_pdf(ctx, file_name, page_numbers, dump_mupdf_page_xml)?;
|
||||||
let mut insns = xml_tree::Element::new(
|
let mut insns = xml_tree::Element::new(
|
||||||
"instructions".into(),
|
"instructions".into(),
|
||||||
[("is-subset".into(), is_subset.to_string())],
|
[(
|
||||||
|
"is-subset".into(),
|
||||||
|
if is_subset {
|
||||||
|
"True".into()
|
||||||
|
} else {
|
||||||
|
"False".into()
|
||||||
|
},
|
||||||
|
)],
|
||||||
);
|
);
|
||||||
insns.text = "\n".into();
|
insns.text = "\n".into();
|
||||||
insns.tail = "\n".into();
|
insns.tail = "\n".into();
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@
|
||||||
|
|
||||||
use quick_xml::{
|
use quick_xml::{
|
||||||
Writer,
|
Writer,
|
||||||
events::{BytesDecl, BytesText, Event},
|
events::{BytesDecl, BytesStart, BytesText, Event},
|
||||||
};
|
};
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
|
|
||||||
|
|
@ -183,6 +183,15 @@ impl Element {
|
||||||
ElementTag::Normal(tag) if tag.is_empty() => {
|
ElementTag::Normal(tag) if tag.is_empty() => {
|
||||||
writer.write_event(Event::Text(BytesText::new(text)))?;
|
writer.write_event(Event::Text(BytesText::new(text)))?;
|
||||||
}
|
}
|
||||||
|
ElementTag::Normal(tag)
|
||||||
|
if attrib.is_empty() && text.is_empty() && children.is_empty() =>
|
||||||
|
{
|
||||||
|
// write element like `<br />` to match python instead of like `<br/>`
|
||||||
|
writer.write_event(Event::Empty(BytesStart::from_content(
|
||||||
|
tag.clone() + " ",
|
||||||
|
tag.len(),
|
||||||
|
)))?;
|
||||||
|
}
|
||||||
ElementTag::Normal(tag) => {
|
ElementTag::Normal(tag) => {
|
||||||
let mut element_writer = writer.create_element(tag);
|
let mut element_writer = writer.create_element(tag);
|
||||||
for (name, value) in attrib {
|
for (name, value) in attrib {
|
||||||
|
|
@ -212,7 +221,10 @@ impl Element {
|
||||||
) -> std::io::Result<()> {
|
) -> std::io::Result<()> {
|
||||||
let mut writer = Writer::new(writer);
|
let mut writer = Writer::new(writer);
|
||||||
if xml_declaration {
|
if xml_declaration {
|
||||||
writer.write_event(Event::Decl(BytesDecl::new("1.0", Some("utf-8"), None)))?;
|
// use specific string to match python
|
||||||
|
writer.write_event(Event::Decl(BytesDecl::from_start(
|
||||||
|
BytesStart::from_content("xml version='1.0' encoding='utf-8'", 3),
|
||||||
|
)))?;
|
||||||
writer.write_event(Event::Text(BytesText::new("\n")))?;
|
writer.write_event(Event::Text(BytesText::new("\n")))?;
|
||||||
}
|
}
|
||||||
self.write_to(&mut writer)
|
self.write_to(&mut writer)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue