fix(docx): keep hide-spelling and hide-grammar settings on save (repin)

craft-docx now owns w:hideSpellingErrors and w:hideGrammaticalErrors in
settings.xml; wordcraft_doc::Settings lacked both, so the serde bridge
dropped them. Also fixes the mc:Ignorable order in the section test.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FypgCWNarDG3QfXK2YMzdx
This commit is contained in:
Martin Ball
2026-11-28 23:02:17 +00:00
co-authored by Claude Opus 5.5
parent e3f1356360
commit 4c913ffd28
3 changed files with 27 additions and 1 deletions
+9
View File
@@ -183,6 +183,13 @@ pub struct Settings {
/// comments and tracked changes are saved without `w:date`.
#[serde(skip_serializing_if = "std::ops::Not::not")]
pub remove_date_time: bool,
/// Hide spelling errors in this document only (`w:hideSpellingErrors`): no squiggles under
/// misspelled words.
#[serde(skip_serializing_if = "std::ops::Not::not")]
pub hide_spelling_errors: bool,
/// Hide grammar errors in this document only (`w:hideGrammaticalErrors`).
#[serde(skip_serializing_if = "std::ops::Not::not")]
pub hide_grammar_errors: bool,
/// The document was opened from ODF: the standard's rules that differ from Word's apply as
/// it is laid out.
#[serde(skip_serializing_if = "Option::is_none")]
@@ -349,6 +356,8 @@ impl Default for Settings {
zoom: None,
remove_personal_info: false,
remove_date_time: false,
hide_spelling_errors: false,
hide_grammar_errors: false,
odf: None,
}
}
+17
View File
@@ -4781,3 +4781,20 @@ fn vml_horizontal_rules_are_read_and_kept() {
let d = read_body(&body);
assert_eq!(rules(&d).iter().map(|r| r.0).collect::<Vec<_>>(), [None, None]);
}
#[test]
fn hide_spelling_and_grammar_errors_survive_a_save() {
let settings_xml = |d: &Document| {
let bytes = wordcraft_docx::write(d).unwrap();
let mut z = craft_zip::Archive::open(&bytes, craft_zip::Limits { max_entries: 10_000, max_total_bytes: 64 << 20 }).unwrap();
String::from_utf8(z.read("word/settings.xml", 16 << 20).unwrap().unwrap()).unwrap()
};
let d = with_settings(Some("<w:hideSpellingErrors/><w:hideGrammaticalErrors/>"));
let saved = settings_xml(&d);
assert!(saved.contains("<w:hideSpellingErrors") && saved.contains("<w:hideGrammaticalErrors"), "{saved}");
let again = wordcraft_docx::read(&wordcraft_docx::write(&d).unwrap()).unwrap();
let saved = settings_xml(&again);
assert!(saved.contains("<w:hideSpellingErrors") && saved.contains("<w:hideGrammaticalErrors"), "second save: {saved}");
let plain = settings_xml(&with_settings(Some("")));
assert!(!plain.contains("hideSpellingErrors") && !plain.contains("hideGrammaticalErrors"), "not invented: {plain}");
}
@@ -37,7 +37,7 @@ fn section_metadata_survives_native_json_and_two_docx_save_reopen_cycles() {
assert!(xml.contains(r#"<w15:footnoteColumns w:val="3"/>"#), "cycle {cycle}: {xml}");
assert!(xml.contains(r#"w:chapStyle="1" w:chapSep="hyphen""#), "cycle {cycle}: {xml}");
assert!(xml.contains(r#"w:chapStyle="10" w:chapSep="colon""#), "cycle {cycle}: {xml}");
assert!(xml.contains("xmlns:w15=") && xml.contains("mc:Ignorable=\"w14 w15 w16du wp14\""), "cycle {cycle}: {xml}");
assert!(xml.contains("xmlns:w15=") && xml.contains("mc:Ignorable=\"w14 w15 wp14 w16du\""), "cycle {cycle}: {xml}");
document = wordcraft_docx::read(&bytes).unwrap();
let json = serde_json::to_vec(&document).unwrap();
document = serde_json::from_slice(&json).unwrap();