|
1 | 1 | import 'dart:collection';
|
2 | 2 | import 'dart:math';
|
3 | 3 |
|
| 4 | +import 'package:collection/collection.dart'; |
4 | 5 | import 'package:csslib/parser.dart' as cssparser;
|
5 | 6 | import 'package:csslib/visitor.dart' as css;
|
6 | 7 | import 'package:flutter/material.dart';
|
@@ -438,7 +439,7 @@ class HtmlParser extends StatelessWidget {
|
438 | 439 | && tree.text!.startsWith(' ')
|
439 | 440 | && tree.element?.localName != "br"
|
440 | 441 | && (!keepLeadingSpace.data
|
441 |
| - || BLOCK_ELEMENTS.contains(tree.element?.localName ?? "")) |
| 442 | + || tree.style.display == Display.BLOCK) |
442 | 443 | && (elementIndex < 1
|
443 | 444 | || (elementIndex >= 1
|
444 | 445 | && parentNodes?[elementIndex - 1] is dom.Text
|
@@ -747,11 +748,16 @@ class HtmlParser extends StatelessWidget {
|
747 | 748 | static StyledElement _removeEmptyElements(StyledElement tree) {
|
748 | 749 | List<StyledElement> toRemove = <StyledElement>[];
|
749 | 750 | bool lastChildBlock = true;
|
750 |
| - tree.children.forEach((child) { |
| 751 | + tree.children.forEachIndexed((index, child) { |
751 | 752 | if (child is EmptyContentElement || child is EmptyLayoutElement) {
|
752 | 753 | toRemove.add(child);
|
753 | 754 | } else if (child is TextContentElement
|
754 |
| - && (tree.name == "body" || tree.name == "ul") |
| 755 | + && ((tree.name == "body" |
| 756 | + && (index == 0 |
| 757 | + || index + 1 == tree.children.length |
| 758 | + || tree.children[index - 1].style.display == Display.BLOCK |
| 759 | + || tree.children[index + 1].style.display == Display.BLOCK)) |
| 760 | + || tree.name == "ul") |
755 | 761 | && child.text!.replaceAll(' ', '').isEmpty) {
|
756 | 762 | toRemove.add(child);
|
757 | 763 | } else if (child is TextContentElement
|
|
0 commit comments