Skip to content
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

content: Handle <hr> horizontal lines #603

Merged

Conversation

Khader-1
Copy link
Collaborator

@Khader-1 Khader-1 commented Mar 29, 2024

Final Result:

image

Fixes: #353

@Khader-1 Khader-1 force-pushed the content-handle-hr-thematic-break-element branch from 5a9ba2b to f6f3503 Compare March 29, 2024 21:55
lib/widgets/content.dart Outdated Show resolved Hide resolved
Copy link
Collaborator

@chrisbobbe chrisbobbe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, this looks mostly good! Some small comments, below.

Also, let's add a some test for the new ThematicBreak widget, in test/widgets/content_test.dart. One shortcut to doing that is testContentSmoke, but unfortunately it won't help us here—it requires ContentExample.expectedText to be non-null, and these "thematic break" lines don't come with any text to check. 🙂 But there are some tests in that file in the same situation, and they end up being pretty simple. For example, the smoke tests for MessageImageEmoji.

lib/widgets/content.dart Outdated Show resolved Hide resolved
lib/widgets/content.dart Show resolved Hide resolved
lib/widgets/content.dart Outdated Show resolved Hide resolved
test/model/content_test.dart Outdated Show resolved Hide resolved
@Khader-1 Khader-1 force-pushed the content-handle-hr-thematic-break-element branch from f6f3503 to ec95eb3 Compare March 30, 2024 10:18
@Khader-1
Copy link
Collaborator Author

Thanks @chrisbobbe! I have restructured the code accordingly.

Copy link
Member

@gnprice gnprice left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @Khader-1, and thanks @chrisbobbe for the review!

A few more comments below, mainly on the tests.

Please also update the screenshot at the top of the PR for the current revision (since I believe you've adjusted the layout). That'll help for getting feedback on the visual result.

test/model/content_test.dart Outdated Show resolved Hide resolved
test/widgets/content_test.dart Outdated Show resolved Hide resolved
lib/widgets/content.dart Outdated Show resolved Hide resolved
@Khader-1 Khader-1 force-pushed the content-handle-hr-thematic-break-element branch 2 times, most recently from d5e07e6 to 36391f8 Compare April 2, 2024 15:19
@Khader-1 Khader-1 requested a review from gnprice April 2, 2024 15:20
lib/widgets/content.dart Outdated Show resolved Hide resolved
Copy link
Member

@gnprice gnprice left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the revision! Comments below.

static const thematicBreaks = ContentExample(
'parse thematic break (<hr>) in block context',
'a\n---\nb',
'<p>a</p><hr><p>b</p>',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Huh, is this the HTML the server outputs for this input? I'd have guessed there'd be some newlines in there, like between </p> and <hr>, based on how some other examples in this file look.

Would you link in the PR description to a test message on chat.zulip.org that demonstrates this example? (That's probably something we should start making a practice of, for better reproducibility. Or perhaps even put the link into the source code.)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apologies for the oversight. I adjusted the output for readability purposes, which resulted in a cleaner HTML string. However, I understand the importance of maintaining accuracy for testing purposes. Moving forward, I'll ensure the test output aligns precisely with the server's actual output.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here's the link to the message in the latest version of the test:
https://chat.zulip.org/#narrow/stream/7-test-here/topic/content.3A.20Handle.20Thematic.20Breaks/near/1774718
Do you suggest having it in ContentExample as an nullable field? or just a comment will do?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool, thanks. Yeah, readability is important, but for these tests their job is to make sure we're successfully parsing whatever the server sends us, with all its quirks and sometimes messes — so the top priority is for the data to represent those authentically.

For now let's just add the link in a comment, like this:

  static const thematicBreaks =  ContentExample(
    'parse thematic break (<hr>) in block context',
    // https://chat.zulip.org/#narrow/stream/7-test-here/near/1774718
    'a\n---\nb',
    '<p>a</p>\n<hr>\n<p>b</p>',

Then I'll file a separate issue for filling that in for the existing examples, adding it as a field, and also adding some automated validation of it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Filed #617.

lib/widgets/content.dart Outdated Show resolved Hide resolved
Copy link
Member

@gnprice gnprice left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the revision! Two wording nits below, and I replied above about the URL. I'll make those three tweaks and merge.

@@ -521,6 +521,16 @@ class ContentExample {
blockUnimplemented('more text'),
]]),
]);

static const thematicBreaks = ContentExample(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: there's only one of these, so singular:

Suggested change
static const thematicBreaks = ContentExample(
static const thematicBreak = ContentExample(

@@ -521,6 +521,16 @@ class ContentExample {
blockUnimplemented('more text'),
]]),
]);

static const thematicBreaks = ContentExample(
'parse thematic break (<hr>) in block context',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: "in block context" is redundant because that's the only way <hr> can appear:

Suggested change
'parse thematic break (<hr>) in block context',
'parse thematic break (<hr>)',

(there's a phrase like that for the test that produces LineBreakNode, but that's to contrast it with the "inside a paragraph" version that produces LineBreakInlineNode)

@gnprice gnprice force-pushed the content-handle-hr-thematic-break-element branch from 736cd84 to a7d97d5 Compare April 4, 2024 22:02
@gnprice gnprice merged commit a7d97d5 into zulip:main Apr 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Handle <hr> horizontal lines
3 participants