hwp2md 0.4.0

HWP/HWPX ↔ Markdown bidirectional converter
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
use super::*;

// ── Phase A-2: List writer — bullet / numbering markup ────────────────────
//
// These tests verify that Block::List items are emitted as OWPML paragraphs
// carrying `numPrIDRef` (numbering definition reference) and a list-specific
// `paraPrIDRef` (paragraph property reference for left-indentation), and that
// the header.xml contains the matching `<hh:numberingList>` definitions.

// ── Header: numberingList definitions ───────────────────────────────────────

/// header.xml must contain a `<hh:numberings>` element with exactly one
/// numbering definition (id=1 for ordered/digit lists).
///
/// Unordered (bullet) lists do not use a `<hh:numbering>` entry in the
/// OWPML schema because `numFormat="BULLET"` is not a valid enum value;
/// instead bullet-list paragraphs rely on the paragraph-property indent alone.
#[test]
fn header_xml_contains_numbering_list() {
    let doc = doc_with_section(vec![Block::List {
        ordered: false,
        start: 1,
        items: vec![ListItem {
            blocks: vec![Block::Paragraph {
                inlines: vec![inline("item")],
            }],
            children: vec![],
        }],
    }]);
    let tables = RefTables::build(&doc);
    let header =
        super::header::generate_header_xml(&doc, &tables).expect("generate_header_xml failed");

    assert!(
        header.contains("<hh:numberings"),
        "header.xml must contain <hh:numberings>:\n{header}"
    );
    assert!(
        header.contains("</hh:numberings>"),
        "header.xml must close </hh:numberings>:\n{header}"
    );
    assert!(
        header.contains(r#"<hh:numberings itemCnt="1""#),
        "numberings must have itemCnt=\"1\" (ordered only):\n{header}"
    );
}

/// header.xml must always contain the numbering definitions even when the
/// document contains no lists (definitions are emitted unconditionally).
#[test]
fn header_xml_numbering_list_always_present() {
    let doc = doc_with_section(vec![Block::Paragraph {
        inlines: vec![inline("no lists here")],
    }]);
    let tables = RefTables::build(&doc);
    let header =
        super::header::generate_header_xml(&doc, &tables).expect("generate_header_xml failed");

    assert!(
        header.contains("<hh:numberings"),
        "numberings must appear even in documents without lists:\n{header}"
    );
}

/// header.xml must have exactly one `<hh:numbering>` (id=1, DIGIT) since the
/// OWPML schema does not support `numFormat="BULLET"` in `<hh:numberings>`.
/// Unordered (bullet) lists emit paragraphs without a `numPrIDRef` attribute.
#[test]
fn header_xml_numbering_id1_is_bullet() {
    let doc = doc_with_section(vec![]);
    let tables = RefTables::build(&doc);
    let header =
        super::header::generate_header_xml(&doc, &tables).expect("generate_header_xml failed");

    // id=1 must be the DIGIT (ordered) numbering — bullet uses no numbering entry.
    let id1_pos = header
        .find(r#"<hh:numbering id="1""#)
        .expect("numbering id=1 must exist");

    // id=2 must NOT exist (only one numbering definition).
    assert!(
        !header.contains(r#"<hh:numbering id="2""#),
        "numbering id=2 must NOT exist; only one entry is registered:\n{header}"
    );

    let slice_id1 = &header[id1_pos..];
    assert!(
        slice_id1.contains(r#"numFormat="DIGIT""#),
        "numbering id=1 must have numFormat=\"DIGIT\":\n{slice_id1}"
    );
    assert!(
        slice_id1.contains("%d."),
        "numbering id=1 must contain \"%d.\" format string:\n{slice_id1}"
    );
}

/// header.xml must have the digit numbering (id=1) — the single registered
/// `<hh:numbering>` entry used for ordered lists.
///
/// The old "id=2" (digit) test is renamed to reflect the new numbering scheme
/// where ordered lists use id=1 (the only registered numbering).
#[test]
fn header_xml_numbering_id2_is_digit() {
    let doc = doc_with_section(vec![]);
    let tables = RefTables::build(&doc);
    let header =
        super::header::generate_header_xml(&doc, &tables).expect("generate_header_xml failed");

    // Only id=1 (DIGIT) is registered now.
    let id1_pos = header
        .find(r#"<hh:numbering id="1""#)
        .expect("numbering id=1 (DIGIT) must exist");

    let slice_id1 = &header[id1_pos..];
    assert!(
        slice_id1.contains(r#"numFormat="DIGIT""#),
        "numbering id=1 must have numFormat=\"DIGIT\":\n{slice_id1}"
    );
    assert!(
        slice_id1.contains("%d."),
        "numbering id=1 must contain \"%d.\" format string:\n{slice_id1}"
    );
}

/// header.xml paraProperties must have itemCnt="5" (id=0 default, id=1 blockquote,
/// id=2 list-depth-0, id=3 list-depth-1+, id=4 heading).
#[test]
fn header_xml_para_properties_has_four_entries() {
    let doc = doc_with_section(vec![]);
    let tables = RefTables::build(&doc);
    let header =
        super::header::generate_header_xml(&doc, &tables).expect("generate_header_xml failed");

    assert!(
        header.contains(r#"<hh:paraProperties itemCnt="5""#),
        "paraProperties must have itemCnt=\"5\":\n{header}"
    );
    // All five IDs must be present.
    assert!(
        header.contains(r#"<hh:paraPr id="0""#),
        "paraPr id=0 must exist:\n{header}"
    );
    assert!(
        header.contains(r#"<hh:paraPr id="1""#),
        "paraPr id=1 must exist:\n{header}"
    );
    assert!(
        header.contains(r#"<hh:paraPr id="2""#),
        "paraPr id=2 must exist:\n{header}"
    );
    assert!(
        header.contains(r#"<hh:paraPr id="3""#),
        "paraPr id=3 must exist:\n{header}"
    );
    assert!(
        header.contains(r#"<hh:paraPr id="4""#),
        "paraPr id=4 (heading) must exist:\n{header}"
    );
}

// ── Section XML: unordered list ──────────────────────────────────────────────

/// An unordered list item paragraph must NOT carry a `numPrIDRef` attribute
/// because `numFormat="BULLET"` is not valid in the OWPML schema.
/// Indentation is conveyed via `paraPrIDRef` alone.
#[test]
fn section_xml_unordered_list_item_has_num_pr_id_ref_1() {
    let xml = section_xml(vec![Block::List {
        ordered: false,
        start: 1,
        items: vec![ListItem {
            blocks: vec![Block::Paragraph {
                inlines: vec![inline("bullet item")],
            }],
            children: vec![],
        }],
    }]);
    assert!(
        !xml.contains("numPrIDRef"),
        "unordered list item must NOT have a numPrIDRef attribute (no BULLET numbering):\n{xml}"
    );
    assert!(
        xml.contains("bullet item"),
        "item text must be present: {xml}"
    );
}

/// An unordered list item must use `paraPrIDRef="2"` (list-depth-0 indent).
#[test]
fn section_xml_unordered_list_item_has_para_pr_id_ref_2() {
    let xml = section_xml(vec![Block::List {
        ordered: false,
        start: 1,
        items: vec![ListItem {
            blocks: vec![Block::Paragraph {
                inlines: vec![inline("bullet")],
            }],
            children: vec![],
        }],
    }]);
    assert!(
        xml.contains(r#"paraPrIDRef="2""#),
        "unordered list item must have paraPrIDRef=\"2\":\n{xml}"
    );
    // Must NOT use the default paragraph style.
    assert!(
        !xml.contains(r#"paraPrIDRef="0""#),
        "list item must NOT use paraPrIDRef=\"0\":\n{xml}"
    );
}

/// Multiple unordered list items must each NOT carry a `numPrIDRef` attribute
/// because the OWPML schema has no valid bullet numFormat.
#[test]
fn section_xml_multiple_unordered_items_all_have_num_pr_id_ref_1() {
    let xml = section_xml(vec![Block::List {
        ordered: false,
        start: 1,
        items: vec![
            ListItem {
                blocks: vec![Block::Paragraph {
                    inlines: vec![inline("alpha")],
                }],
                children: vec![],
            },
            ListItem {
                blocks: vec![Block::Paragraph {
                    inlines: vec![inline("beta")],
                }],
                children: vec![],
            },
            ListItem {
                blocks: vec![Block::Paragraph {
                    inlines: vec![inline("gamma")],
                }],
                children: vec![],
            },
        ],
    }]);
    assert!(
        !xml.contains("numPrIDRef"),
        "unordered list items must NOT carry numPrIDRef (no BULLET numbering): {xml}"
    );
    assert!(xml.contains("alpha"), "{xml}");
    assert!(xml.contains("beta"), "{xml}");
    assert!(xml.contains("gamma"), "{xml}");
}

// ── Section XML: ordered list ─────────────────────────────────────────────────

/// An ordered list item paragraph must carry `numPrIDRef="1"` (digit, the
/// sole registered numbering definition in the OWPML schema).
#[test]
fn section_xml_ordered_list_item_has_num_pr_id_ref_2() {
    let xml = section_xml(vec![Block::List {
        ordered: true,
        start: 1,
        items: vec![ListItem {
            blocks: vec![Block::Paragraph {
                inlines: vec![inline("first")],
            }],
            children: vec![],
        }],
    }]);
    assert!(
        xml.contains(r#"numPrIDRef="1""#),
        "ordered list item must have numPrIDRef=\"1\" (DIGIT, id=1):\n{xml}"
    );
    assert!(xml.contains("first"), "item text must be present: {xml}");
}

/// An ordered list item must use `paraPrIDRef="2"` (list-depth-0 indent).
#[test]
fn section_xml_ordered_list_item_has_para_pr_id_ref_2() {
    let xml = section_xml(vec![Block::List {
        ordered: true,
        start: 1,
        items: vec![ListItem {
            blocks: vec![Block::Paragraph {
                inlines: vec![inline("numbered")],
            }],
            children: vec![],
        }],
    }]);
    assert!(
        xml.contains(r#"paraPrIDRef="2""#),
        "ordered list item must have paraPrIDRef=\"2\":\n{xml}"
    );
}

/// Multiple ordered list items must each carry `numPrIDRef="1"` (DIGIT, id=1).
#[test]
fn section_xml_multiple_ordered_items_all_have_num_pr_id_ref_2() {
    let xml = section_xml(vec![Block::List {
        ordered: true,
        start: 1,
        items: vec![
            ListItem {
                blocks: vec![Block::Paragraph {
                    inlines: vec![inline("one")],
                }],
                children: vec![],
            },
            ListItem {
                blocks: vec![Block::Paragraph {
                    inlines: vec![inline("two")],
                }],
                children: vec![],
            },
        ],
    }]);
    let count = xml.matches(r#"numPrIDRef="1""#).count();
    assert_eq!(
        count, 2,
        "two ordered list items must each have numPrIDRef=\"1\"; found {count}: {xml}"
    );
}

// ── numPrIDRef distinction ───────────────────────────────────────────────────

/// Ordered and unordered lists must be distinguishable in the XML output.
/// Ordered: carries `numPrIDRef="1"` (DIGIT, id=1).
/// Unordered: carries NO `numPrIDRef` (BULLET not valid in OWPML schema).
#[test]
fn section_xml_ordered_and_unordered_use_different_num_pr_id_refs() {
    // Ordered list in the same document as unordered list.
    let xml = section_xml(vec![
        Block::List {
            ordered: false,
            start: 1,
            items: vec![ListItem {
                blocks: vec![Block::Paragraph {
                    inlines: vec![inline("bullet")],
                }],
                children: vec![],
            }],
        },
        Block::List {
            ordered: true,
            start: 1,
            items: vec![ListItem {
                blocks: vec![Block::Paragraph {
                    inlines: vec![inline("number")],
                }],
                children: vec![],
            }],
        },
    ]);
    // Ordered list item uses numPrIDRef="1" (DIGIT).
    assert!(
        xml.contains(r#"numPrIDRef="1""#),
        "ordered list item numPrIDRef=\"1\" must appear:\n{xml}"
    );
    // Both items must have their text.
    assert!(
        xml.contains("bullet"),
        "unordered text 'bullet' must appear: {xml}"
    );
    assert!(
        xml.contains("number"),
        "ordered text 'number' must appear: {xml}"
    );
}

// ── Paragraph count ────────────────────────────────────────────────────────

/// Each list item produces exactly one `<hp:p>` paragraph.
#[test]
fn section_xml_list_items_produce_correct_paragraph_count() {
    let xml = section_xml(vec![Block::List {
        ordered: false,
        start: 1,
        items: vec![
            ListItem {
                blocks: vec![Block::Paragraph {
                    inlines: vec![inline("a")],
                }],
                children: vec![],
            },
            ListItem {
                blocks: vec![Block::Paragraph {
                    inlines: vec![inline("b")],
                }],
                children: vec![],
            },
            ListItem {
                blocks: vec![Block::Paragraph {
                    inlines: vec![inline("c")],
                }],
                children: vec![],
            },
        ],
    }]);
    let p_count = xml.matches("<hp:p ").count();
    assert_eq!(
        p_count, 3,
        "three list items must produce three <hp:p> elements; found {p_count}: {xml}"
    );
}

// ── Edge cases ─────────────────────────────────────────────────────────────

/// An empty list (no items) produces no paragraph elements.
#[test]
fn section_xml_empty_list_produces_no_paragraphs() {
    let xml = section_xml(vec![Block::List {
        ordered: false,
        start: 1,
        items: vec![],
    }]);
    // The section wrapper is present but no <hp:p> elements inside.
    assert!(
        !xml.contains("<hp:p "),
        "empty list must produce no <hp:p> elements:\n{xml}"
    );
}

/// A list item with bold inline text retains the inline charPr formatting
/// attribute. Unordered items have NO numPrIDRef (bullet not valid in OWPML).
#[test]
fn section_xml_list_item_with_bold_inline_has_both_num_pr_and_charpr() {
    let xml = section_xml(vec![Block::List {
        ordered: false,
        start: 1,
        items: vec![ListItem {
            blocks: vec![Block::Paragraph {
                inlines: vec![bold_inline("important")],
            }],
            children: vec![],
        }],
    }]);
    assert!(
        !xml.contains("numPrIDRef"),
        "unordered bold list item must NOT have numPrIDRef (no BULLET numbering):\n{xml}"
    );
    assert!(
        xml.contains(r#"bold="true""#),
        "bold attribute must be present on inline charPr:\n{xml}"
    );
    assert!(
        xml.contains("important"),
        "text content must be present: {xml}"
    );
}

/// A list item with no inline content (empty paragraph) is emitted without error.
#[test]
fn section_xml_list_item_empty_paragraph_no_panic() {
    let xml = section_xml(vec![Block::List {
        ordered: true,
        start: 1,
        items: vec![ListItem {
            blocks: vec![Block::Paragraph { inlines: vec![] }],
            children: vec![],
        }],
    }]);
    assert!(
        xml.contains(r#"numPrIDRef="1""#),
        "empty paragraph ordered list item must have numPrIDRef=\"1\" (DIGIT):\n{xml}"
    );
    assert!(
        xml.contains("<hp:p "),
        "paragraph element must be emitted: {xml}"
    );
}

// ── Nested lists (ListItem.children) ─────────────────────────────────────────

/// A list item with children emits both the parent item and child items,
/// with child items using paraPrIDRef="3" (depth-1 indent).
#[test]
fn section_xml_nested_list_via_children_uses_para_pr_id_ref_3() {
    let xml = section_xml(vec![Block::List {
        ordered: false,
        start: 1,
        items: vec![ListItem {
            blocks: vec![Block::Paragraph {
                inlines: vec![inline("parent item")],
            }],
            children: vec![ListItem {
                blocks: vec![Block::Paragraph {
                    inlines: vec![inline("child item")],
                }],
                children: vec![],
            }],
        }],
    }]);
    assert!(xml.contains("parent item"), "parent item text: {xml}");
    assert!(xml.contains("child item"), "child item text: {xml}");
    // Parent item: paraPrIDRef="2" (depth=0)
    assert!(
        xml.contains(r#"paraPrIDRef="2""#),
        "parent item must have paraPrIDRef=\"2\":\n{xml}"
    );
    // Child item: paraPrIDRef="3" (depth=1)
    assert!(
        xml.contains(r#"paraPrIDRef="3""#),
        "child item must have paraPrIDRef=\"3\":\n{xml}"
    );
}

/// A nested `Block::List` inside a list item (via item.blocks) uses
/// paraPrIDRef="3" for its paragraphs.
#[test]
fn section_xml_nested_block_list_inside_item_uses_para_pr_id_ref_3() {
    let xml = section_xml(vec![Block::List {
        ordered: false,
        start: 1,
        items: vec![ListItem {
            blocks: vec![
                Block::Paragraph {
                    inlines: vec![inline("outer item")],
                },
                // Nested list as a block inside the item.
                Block::List {
                    ordered: true,
                    start: 1,
                    items: vec![ListItem {
                        blocks: vec![Block::Paragraph {
                            inlines: vec![inline("inner item")],
                        }],
                        children: vec![],
                    }],
                },
            ],
            children: vec![],
        }],
    }]);
    assert!(xml.contains("outer item"), "outer item text: {xml}");
    assert!(xml.contains("inner item"), "inner item text: {xml}");
    // Inner list items must be at depth=1, using paraPrIDRef="3".
    assert!(
        xml.contains(r#"paraPrIDRef="3""#),
        "nested block list items must have paraPrIDRef=\"3\":\n{xml}"
    );
}

// ── Paragraph ID counter continuity ─────────────────────────────────────────

/// Paragraph IDs across list items must be sequential and continue the
/// section-level counter correctly.
#[test]
fn section_xml_list_paragraph_ids_are_sequential() {
    let xml = section_xml(vec![Block::List {
        ordered: false,
        start: 1,
        items: vec![
            ListItem {
                blocks: vec![Block::Paragraph {
                    inlines: vec![inline("item 0")],
                }],
                children: vec![],
            },
            ListItem {
                blocks: vec![Block::Paragraph {
                    inlines: vec![inline("item 1")],
                }],
                children: vec![],
            },
        ],
    }]);
    assert!(
        xml.contains(r#"id="0""#),
        "first list paragraph must be id=0: {xml}"
    );
    assert!(
        xml.contains(r#"id="1""#),
        "second list paragraph must be id=1: {xml}"
    );
}

/// When a list follows other blocks, the list paragraph IDs continue from
/// where the preceding blocks left off.
#[test]
fn section_xml_list_paragraph_ids_continue_after_preceding_blocks() {
    let xml = section_xml(vec![
        Block::Paragraph {
            inlines: vec![inline("before")],
        },
        Block::List {
            ordered: false,
            start: 1,
            items: vec![ListItem {
                blocks: vec![Block::Paragraph {
                    inlines: vec![inline("list item")],
                }],
                children: vec![],
            }],
        },
    ]);
    // Paragraph "before" gets id=0; list item gets id=1.
    assert!(
        xml.contains(r#"id="0""#),
        "normal paragraph must be id=0: {xml}"
    );
    assert!(xml.contains(r#"id="1""#), "list item must be id=1: {xml}");
}

// ── Roundtrip: list content survives MD → HWPX ──────────────────────────────

/// An ordered list survives the write path: the text content of each item
/// is present in the HWPX section XML.
#[test]
fn roundtrip_ordered_list_text_preserved_in_hwpx() {
    let tmp = tempfile::NamedTempFile::new().expect("tmp file");
    let doc = Document {
        metadata: Metadata::default(),
        sections: vec![Section {
            blocks: vec![Block::List {
                ordered: true,
                start: 1,
                items: vec![
                    ListItem {
                        blocks: vec![Block::Paragraph {
                            inlines: vec![inline("step one")],
                        }],
                        children: vec![],
                    },
                    ListItem {
                        blocks: vec![Block::Paragraph {
                            inlines: vec![inline("step two")],
                        }],
                        children: vec![],
                    },
                ],
            }],

            page_layout: None,
        }],
        assets: Vec::new(),
    };
    write_hwpx(&doc, tmp.path(), None).expect("write_hwpx");

    // Read back the section XML from the HWPX ZIP.
    let file = std::fs::File::open(tmp.path()).expect("open zip");
    let mut archive = zip::ZipArchive::new(file).expect("parse zip");
    let mut entry = archive
        .by_name("Contents/section0.xml")
        .expect("section0.xml must exist");
    let mut xml = String::new();
    std::io::Read::read_to_string(&mut entry, &mut xml).expect("read section0.xml");

    assert!(
        xml.contains("step one"),
        "ordered list item 'step one' must survive write: {xml}"
    );
    assert!(
        xml.contains("step two"),
        "ordered list item 'step two' must survive write: {xml}"
    );
    assert!(
        xml.contains(r#"numPrIDRef="1""#),
        "ordered list items must have numPrIDRef=\"1\" (DIGIT, id=1) in HWPX: {xml}"
    );
}

/// An unordered list survives the write path with bullet numPrIDRef.
#[test]
fn roundtrip_unordered_list_text_preserved_in_hwpx() {
    let tmp = tempfile::NamedTempFile::new().expect("tmp file");
    let doc = Document {
        metadata: Metadata::default(),
        sections: vec![Section {
            blocks: vec![Block::List {
                ordered: false,
                start: 1,
                items: vec![
                    ListItem {
                        blocks: vec![Block::Paragraph {
                            inlines: vec![inline("alpha")],
                        }],
                        children: vec![],
                    },
                    ListItem {
                        blocks: vec![Block::Paragraph {
                            inlines: vec![inline("beta")],
                        }],
                        children: vec![],
                    },
                ],
            }],

            page_layout: None,
        }],
        assets: Vec::new(),
    };
    write_hwpx(&doc, tmp.path(), None).expect("write_hwpx");

    let file = std::fs::File::open(tmp.path()).expect("open zip");
    let mut archive = zip::ZipArchive::new(file).expect("parse zip");
    let mut entry = archive
        .by_name("Contents/section0.xml")
        .expect("section0.xml must exist");
    let mut xml = String::new();
    std::io::Read::read_to_string(&mut entry, &mut xml).expect("read section0.xml");

    assert!(
        xml.contains("alpha"),
        "unordered item 'alpha' must survive: {xml}"
    );
    assert!(
        xml.contains("beta"),
        "unordered item 'beta' must survive: {xml}"
    );
    assert!(
        !xml.contains("numPrIDRef"),
        "unordered list items must NOT carry numPrIDRef in HWPX (no BULLET numbering): {xml}"
    );
}

/// header.xml in the HWPX ZIP must contain the numberingList element.
#[test]
fn roundtrip_header_xml_contains_numbering_list() {
    let tmp = tempfile::NamedTempFile::new().expect("tmp file");
    let doc = Document {
        metadata: Metadata::default(),
        sections: vec![Section {
            blocks: vec![Block::List {
                ordered: false,
                start: 1,
                items: vec![ListItem {
                    blocks: vec![Block::Paragraph {
                        inlines: vec![inline("item")],
                    }],
                    children: vec![],
                }],
            }],

            page_layout: None,
        }],
        assets: Vec::new(),
    };
    write_hwpx(&doc, tmp.path(), None).expect("write_hwpx");

    let file = std::fs::File::open(tmp.path()).expect("open zip");
    let mut archive = zip::ZipArchive::new(file).expect("parse zip");
    let mut entry = archive
        .by_name("Contents/header.xml")
        .expect("header.xml must exist");
    let mut header = String::new();
    std::io::Read::read_to_string(&mut entry, &mut header).expect("read header.xml");

    assert!(
        header.contains("<hh:numberings"),
        "header.xml in HWPX must contain <hh:numberings>:\n{header}"
    );
    // Only DIGIT numbering is registered; BULLET is not a valid OWPML numFormat.
    assert!(
        !header.contains(r#"numFormat="BULLET""#),
        "header.xml must NOT contain BULLET numbering (invalid in OWPML schema):\n{header}"
    );
    assert!(
        header.contains(r#"numFormat="DIGIT""#),
        "header.xml must contain DIGIT numbering:\n{header}"
    );
}