File tree Expand file tree Collapse file tree 1 file changed +10
-0
lines changed Expand file tree Collapse file tree 1 file changed +10
-0
lines changed Original file line number Diff line number Diff line change @@ -523,13 +523,23 @@ class HtmlParser extends StatelessWidget {
523
523
/// If the text is the first element in the current tree node list, it
524
524
/// starts with a whitespace, it isn't a line break, and either the
525
525
/// whitespace is unnecessary or it is a block element, delete it.
526
+ ///
527
+ /// We should also delete the whitespace at any point in the node list
528
+ /// if the previous element is a <br> because that tag makes the element
529
+ /// act like a block element.
526
530
if (textIndex < 1
527
531
&& tree.text! .startsWith (' ' )
528
532
&& tree.element? .localName != "br"
529
533
&& (! keepLeadingSpace.data
530
534
|| BLOCK_ELEMENTS .contains (tree.element? .localName ?? "" ))
531
535
) {
532
536
tree.text = tree.text! .replaceFirst (' ' , '' );
537
+ } else if (textIndex >= 1
538
+ && tree.text! .startsWith (' ' )
539
+ && tree.element? .nodes[textIndex - 1 ] is dom.Element
540
+ && (tree.element? .nodes[textIndex - 1 ] as dom.Element ).localName == "br"
541
+ ) {
542
+ tree.text = tree.text! .replaceFirst (' ' , '' );
533
543
}
534
544
/// If the text is the last element in the current tree node list, it isn't
535
545
/// a line break, and the next text node starts with a whitespace,
You can’t perform that action at this time.
0 commit comments