@@ -1579,8 +1579,14 @@ class _ZulipContentParser {
1579
1579
/// See [ParagraphNode] .
1580
1580
List <BlockContentNode > parseImplicitParagraphBlockContentList (dom.NodeList nodes) {
1581
1581
final List <BlockContentNode > result = [];
1582
- final List <dom. Node > currentParagraph = [];
1582
+
1583
1583
List <ImageNode > imageNodes = [];
1584
+ void consumeImageNodes () {
1585
+ result.add (ImageNodeList (imageNodes));
1586
+ imageNodes = [];
1587
+ }
1588
+
1589
+ final List <dom.Node > currentParagraph = [];
1584
1590
void consumeParagraph () {
1585
1591
final parsed = parseBlockInline (currentParagraph);
1586
1592
result.add (ParagraphNode (
@@ -1595,8 +1601,7 @@ class _ZulipContentParser {
1595
1601
1596
1602
if (_isPossibleInlineNode (node)) {
1597
1603
if (imageNodes.isNotEmpty) {
1598
- result.add (ImageNodeList (imageNodes));
1599
- imageNodes = [];
1604
+ consumeImageNodes ();
1600
1605
// In a context where paragraphs are implicit it should be impossible
1601
1606
// to have more paragraph content after image previews.
1602
1607
result.add (UnimplementedBlockContentNode (htmlNode: node));
@@ -1611,23 +1616,25 @@ class _ZulipContentParser {
1611
1616
imageNodes.add (block);
1612
1617
continue ;
1613
1618
}
1614
- if (imageNodes.isNotEmpty) {
1615
- result.add (ImageNodeList (imageNodes));
1616
- imageNodes = [];
1617
- }
1619
+ if (imageNodes.isNotEmpty) consumeImageNodes ();
1618
1620
result.add (block);
1619
1621
}
1620
1622
if (currentParagraph.isNotEmpty) consumeParagraph ();
1621
- if (imageNodes.isNotEmpty) result.add (ImageNodeList (imageNodes));
1622
-
1623
+ if (imageNodes.isNotEmpty) consumeImageNodes ();
1623
1624
return result;
1624
1625
}
1625
1626
1626
1627
static final _redundantLineBreaksRegexp = RegExp (r'^\n+$' );
1627
1628
1628
1629
List <BlockContentNode > parseBlockContentList (dom.NodeList nodes) {
1629
1630
final List <BlockContentNode > result = [];
1631
+
1630
1632
List <ImageNode > imageNodes = [];
1633
+ void consumeImageNodes () {
1634
+ result.add (ImageNodeList (imageNodes));
1635
+ imageNodes = [];
1636
+ }
1637
+
1631
1638
for (final node in nodes) {
1632
1639
// We get a bunch of newline Text nodes between paragraphs.
1633
1640
// A browser seems to ignore these; let's do the same.
@@ -1640,13 +1647,10 @@ class _ZulipContentParser {
1640
1647
imageNodes.add (block);
1641
1648
continue ;
1642
1649
}
1643
- if (imageNodes.isNotEmpty) {
1644
- result.add (ImageNodeList (imageNodes));
1645
- imageNodes = [];
1646
- }
1650
+ if (imageNodes.isNotEmpty) consumeImageNodes ();
1647
1651
result.add (block);
1648
1652
}
1649
- if (imageNodes.isNotEmpty) result. add ( ImageNodeList (imageNodes) );
1653
+ if (imageNodes.isNotEmpty) consumeImageNodes ( );
1650
1654
return result;
1651
1655
}
1652
1656
0 commit comments