Skip to content

Blank text nodes after code blocks are "unimplemented" #355

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

Closed
Tracked by #309
gnprice opened this issue Nov 1, 2023 · 2 comments · Fixed by #604
Closed
Tracked by #309

Blank text nodes after code blocks are "unimplemented" #355

gnprice opened this issue Nov 1, 2023 · 2 comments · Fixed by #604
Assignees
Labels
a-content Parsing and rendering Zulip HTML content, notably message contents

Comments

@gnprice
Copy link
Member

gnprice commented Nov 1, 2023

In a few messages, the current prototype reports as "unimplemented" a text node that appears to consist of two newlines. Specifically I see this in two recent messages on chat.zulip.org:
https://chat.zulip.org/#narrow/stream/412-api-documentation/topic/OpenAPI.20requestBody/near/1672619
https://chat.zulip.org/#narrow/stream/378-api-design/topic/unreads.3A.20access.20to.20messages/near/1668410

Both are from me; I don't know if there's some pattern in how I format things that happens to tickle this, or if that's a coincidence. In both cases, the unimplemented node appears just after a code block.

We should pin down what's happening in these messages and fix it so that we handle that HTML correctly with no complaints. For how to get the server's HTML for those messages, see comments in test/model/content_test.dart.

@gnprice gnprice added the a-content Parsing and rendering Zulip HTML content, notably message contents label Nov 1, 2023
@gnprice gnprice added this to the Beta milestone Nov 1, 2023
@gnprice gnprice modified the milestones: Beta 1, Beta 2 Nov 8, 2023
@gnprice gnprice modified the milestones: Beta 2, Beta 3 Nov 22, 2023
@Khader-1
Copy link
Collaborator

After inspecting the messages mentioned. I found that the issue has to do with the '\n' in the message html:

<div class="codehilite"><pre><span></span><code>openapi: Loosen anchor parameter specification to string.\n</code></pre></div>\n\n<p>This is a temporary hack, I hope. It sounds like it's covered by issues 698 and/or 700 you mentioned above.</p>

Specifically:
\n\n in </div>\n\n<p>This is

looking back at the code I can see that in case of single \n this gets handled with an if statement

  /** @lib/model/content.dart:1103 */
  List<BlockContentNode> parseBlockContentList(dom.NodeList nodes) {
    assert(_debugParserContext == _ParserContext.block);
    final List<BlockContentNode> result = [];
    List<ImageNode> imageNodes = [];
    for (final node in nodes) {
      // We get a bunch of newline Text nodes between paragraphs.
      // A browser seems to ignore these; let's do the same.
      if (node is dom.Text && (node.text == '\n')) continue;
      // ......

I imagine this can be easily solved by replacing the existing check that the node.text is \n with a regular expression that checks it the text is any number of repetitions of '\n'. Something like

      if (node is dom.Text && RegExp(r'^(\n+)$').hasMatch(node.text)) continue;

I will create a new test case and work on it.

Khader-1 added a commit to Khader-1/zulip-flutter that referenced this issue Mar 29, 2024
Khader-1 added a commit to Khader-1/zulip-flutter that referenced this issue Mar 29, 2024
Khader-1 added a commit to Khader-1/zulip-flutter that referenced this issue Mar 30, 2024
Khader-1 added a commit to Khader-1/zulip-flutter that referenced this issue Apr 4, 2024
Khader-1 added a commit to Khader-1/zulip-flutter that referenced this issue Apr 8, 2024
@gnprice
Copy link
Member Author

gnprice commented Apr 25, 2024

We should pin down what's happening in these messages and fix it so that we handle that HTML correctly with no complaints.

FTR, we determined (#604 (comment)) that the pattern that triggers this quirk in the server is for the message's Markdown source to express the code block with four-space-indent syntax, rather than triple-backticks syntax.

(And that does indeed cover the two original examples above, as well as all other examples we've found.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a-content Parsing and rendering Zulip HTML content, notably message contents
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

2 participants