@@ -1471,21 +1471,6 @@ class _ZulipContentParser {
1471
1471
}
1472
1472
1473
1473
if (localName == 'p' && className.isEmpty) {
1474
- // Oddly, the way a math block gets encoded in Zulip HTML is inside a <p>.
1475
- if (element.nodes case [dom.Element (localName: 'span' ) && var child, ...]) {
1476
- if (child.className == 'katex-display' ) {
1477
- if (element.nodes case [_]
1478
- || [_, dom.Element (localName: 'br' ),
1479
- dom.Text (text: "\n " )]) {
1480
- // This might be too specific; we'll find out when we do #190.
1481
- // The case with the `<br>\n` can happen when at the end of a quote;
1482
- // it seems like a glitch in the server's Markdown processing,
1483
- // so hopefully there just aren't any further such glitches.
1484
- return parseMathBlock (child);
1485
- }
1486
- }
1487
- }
1488
-
1489
1474
final parsed = parseBlockInline (element.nodes);
1490
1475
return ParagraphNode (debugHtmlNode: debugHtmlNode,
1491
1476
links: parsed.links,
@@ -1599,6 +1584,30 @@ class _ZulipContentParser {
1599
1584
for (final node in nodes) {
1600
1585
if (node is dom.Text && (node.text == '\n ' )) continue ;
1601
1586
1587
+ // Oddly, the way a math block gets encoded in Zulip HTML is inside a <p>.
1588
+ if (node case dom.Element (localName: 'p' , className: '' , nodes: [
1589
+ dom.Element (
1590
+ localName: 'span' ,
1591
+ className: 'katex-display' ) && final child, ...])) {
1592
+ final BlockContentNode parsed;
1593
+ if (node.nodes case [_]
1594
+ || [_, dom.Element (localName: 'br' ),
1595
+ dom.Text (text: "\n " )]) {
1596
+ // This might be too specific; we'll find out when we do #190.
1597
+ // The case with the `<br>\n` can happen when at the end of a quote;
1598
+ // it seems like a glitch in the server's Markdown processing,
1599
+ // so hopefully there just aren't any further such glitches.
1600
+ parsed = parseMathBlock (child);
1601
+ } else {
1602
+ parsed = UnimplementedBlockContentNode (htmlNode: node);
1603
+ }
1604
+
1605
+ if (currentParagraph.isNotEmpty) consumeParagraph ();
1606
+ if (imageNodes.isNotEmpty) consumeImageNodes ();
1607
+ result.add (parsed);
1608
+ continue ;
1609
+ }
1610
+
1602
1611
if (_isPossibleInlineNode (node)) {
1603
1612
if (imageNodes.isNotEmpty) {
1604
1613
consumeImageNodes ();
@@ -1642,6 +1651,29 @@ class _ZulipContentParser {
1642
1651
continue ;
1643
1652
}
1644
1653
1654
+ // Oddly, the way a math block gets encoded in Zulip HTML is inside a <p>.
1655
+ if (node case dom.Element (localName: 'p' , className: '' , nodes: [
1656
+ dom.Element (
1657
+ localName: 'span' ,
1658
+ className: 'katex-display' ) && final child, ...])) {
1659
+ final BlockContentNode parsed;
1660
+ if (node.nodes case [_]
1661
+ || [_, dom.Element (localName: 'br' ),
1662
+ dom.Text (text: "\n " )]) {
1663
+ // This might be too specific; we'll find out when we do #190.
1664
+ // The case with the `<br>\n` can happen when at the end of a quote;
1665
+ // it seems like a glitch in the server's Markdown processing,
1666
+ // so hopefully there just aren't any further such glitches.
1667
+ parsed = parseMathBlock (child);
1668
+ } else {
1669
+ parsed = UnimplementedBlockContentNode (htmlNode: node);
1670
+ }
1671
+
1672
+ if (imageNodes.isNotEmpty) consumeImageNodes ();
1673
+ result.add (parsed);
1674
+ continue ;
1675
+ }
1676
+
1645
1677
final block = parseBlockContent (node);
1646
1678
if (block is ImageNode ) {
1647
1679
imageNodes.add (block);
0 commit comments