Skip to content

fix(comparer): preserve legal numbering when comparing documents#75

Merged
JSv4 merged 4 commits intomainfrom
fix/legal-numbering-issue-1634
Dec 6, 2025
Merged

fix(comparer): preserve legal numbering when comparing documents#75
JSv4 merged 4 commits intomainfrom
fix/legal-numbering-issue-1634

Conversation

@JSv4
Copy link
Copy Markdown
Owner

@JSv4 JSv4 commented Dec 6, 2025

Summary

  • Fixes legal numbering (w:isLgl) being lost when comparing Word documents where one has legal numbering and the other doesn't
  • Added CopyMissingNumberingFromOneDocToAnother method that copies missing numbering definitions from the revised document to the comparison result
  • Handles ID conflicts by assigning new IDs when numbering definitions differ

Background

This addresses the issue reported in dotnet/Open-XML-SDK#1634. When comparing documents:

  • Document 1 (original): Normal numbering
  • Document 2 (revised): Legal numbering style (w:isLgl)

The comparison result was losing the legal numbering entirely because:

  1. Result document starts as a copy of source1 (original)
  2. Styles were copied from source2 via CopyMissingStylesFromOneDocToAnother
  3. But numbering definitions were NOT copied

Test plan

  • Added 5 new test cases in WmlComparerLegalNumberingTests.cs:
    • WC_LegalNum_001: Original has legal numbering, revised doesn't → preserves legal
    • WC_LegalNum_002: Revised has legal numbering, original doesn't → now preserves legal (was failing)
    • WC_LegalNum_003: Both have legal numbering → preserves legal
    • WC_LegalNum_004: Multi-level numbering scenario → now preserves legal (was failing)
    • WC_LegalNum_005: Different numIds with legal numbering → merges correctly
  • All 1122 existing tests pass (no regressions)
  • All 38 WmlComparer tests pass

JSv4 added 4 commits December 6, 2025 00:01
When comparing Word documents where one has legal numbering (w:isLgl)
and the other doesn't, the comparison result was losing the legal
numbering definitions entirely.

Root cause: The result document starts as a copy of source1, and while
styles were copied from source2 via CopyMissingStylesFromOneDocToAnother,
there was no equivalent for numbering definitions.

Fix: Added CopyMissingNumberingFromOneDocToAnother that:
- Copies missing w:abstractNum elements from revised to result
- Copies missing w:num elements with proper abstractNumId remapping
- Handles ID conflicts by assigning new IDs when definitions differ
- Compares by content (not just ID) to detect different definitions

Fixes: dotnet/Open-XML-SDK#1634
…ring merge

- Add null-safe GetIntAttribute helper for robust attribute extraction
- Check for matching abstractNum content across ALL destination elements
  (not just by ID) to avoid duplicate definitions
- Use explicit PutXDocument(toNumberingXDoc) for clarity
- Add null-checks when setting abstractNumId element values
- Improve code comments for maintainability
- Update main README.md:
  - Fix installation instructions (NuGet, not GitHub Packages)
  - Update repository URLs from JSv4/Redlines to JSv4/Docxodus
  - Add format change detection to features
  - Expand HTML converter features (comments, pagination, headers/footers)
  - Add OpenContractExporter to features list
  - Update npm example with new APIs (metadata, format changes)
  - Update test count (~1,100)

- Update npm/README.md:
  - Add new features (move detection, format changes, pagination, etc.)
  - Update RevisionType enum with Moved and FormatChanged
  - Add getDocumentMetadata and exportToOpenContract API docs
  - Add Web Worker API section
  - Add additional React hooks (useAnnotations, useDocumentStructure)
  - Expand ConversionOptions with new properties
  - Fix credits URL

- Update tools READMEs:
  - Add environment variable documentation (DEBUG flags)
  - Remove outdated limitation (headers/footers now supported)
  - Fix license URLs to JSv4/Docxodus

- Fix repository URLs in all .csproj files:
  - Docxodus/Docxodus.csproj
  - tools/redline/redline.csproj
  - tools/docx2html/docx2html.csproj
  - tools/docx2oc/docx2oc.csproj
@JSv4 JSv4 merged commit 8058c20 into main Dec 6, 2025
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant