Skip to content

Commit 5f6f785

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

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-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: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,21 @@ class ContentExample {
301301
'\n</code></pre></div>'),
302302
]);
303303

304+
static const lineBreaksAfterCodeBlocks = ContentExample(
305+
'blank text nodes after code blocks',
306+
' code block.\n\nsome content',
307+
'<div class="codehilite">'
308+
'<pre><span></span><code>'
309+
'code block.\n'
310+
'</code></pre>'
311+
'</div>\n\n'
312+
'<p>'
313+
'some content'
314+
'</p>', [
315+
CodeBlockNode([CodeBlockSpanNode(text: "code block.", type: CodeBlockSpanType.text)]),
316+
ParagraphNode(links: null, nodes: [TextNode("some content")]),
317+
]);
318+
304319
static final mathInline = ContentExample.inline(
305320
'inline math',
306321
r"$$ \lambda $$",
@@ -843,6 +858,7 @@ void main() {
843858
testParseExample(ContentExample.codeBlockHighlightedMultiline);
844859
testParseExample(ContentExample.codeBlockWithHighlightedLines);
845860
testParseExample(ContentExample.codeBlockWithUnknownSpanType);
861+
testParseExample(ContentExample.lineBreaksAfterCodeBlocks);
846862

847863
testParseExample(ContentExample.mathBlock);
848864
testParseExample(ContentExample.mathBlockInQuote);

0 commit comments

Comments
 (0)