Skip to content

Pass document_properties to table cell paragraphs so to_html works with hyperlinks (#160)#180

Merged
satoryu merged 1 commit into
masterfrom
fix-160-table-cell-hyperlinks
May 31, 2026
Merged

Pass document_properties to table cell paragraphs so to_html works with hyperlinks (#160)#180
satoryu merged 1 commit into
masterfrom
fix-160-table-cell-hyperlinks

Conversation

@satoryu
Copy link
Copy Markdown
Member

@satoryu satoryu commented May 31, 2026

Summary

Fixes #160. Calling to_html on a paragraph inside a table cell that contains a hyperlink no longer raises.

The bug

TableCell#paragraphs built Paragraph objects without document_properties, so each paragraph's @document_properties defaulted to {}. When such a paragraph contained a hyperlink, TextRun#href evaluated @document_properties[:hyperlinks][hyperlink_id] — and [:hyperlinks] was nil:

doc.tables[0].rows[0].cells[0].paragraphs.map(&:to_html)
# => NoMethodError: undefined method '[]' for nil

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 via parse_paragraph_from:

Document#parse_table_fromTableTableRow / TableColumnTableCellParagraph

All new constructor arguments are optional (document_properties = {}, doc = nil), so existing direct instantiations keep working. As a bonus, paragraph style now resolves inside table cells too (it needs the document reference).

Tests

  • New regression spec renders html for tables.docx's cell [0].rows[1].cells[1], which links to http://google.com/, asserting it does not raise and the output contains <a href="http://google.com/".
  • Confirmed it fails on master (NoMethodError) and passes with this change. Full suite green locally (152 examples, 0 failures).

Closes #160

🤖 Generated with Claude Code

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>
@satoryu satoryu merged commit a74e2cf into master May 31, 2026
6 checks passed
@satoryu satoryu deleted the fix-160-table-cell-hyperlinks branch May 31, 2026 15:03
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.

Can not call to_html on paragraphs in table cells if they contain hyper links

1 participant