Skip to content

Reader HTML: Support a table inside a list item - #2983

Open
APX403 wants to merge 1 commit into
PHPOffice:masterfrom
APX403:fix-table-in-list-item
Open

APX403 wants to merge 1 commit into
PHPOffice:masterfrom
APX403:fix-table-in-list-item

Conversation

@APX403

@APX403 APX403 commented Dec 1, 2026

Copy link
Copy Markdown

Description

A <table> inside a <li>, which rich text editors such as TinyMCE produce, makes Html::addHtml() throw:

BadMethodCallException: Cannot add Table in ListItemRun.

The children of a <li> are added to its ListItemRun, which is a paragraph and cannot hold a table. The table is now added to the container of the list item, right after it, the way parseList() already adds a list nested in a <li>. With the HTML of the issue:

Html::addHtml($section, '<ul><li>I am a bullet</li><li><table><tr><td>I am a cell</td></tr></table></li><li>I am a bullet</li></ul>');

the document gets the first bullet, an empty bullet followed by the table, then the last bullet, which continues the same list. When the list is in a table cell, the table goes into that cell.

Fixes #1466

Checklist:

  • My CI is 🟢
  • I have covered by unit tests my new code (check build/coverage for coverage report)
  • I have updated the documentation to describe the changes
  • I have updated the changelog

A <table> in a <li>, which rich text editors produce, made
Html::addHtml() throw "Cannot add Table in ListItemRun": the children
of a <li> are added to its ListItemRun, and a run cannot hold a table.
The table is now added to the container of the list item, right after
it, the way a nested list already is.
@coveralls

Copy link
Copy Markdown

Coverage Status

coverage: 96.583% (+0.001%) from 96.582% — APX403:fix-table-in-list-item into PHPOffice:master

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

Tables inside a bullet list result in a corrupt docx file

2 participants