Skip to content

Commit 02e29b2

Browse files
committed
content: Handle blank text nodes after code blocks
Fixes: zulip#355
1 parent 81feda5 commit 02e29b2

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

lib/model/content.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1107,7 +1107,7 @@ class _ZulipContentParser {
11071107
for (final node in nodes) {
11081108
// We get a bunch of newline Text nodes between paragraphs.
11091109
// A browser seems to ignore these; let's do the same.
1110-
if (node is dom.Text && (node.text == '\n')) continue;
1110+
if (node is dom.Text && RegExp(r'^(\n+)$').hasMatch(node.text)) continue;
11111111

11121112
final block = parseBlockContent(node);
11131113
if (block is ImageNode) {

test/model/content_test.dart

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -521,6 +521,21 @@ class ContentExample {
521521
blockUnimplemented('more text'),
522522
]]),
523523
]);
524+
525+
static const lineBreaksAfterCodeBlocks = ContentExample(
526+
'blank text nodes after code blocks',
527+
' code block''\n\n''some content',
528+
'<div class="codehilite">'
529+
'<pre><code>'
530+
'code block.\n'
531+
'</code></pre>'
532+
'</div>\n\n'
533+
'<p>'
534+
'some content'
535+
'</p>', [
536+
CodeBlockNode([CodeBlockSpanNode(text: "code block.", type: CodeBlockSpanType.text)]),
537+
ParagraphNode(links: null, nodes: [TextNode("some content")]),
538+
]);
524539
}
525540

526541
UnimplementedBlockContentNode blockUnimplemented(String html) {
@@ -875,6 +890,8 @@ void main() {
875890
]]),
876891
]);
877892

893+
testParseExample(ContentExample.lineBreaksAfterCodeBlocks);
894+
878895
test('all content examples are tested', () {
879896
// Check that every ContentExample defined above has a corresponding
880897
// actual test case that runs on it. If you've added a new example

0 commit comments

Comments
 (0)