Skip to content

Commit

Permalink
fix some inline tests?
Browse files Browse the repository at this point in the history
  • Loading branch information
sirpengi committed Jan 26, 2024
1 parent da747a7 commit f25708d
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 23 deletions.
16 changes: 13 additions & 3 deletions lib/model/content.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1016,9 +1016,19 @@ class _ZulipContentParser {
if (node is dom.Text && (node.text == '\n')) continue;

if (_isPossibleInlineNode(node)) {
// TODO: It seems impossible to trigger this using real markup.
// Images are always the final items of a list item.
if (imageNodes.isNotEmpty) consumeImages();
if (imageNodes.isNotEmpty) {
consumeImages();
// In a context where paragraphs are implicit it
// should be impossible to have more paragraph
// content after image previews.
result.add(ParagraphNode(
wasImplicit: true,
links: null,
nodes: [UnimplementedInlineContentNode(htmlNode: node)]
));
// But what to do with the rest of the content?
continue;
}
currentParagraph.add(node);
continue;
}
Expand Down
33 changes: 13 additions & 20 deletions test/model/content_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,8 @@ void main() {
]),
]);

testParse('image as immediate child in list item',
// TODO: maybe delete this
testParse('image as immediate child in implicit paragraph',
// "* https://chat.zulip.org/user_avatars/2/realm/icon.png"
'<ul>\n'
'<li>'
Expand All @@ -546,7 +547,7 @@ void main() {
]]),
]);

testParse('image cluster in list item',
testParse('image cluster in implicit paragraph',
// "* [icon.png](https://chat.zulip.org/user_avatars/2/realm/icon.png) [icon.png](https://chat.zulip.org/user_avatars/2/realm/icon.png?version=2)"
'<ul>\n'
'<li>'
Expand All @@ -572,34 +573,26 @@ void main() {
]]),
]);

testParse('content after image cluster in list item',
// "* [icon.png](https://chat.zulip.org/user_avatars/2/realm/icon.png) [icon.png](https://chat.zulip.org/user_avatars/2/realm/icon.png?version=2)\n\n another paragraph"
testParse('impossible content after image cluster in implicit paragraph',
'<ul>\n'
'<li>\n'
'<p>'
'<a href="https://chat.zulip.org/user_avatars/2/realm/icon.png">icon.png</a> '
'<a href="https://chat.zulip.org/user_avatars/2/realm/icon.png?version=2">icon.png</a></p>\n'
'<li>'
'<a href="https://chat.zulip.org/user_avatars/2/realm/icon.png">icon.png</a> '
'<div class="message_inline_image">'
'<a href="https://chat.zulip.org/user_avatars/2/realm/icon.png" title="icon.png">'
'<img src="https://chat.zulip.org/user_avatars/2/realm/icon.png"></a></div>'
'<div class="message_inline_image">'
'<a href="https://chat.zulip.org/user_avatars/2/realm/icon.png?version=2" title="icon.png">'
'<img src="https://chat.zulip.org/user_avatars/2/realm/icon.png?version=2"></a></div>'
'<p>another paragraph</p>\n</li>\n</ul>',
const [
'<span>Some content</span></li>\n</ul>',
[
ListNode(ListStyle.unordered, [[
ParagraphNode(links: null, nodes: [
const ParagraphNode(wasImplicit: true, links: null, nodes: [
LinkNode(url: 'https://chat.zulip.org/user_avatars/2/realm/icon.png', nodes: [TextNode('icon.png')]),
TextNode(' '),
LinkNode(url: 'https://chat.zulip.org/user_avatars/2/realm/icon.png?version=2', nodes: [TextNode('icon.png')]),
]),
ImageNodeList([
const ImageNodeList([
ImageNode(srcUrl: 'https://chat.zulip.org/user_avatars/2/realm/icon.png'),
ImageNode(srcUrl: 'https://chat.zulip.org/user_avatars/2/realm/icon.png?version=2'),
]),
ParagraphNode(links: null, nodes: [
TextNode('another paragraph'),
]),
ParagraphNode(wasImplicit: true, links: null, nodes: [
inlineUnimplemented('<span>Some content</span>'),
])
]]),
]);
});
Expand Down

0 comments on commit f25708d

Please sign in to comment.