mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-17 15:55:14 +00:00
craft-docx: relate the bibliography store from the main part, not the package (#1835)
This commit is contained in:
1 parent
d09d31c109
commit
76fc04feee
2 files changed
+16
-4
No files matched your search
@@ -227,6 +227,11 @@ pub(crate) fn write_parts(doc: &Document, flavor: Flavor) -> Result<Vec<(String,
|
||||
}
|
||||
}
|
||||
|
||||
// Bibliography sources: Word looks for their data store among the main part's relationships,
|
||||
// not the package's, and shows no sources when it is related from `_rels/.rels`.
|
||||
if !doc.sources.is_empty() {
|
||||
rels.add(rt::CUSTOM_XML, "../customXml/item1.xml", false);
|
||||
}
|
||||
// Main part goes first in the zip after content types.
|
||||
entries.insert(0, ("word/document.xml".into(), body));
|
||||
overrides.insert(0, ("/word/document.xml".into(), flavor.main_content_type().into()));
|
||||
@@ -246,7 +251,6 @@ pub(crate) fn write_parts(doc: &Document, flavor: Flavor) -> Result<Vec<(String,
|
||||
overrides.push(("/docProps/custom.xml".into(), "application/vnd.openxmlformats-officedocument.custom-properties+xml".into()));
|
||||
}
|
||||
if !doc.sources.is_empty() {
|
||||
root.add(rt::CUSTOM_XML, "customXml/item1.xml", false);
|
||||
let mut item_rels = PartRels::default();
|
||||
item_rels.add(rt::CUSTOM_XML_PROPS, "itemProps1.xml", false);
|
||||
push_part(
|
||||
|
||||
@@ -2399,6 +2399,10 @@ fn bibliography_sources_round_trip() {
|
||||
|
||||
assert_bibliography_parts(&bytes);
|
||||
assert_bibliography_sources_round_trip(&bytes);
|
||||
// Saved again after reading, the store keeps one relationship, from the main part.
|
||||
let again = craft_docx::write(&craft_docx::read(&bytes).expect("read")).expect("write again");
|
||||
assert_bibliography_parts(&again);
|
||||
assert_eq!(craft_docx::read(&again).expect("read again").sources.len(), d.sources.len());
|
||||
}
|
||||
|
||||
/// #4848: a corporate author saves as Word's `b:Corporate`, in place of a name list (a role holds
|
||||
@@ -2440,10 +2444,14 @@ fn assert_bibliography_parts(bytes: &[u8]) {
|
||||
assert!(zip.by_name("customXml/itemProps1.xml").is_ok());
|
||||
assert!(zip.by_name("customXml/_rels/item1.xml.rels").is_ok());
|
||||
|
||||
// Word finds the sources' data store only through the main part's relationships.
|
||||
let mut rels_xml = String::new();
|
||||
std::io::Read::read_to_string(&mut zip.by_name("_rels/.rels").unwrap(), &mut rels_xml).unwrap();
|
||||
assert!(rels_xml.contains("relationships/customXml"), "{rels_xml}");
|
||||
assert!(rels_xml.contains("Target=\"customXml/item1.xml\""), "{rels_xml}");
|
||||
std::io::Read::read_to_string(&mut zip.by_name("word/_rels/document.xml.rels").unwrap(), &mut rels_xml).unwrap();
|
||||
assert_eq!(rels_xml.matches("relationships/customXml\"").count(), 1, "{rels_xml}");
|
||||
assert!(rels_xml.contains("Target=\"../customXml/item1.xml\""), "{rels_xml}");
|
||||
let mut root_xml = String::new();
|
||||
std::io::Read::read_to_string(&mut zip.by_name("_rels/.rels").unwrap(), &mut root_xml).unwrap();
|
||||
assert!(!root_xml.contains("relationships/customXml\""), "{root_xml}");
|
||||
|
||||
let mut ct_xml = String::new();
|
||||
std::io::Read::read_to_string(&mut zip.by_name("[Content_Types].xml").unwrap(), &mut ct_xml).unwrap();
|
||||
|
||||
Reference in new issue
Block a user