Skip to content

Commit 8cccebf

Browse files
committed
content: Handle clusters of images in parseImplicitParagraphBlockContentList
Fixes: #193
1 parent 1a0128a commit 8cccebf

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

lib/model/content.dart

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -997,6 +997,7 @@ class _ZulipContentParser {
997997
assert(_debugParserContext == _ParserContext.block);
998998
final List<BlockContentNode> result = [];
999999
final List<dom.Node> currentParagraph = [];
1000+
List<ImageNode> imageNodes = [];
10001001
void consumeParagraph() {
10011002
final parsed = parseBlockInline(currentParagraph);
10021003
result.add(ParagraphNode(
@@ -1014,9 +1015,19 @@ class _ZulipContentParser {
10141015
continue;
10151016
}
10161017
if (currentParagraph.isNotEmpty) consumeParagraph();
1017-
result.add(parseBlockContent(node));
1018+
final block = parseBlockContent(node);
1019+
if (block is ImageNode) {
1020+
imageNodes.add(block);
1021+
continue;
1022+
}
1023+
if (imageNodes.isNotEmpty) {
1024+
result.add(ImageNodeList(imageNodes));
1025+
imageNodes = [];
1026+
}
1027+
result.add(block);
10181028
}
10191029
if (currentParagraph.isNotEmpty) consumeParagraph();
1030+
if (imageNodes.isNotEmpty) result.add(ImageNodeList(imageNodes));
10201031

10211032
return result;
10221033
}

lib/widgets/content.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,10 @@ class BlockContentList extends StatelessWidget {
8585
} else if (node is ImageNodeList) {
8686
return MessageImageList(node: node);
8787
} else if (node is ImageNode) {
88+
assert(false,
89+
"[ImageNode] not allowed in [BlockContentList]. "
90+
"It should be wrapped in [ImageNodeList]."
91+
);
8892
return MessageImage(node: node);
8993
} else if (node is UnimplementedBlockContentNode) {
9094
return Text.rich(_errorUnimplemented(node));

0 commit comments

Comments
 (0)