Repository navigation
fix(utils): separate HTML5 block elements and table headers in htmlToText - #4366
Merged
barjin merged 1 commit intoNov 9, 2026
Merged
Conversation
…Text Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
barjin
approved these changes
Nov 9, 2026
barjin
left a comment
Member
There was a problem hiding this comment.
lgtm, thank you @SwastikTripathi !
barjin
approved these changes
Nov 9, 2026
barjin
left a comment
Member
There was a problem hiding this comment.
lgtm, thank you @SwastikTripathi !
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.
htmlToTextonly adds line breaks around the block tags inBLOCK_TAGS_REGEX, and that list stops at HTML 4. Sibling HTML5 sections were glued together, which is the merging of distinct text that the function's docs say it tries to avoid:<section>Call 555-1234</section><section>9876 Main St</section>Call 555-12349876 Main StCall 555-1234\n9876 Main St<header>Head</header><main>Body</main><footer>Foot</footer>HeadBodyFootHead\nBody\nFootA<hr>BABA\nB<dl><dt>Term</dt><dd>Def</dd></dl>TermDefTerm\nDef<details><summary>Sum</summary>Body</details>SumBodySum\nBody<tr><th>H1</th><th>H2</th></tr>H1H2H1\tH2\tThe first row shows the practical effect:
social.parseHandlesFromHtmlruns on this text, so a phone number at the end of one<section>runs into the next section's digits.The list now also has the HTML5 sectioning and grouping elements a browser lays out as blocks (
article,aside,section,nav,header,footer,main,hgroup,figure,figcaption,details,summary,dialog,menu), plushr,dt,dd,legendandcaption.<th>cells get the same tab separator as<td>.Added a test with those cases to
test/utils/cheerio.test.ts. None of the new tags appear in the existing inputs (includinghtml-to-text-test-data.tsand the social tests), so their expected output doesn't change.Verification: I couldn't run the repo's vitest suite here. I ran the new test's cases, plus several existing cases, through the published
@crawlee/utilsbuild, once as released and once with the same two-line change applied to its compiledcheerio.js(the block-tag andtdcode is the same as on master). As released, all 7 new cases fail. With the change, all 7 pass, both bare and wrapped in a full<html><body>document ascheckHtmlToTextdoes, and the existing cases I retyped give the same output as before.oxfmt --checkpasses on both files.🤖 Generated with Claude Code