Skip to content

Conversation

@stesee
Copy link
Collaborator

@stesee stesee commented Jan 22, 2026

  • DocumentAssembler
    • only add paragraph when no other block-level elements exist in the table cell
    • fix bug where conditionals can leave a table cell in an invalid state, causing Word to report an error.
    • emulate Word's whitespace handling and treatment of xml:space="preserve"
    • avoid spurious error and crash on
  • UnicodeMapper
    • more comprehensive fix for whitespace handling in UnicodeMapper

dependabot bot and others added 12 commits January 14, 2026 13:09
---
updated-dependencies:
- dependency-name: System.Configuration.ConfigurationManager
  dependency-version: 10.0.2
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
…erToolsExamples/MarkupSimplifierApp/System.Configuration.ConfigurationManager-10.0.2

Bump System.Configuration.ConfigurationManager from 10.0.1 to 10.0.2
…val="0" /></numPr>

It seems DocumentBuilder was originally written to handle <numPr id="0" />, which is non-standard AFAIK. I've left that in there, but now handle the proper way to designate numId="0" as well.
Fix completely empty table cells causing Word errors
DocumentBuilder fix: avoid spurious error and crash on <numPr><numId val="0" /></numPr>
Fix whitespace handling in UnicodeMapper and DocumentAssembler
Copilot AI review requested due to automatic review settings January 22, 2026 10:34
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request implements important fixes to DocumentAssembler, UnicodeMapper, and DocumentBuilder for handling whitespace, table cells, and numbering definitions in OpenXML documents.

Changes:

  • Enhanced UnicodeMapper to properly emulate Word's whitespace handling and respect xml:space="preserve" attributes
  • Fixed DocumentAssembler to ensure table cells always contain valid block-level elements and to preserve leading/trailing whitespace
  • Fixed DocumentBuilder to handle numbering definitions with numId=0 (which indicates "no numbering") without crashing

Reviewed changes

Copilot reviewed 9 out of 15 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
OpenXmlPowerTools/UnicodeMapper.cs Adds NormalizeWhitespace method to properly handle whitespace in text elements based on xml:space attribute
OpenXmlPowerTools/DocumentAssembler/DocumentAssembler.cs Adds validation for table cells to ensure block-level content exists and adds GetXmlSpaceAttribute helper to preserve whitespace
OpenXmlPowerTools/DocumentBuilder/DocumentBuilder.cs Adds defensive handling for numbering elements with numId=0 to prevent crashes
OpenXmlPowerTools.Tests/UnicodeMapperTests.cs Adds comprehensive tests to verify whitespace handling matches Word's behavior
OpenXmlPowerTools.Tests/DocumentBuilderTests.cs Adds tests for handling documents with zero numbering IDs
OpenXmlPowerTools.Tests/DocumentAssemblerTests.cs Adds tests for conditional blocks in table cells and whitespace preservation
OpenXmlPowerToolsExamples/MarkupSimplifierApp/MarkupSimplifierApp.csproj Updates System.Configuration.ConfigurationManager to version 10.0.2
TestFiles/* Adds test documents for whitespace handling, numbering with zero ID, and conditional table cells

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +1419 to +1430
private static XAttribute GetXmlSpaceAttribute(string textOfTextElement)
{
if (!string.IsNullOrEmpty(textOfTextElement))
{
if (char.IsWhiteSpace(textOfTextElement[0]) ||
char.IsWhiteSpace(textOfTextElement[textOfTextElement.Length - 1]))
{
return new XAttribute(XNamespace.Xml + "space", "preserve");
}
}
return null;
}
Copy link

Copilot AI Jan 22, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The GetXmlSpaceAttribute method should return null explicitly when the condition is not met instead of relying on implicit null return. This makes the intent clearer and follows best practices for nullable return types.

Consider adding an explicit return null; statement after the closing brace of the if block for better code clarity.

Copilot uses AI. Check for mistakes.
Comment on lines +1421 to +1427
if (!string.IsNullOrEmpty(textOfTextElement))
{
if (char.IsWhiteSpace(textOfTextElement[0]) ||
char.IsWhiteSpace(textOfTextElement[textOfTextElement.Length - 1]))
{
return new XAttribute(XNamespace.Xml + "space", "preserve");
}
Copy link

Copilot AI Jan 22, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These 'if' statements can be combined.

Suggested change
if (!string.IsNullOrEmpty(textOfTextElement))
{
if (char.IsWhiteSpace(textOfTextElement[0]) ||
char.IsWhiteSpace(textOfTextElement[textOfTextElement.Length - 1]))
{
return new XAttribute(XNamespace.Xml + "space", "preserve");
}
if (!string.IsNullOrEmpty(textOfTextElement) &&
(char.IsWhiteSpace(textOfTextElement[0]) ||
char.IsWhiteSpace(textOfTextElement[textOfTextElement.Length - 1])))
{
return new XAttribute(XNamespace.Xml + "space", "preserve");

Copilot uses AI. Check for mistakes.
@stesee stesee merged commit c509b98 into release Jan 22, 2026
15 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators Jan 22, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants