|
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/gestures.dart';
|
@@ -286,12 +287,18 @@ class HtmlParser extends StatelessWidget {
|
286 | 287 | style: tree.style,
|
287 | 288 | shrinkWrap: context.parser.shrinkWrap,
|
288 | 289 | children: tree.children
|
289 |
| - .expand((tree) => [ |
290 |
| - parseTree(newContext, tree), |
| 290 | + .expandIndexed((i, childTree) => [ |
291 | 291 | if (shrinkWrap &&
|
292 |
| - tree.style.display == Display.BLOCK && |
293 |
| - tree.element?.localName != "html" && |
294 |
| - tree.element?.localName != "body") |
| 292 | + childTree.style.display == Display.BLOCK && |
| 293 | + i > 0 && |
| 294 | + tree.children[i - 1] is ReplacedElement) |
| 295 | + TextSpan(text: "\n"), |
| 296 | + parseTree(newContext, childTree), |
| 297 | + if (shrinkWrap && |
| 298 | + i != tree.children.length - 1 && |
| 299 | + childTree.style.display == Display.BLOCK && |
| 300 | + childTree.element?.localName != "html" && |
| 301 | + childTree.element?.localName != "body") |
295 | 302 | TextSpan(text: "\n"),
|
296 | 303 | ])
|
297 | 304 | .toList(),
|
@@ -433,21 +440,26 @@ class HtmlParser extends StatelessWidget {
|
433 | 440 | child: StyledText(
|
434 | 441 | textSpan: TextSpan(
|
435 | 442 | style: newContext.style.generateTextStyle(),
|
436 |
| - children: tree.children |
437 |
| - .map((tree) => parseTree(newContext, tree)) |
438 |
| - .toList(), |
| 443 | + children: tree.children.map((tree) => parseTree(newContext, tree)).toList(), |
439 | 444 | ),
|
440 | 445 | style: newContext.style,
|
441 |
| - renderContext: context, |
| 446 | + renderContext: newContext, |
442 | 447 | ),
|
443 | 448 | ),
|
444 | 449 | );
|
445 | 450 | } else {
|
446 | 451 | ///[tree] is an inline element.
|
447 | 452 | return TextSpan(
|
448 | 453 | style: newContext.style.generateTextStyle(),
|
449 |
| - children: |
450 |
| - tree.children.map((tree) => parseTree(newContext, tree)).toList(), |
| 454 | + children: tree.children |
| 455 | + .expand((tree) => [ |
| 456 | + parseTree(newContext, tree), |
| 457 | + if (tree.style.display == Display.BLOCK && |
| 458 | + tree.element?.localName != "html" && |
| 459 | + tree.element?.localName != "body") |
| 460 | + TextSpan(text: "\n"), |
| 461 | + ]) |
| 462 | + .toList(), |
451 | 463 | );
|
452 | 464 | }
|
453 | 465 | }
|
|
0 commit comments