Pass document_properties to table cell paragraphs so to_html works with hyperlinks (#160)#180
Merged
Merged
Conversation
Paragraphs inside table cells were built without document_properties, so
@document_properties defaulted to {}. Calling to_html on a cell paragraph
that contained a hyperlink then crashed in TextRun#href with
"undefined method '[]' for nil" (document_properties[:hyperlinks] was nil).
Thread document_properties and the document through Table -> Row/Column ->
Cell -> Paragraph (all new arguments are optional for backward compatibility),
mirroring how body paragraphs are built. As a bonus, paragraph styles now
resolve inside table cells too.
Adds a regression spec rendering html for a cell containing a hyperlink.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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 #160. Calling
to_htmlon a paragraph inside a table cell that contains a hyperlink no longer raises.The bug
TableCell#paragraphsbuiltParagraphobjects withoutdocument_properties, so each paragraph's@document_propertiesdefaulted to{}. When such a paragraph contained a hyperlink,TextRun#hrefevaluated@document_properties[:hyperlinks][hyperlink_id]— and[:hyperlinks]wasnil:The root cause was identified by the reporter (@perryn): table cells had no access to
document_properties.The fix
Thread
document_properties(and the owning document) down through the table containers, mirroring how body paragraphs are built viaparse_paragraph_from:Document#parse_table_from→Table→TableRow/TableColumn→TableCell→ParagraphAll new constructor arguments are optional (
document_properties = {},doc = nil), so existing direct instantiations keep working. As a bonus, paragraphstylenow resolves inside table cells too (it needs the document reference).Tests
tables.docx's cell[0].rows[1].cells[1], which links tohttp://google.com/, asserting it does not raise and the output contains<a href="http://google.com/".master(NoMethodError) and passes with this change. Full suite green locally (152 examples, 0 failures).Closes #160
🤖 Generated with Claude Code