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