Fix annotation projection on sanitized HTML fragments#111
Merged
Conversation
…ts (#110) XElement.Parse() requires valid XML with a single root element, but sanitized HTML (e.g., DOMPurify output) strips <html>/<body> wrappers, leaving multiple top-level elements. Also handle HTML named entities ( , –, etc.) that are invalid in XML. https://claude.ai/code/session_01B3Yy9hY9o3iUBf5KD8wXUP
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes annotation projection methods to handle HTML fragments with multiple root elements and HTML named entities, which are common in sanitized HTML output from libraries like DOMPurify.
Key Changes
HTML Fragment Parsing: Added
ParseHtmlString()method that: ,–, etc.) with numeric XML equivalents for XML compatibility<docxodus-fragment-root>element to satisfyXElement.Parse()requirementsHTML Serialization: Added
SerializeHtmlString()method that:Updated Methods: Modified three public methods to use the new parsing/serialization:
ProjectAnnotationsOntoHtml()AddAnnotationToHtml()RemoveAnnotationFromHtml()Comprehensive Tests: Added 6 new test cases covering:
specifically)Implementation Details
https://claude.ai/code/session_01B3Yy9hY9o3iUBf5KD8wXUP