-
Notifications
You must be signed in to change notification settings - Fork 306
Handle the case when a code block has no grandchildren #919
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -986,18 +986,18 @@ class _ZulipContentParser { | |
&& divElement.className == "codehilite"); | ||
|
||
if (divElement.nodes.length != 1) return null; | ||
final child = divElement.nodes[0]; | ||
final child = divElement.nodes.single; | ||
if (child is! dom.Element) return null; | ||
if (child.localName != 'pre') return null; | ||
|
||
if (child.nodes.length > 2) return null; | ||
if (child.nodes.length > 2 || child.nodes.isEmpty) return null; | ||
if (child.nodes.length == 2) { | ||
final first = child.nodes[0]; | ||
if (first is! dom.Element | ||
|| first.localName != 'span' | ||
|| first.nodes.isNotEmpty) return null; | ||
} | ||
final grandchild = child.nodes[child.nodes.length - 1]; | ||
final grandchild = child.nodes.last; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this a pure refactor, or does this change behavior somehow? I noticed there's a line There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This refactoring is purely for readability. Let's get an nfc commit for both. |
||
if (grandchild is! dom.Element) return null; | ||
if (grandchild.localName != 'code') return null; | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -344,6 +344,17 @@ class ContentExample { | |
]), | ||
]); | ||
|
||
// Current servers no longer produce this, but it can be found in ancient | ||
// messages. For example: | ||
// https://chat.zulip.org/#narrow/stream/2-general/topic/Error.20in.20dev.20server/near/18765 | ||
static final codeBlockWithEmptyBody = ContentExample( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's have a comment that makes it clear we don't expect this in messages from current servers. The link to the ancient message you put in the PR description is helpful; we could include that here too. |
||
'code block, with an empty body', | ||
'```', | ||
'<div class="codehilite"><pre></pre></div>', [ | ||
blockUnimplemented( | ||
'<div class="codehilite"><pre></pre></div>'), | ||
]); | ||
|
||
static final codeBlockWithHighlightedLines = ContentExample( | ||
'code block, with syntax highlighting and highlighted lines', | ||
'```\n::markdown hl_lines="2 4"\n# he\n## llo\n### world\n```', | ||
|
@@ -1149,6 +1160,7 @@ void main() { | |
testParseExample(ContentExample.codeBlockPlain); | ||
testParseExample(ContentExample.codeBlockHighlightedShort); | ||
testParseExample(ContentExample.codeBlockHighlightedMultiline); | ||
testParseExample(ContentExample.codeBlockWithEmptyBody); | ||
testParseExample(ContentExample.codeBlockWithHighlightedLines); | ||
testParseExample(ContentExample.codeBlockWithUnknownSpanType); | ||
testParseExample(ContentExample.codeBlockFollowedByMultipleLineBreaks); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: include the key "why" information in the commit message, rather than rely on the PR description. We aim for the Git history to be able to serve as our primary record of what we did.
In particular key points include
Details that can be read off from the commit's added test case don't need to be repeated in the commit message, though.