Repository navigation
fix(parser): start a new line before every HTML block element - #21107
Conversation
walkHTMLLeaf broke the line in front of a block child only for p, li,
headings, tr and blockquote, while it broke the line after every tag in
isBlockTag. Text in front of a nested div, section or article ran into the
block's own ("<div>Name:<div>Alice</div></div>" read "Name:Alice").
Block elements missing from isBlockTag (dl, dt, dd, figure, figcaption,
hr, nav, main, aside, ...) broke it on neither side, so "A<dl><dt>Term"
read "ATerm" and "above<hr>below" read "abovebelow".
The break in front of a block now uses isBlockTag, like the break after it
and like the email body walker, and isBlockTag lists the elements HTML lays
out as blocks. The email walker shares isBlockTag, so its definition lists
and rules are separated too.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info
📝 Walkthrough
Merge Risk: ⚪ Minimal · up to
|
|
LGTM |
yuzhichang
left a comment
There was a problem hiding this comment.
LGTM. Extending isBlockTag to the remaining block-level elements is consistent with the existing before/after break logic, and the tests cover div, dl, figure, hr, and nav. No blocking findings.
Summary
walkHTMLLeafinhtml_parser.gohandles line breaks around block children unevenly:isBlockTag.p,li,h1–h6,trandblockquote.So text in front of a nested
div,section,article,headerorfooterran into the block's own text. Block elements thatisBlockTagdoes not list got no break on either side. Onmain:<div>Name:<div>Alice</div></div>Name:Alice<div><span>Total</span><div>42</div></div>Total42<div>A<dl><dt>Term</dt><dd>Definition</dd></dl>B</div>ATermDefinitionB<div>See<figure><figcaption>Fig 1</figcaption></figure>below</div>SeeFig 1below<div>above<hr>below</div>abovebelow<article>left<nav>Menu</nav>right</article>leftMenurightThe glued tokens (
Name:Alice,Total42) match a search for neither word.What changed
isBlockTag, the same as the break after it.htmlBodyToText, the email body walker, already does both, andTestHTMLBodyToTextcovers its "text before nested block" case.isBlockTagnow lists the elements HTML lays out as blocks:main,nav,aside,address,hgroup,search,center,ul,ol,menu,dl,dt,dd,figure,figcaption,details,summary,dialog,form,fieldset,legendandhr.The email walker shares
isBlockTag, so definition lists and rules in email bodies are separated as well. Inline elements are unchanged:<div>Hello <b>bold</b> and <a>link</a> text</div>is still one line.Testing
TestHTMLParser_BlockElementsStartANewLinecovers the six cases in the table plus one inline case. Onmain, all six block cases fail.TestHTMLBodyToTextgets a definition list and rule case, which also fails onmain.TestHTMLParser_AlignmentGolden, and the email tests pass unchanged.go vetreports only the existingpaddleocr.go:453context warning.