fix: restore double-newline row boundaries in Table.text (#4235)#4299
Open
alvinttang wants to merge 1 commit intoUnstructured-IO:mainfrom
Open
fix: restore double-newline row boundaries in Table.text (#4235)#4299alvinttang wants to merge 1 commit intoUnstructured-IO:mainfrom
alvinttang wants to merge 1 commit intoUnstructured-IO:mainfrom
Conversation
HtmlTable.text was joining all cell text with a flat space, losing row
structure. Downstream callers that relied on `str(table).split("\n\n")`
to reconstruct rows (e.g. header→value mapping for XLSX sheets) broke
silently after 0.16.0.
Fix: iterate rows via iter_rows()/iter_cell_texts(), join cells within a
row with a single space, and separate rows with double newlines. Empty
rows are suppressed. The html/text_as_html metadata fields are unchanged.
Co-Authored-By: Claude Sonnet 4.6 <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 #4235 —
str(Table)no longer preserves row boundaries after 0.16.0, breaking downstream parsing that relied onstr(table).split("\n\n")to reconstruct header→value mappings from XLSX sheets.Root cause:
HtmlTable.textinunstructured/common/html_table.pywas using" ".join(self._table.itertext())which walks all text nodes in document order and flattens everything into a single space-separated string. This lost all row structure.Fix: Replace the flat
itertext()join withiter_rows()/iter_cell_texts()— cells within a row are joined with" ", rows are joined with"\n\n", and all-blank rows are suppressed. Themetadata.text_as_htmlfield (compact HTML) is unchanged.Changes
unstructured/common/html_table.py—HtmlTable.textnow iterates rows and joins with"\n\n"test_unstructured/common/test_html_table.py— updated existing text assertion; added regression testit_separates_rows_with_double_newlines_for_boundary_reconstructionTest plan
test_html_table.pytests passstr(table).split("\n\n")returns one entry per row🤖 Generated with Claude Code