@@ -625,8 +625,10 @@ class HtmlParser extends StatelessWidget {
625
625
parentAfterText = parentAfter? .text ?? " " ;
626
626
}
627
627
/// If the text is the first element in the current tree node list, it
628
- /// starts with a whitespace, it isn't a line break, and either the
629
- /// whitespace is unnecessary or it is a block element, delete it.
628
+ /// starts with a whitespace, it isn't a line break, either the
629
+ /// whitespace is unnecessary or it is a block element, and either it is
630
+ /// first element in the parent node list or the previous element
631
+ /// in the parent node list ends with a whitespace, delete it.
630
632
///
631
633
/// We should also delete the whitespace at any point in the node list
632
634
/// if the previous element is a <br> because that tag makes the element
@@ -636,6 +638,10 @@ class HtmlParser extends StatelessWidget {
636
638
&& tree.element? .localName != "br"
637
639
&& (! keepLeadingSpace.data
638
640
|| BLOCK_ELEMENTS .contains (tree.element? .localName ?? "" ))
641
+ && (elementIndex < 1
642
+ || (elementIndex >= 1
643
+ && parentNodes? [elementIndex - 1 ] is dom.Text
644
+ && parentNodes! [elementIndex - 1 ].text! .endsWith (" " )))
639
645
) {
640
646
tree.text = tree.text! .replaceFirst (' ' , '' );
641
647
} else if (textIndex >= 1
0 commit comments