-
Notifications
You must be signed in to change notification settings - Fork 16
DocumentAssembler fixes #186
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
--- 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.
…, causing Word to report an error.
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
There was a problem hiding this 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.
| 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; | ||
| } |
Copilot
AI
Jan 22, 2026
There was a problem hiding this comment.
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.
| if (!string.IsNullOrEmpty(textOfTextElement)) | ||
| { | ||
| if (char.IsWhiteSpace(textOfTextElement[0]) || | ||
| char.IsWhiteSpace(textOfTextElement[textOfTextElement.Length - 1])) | ||
| { | ||
| return new XAttribute(XNamespace.Xml + "space", "preserve"); | ||
| } |
Copilot
AI
Jan 22, 2026
There was a problem hiding this comment.
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.
| 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"); |
Uh oh!
There was an error while loading. Please reload this page.