Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions lib/html_parser.dart
Original file line number Diff line number Diff line change
Expand Up @@ -625,8 +625,10 @@ class HtmlParser extends StatelessWidget {
parentAfterText = parentAfter?.text ?? " ";
}
/// If the text is the first element in the current tree node list, it
/// starts with a whitespace, it isn't a line break, and either the
/// whitespace is unnecessary or it is a block element, delete it.
/// starts with a whitespace, it isn't a line break, either the
/// whitespace is unnecessary or it is a block element, and either it is
/// first element in the parent node list or the previous element
/// in the parent node list ends with a whitespace, delete it.
///
/// We should also delete the whitespace at any point in the node list
/// if the previous element is a <br> because that tag makes the element
Expand All @@ -636,6 +638,10 @@ class HtmlParser extends StatelessWidget {
&& tree.element?.localName != "br"
&& (!keepLeadingSpace.data
|| BLOCK_ELEMENTS.contains(tree.element?.localName ?? ""))
&& (elementIndex < 1
|| (elementIndex >= 1
&& parentNodes?[elementIndex - 1] is dom.Text
&& parentNodes![elementIndex - 1].text!.endsWith(" ")))
) {
tree.text = tree.text!.replaceFirst(' ', '');
} else if (textIndex >= 1
Expand Down