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

widgets: Support markdown in widgets. #28079

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

roanster007
Copy link
Collaborator

@roanster007 roanster007 commented Dec 7, 2023

Previously, markdown was not supported in widgets like polls and todo. This is fixed by adding an inline only backend processor ZulipInlineMarkdown, and using it to render the poll options or tasks and descriptions of todo before adding them to the database.

  • Commt 1 (fbb12bc): Add ZulipInlineMarkdown processor to render inline only patterns.
  • Commit 2 (e4ceba6): Support inline markdown in polls.
  • Commit 3 (1197b5f): Support inline markdown in todo widgets.

Fixes: #21917

CZO

Screenshots and screen captures:

image image
Self-review checklist
  • Self-reviewed the changes for clarity and maintainability
    (variable names, code reuse, readability, etc.).

Communicate decisions, questions, and potential concerns.

  • Explains differences from previous plans (e.g., issue description).
  • Highlights technical choices and bugs encountered.
  • Calls out remaining decisions and concerns.
  • Automated tests verify logic where appropriate.

Individual commits are ready for review (see commit discipline).

  • Each commit is a coherent idea.
  • Commit message(s) explain reasoning and motivation for changes.

Completed manual review and testing of the following:

  • Visual appearance of the changes.
  • Responsiveness and internationalization.
  • Strings and tooltips.
  • End-to-end functionality of buttons, interactions and flows.
  • Corner cases, error conditions, and easily imagined bugs.

@roanster007 roanster007 force-pushed the iss-12947 branch 2 times, most recently from fd6cc8a to e66720e Compare December 7, 2023 13:13
@roanster007 roanster007 marked this pull request as draft December 9, 2023 20:53
@roanster007 roanster007 marked this pull request as ready for review December 11, 2023 14:35
@roanster007 roanster007 force-pushed the iss-12947 branch 5 times, most recently from 0c7d818 to e7c9978 Compare December 11, 2023 17:03
@bupd
Copy link
Collaborator

bupd commented Dec 12, 2023

@roanster007 Reviewed the changes locally <time and basic markdown seems to be working fine.

poll-time

I've noticed that the current process of adding time to a poll in Zulip involves typing the time in the compose box and then copying it to the "Add Option" field. While this works well, it would be even more user-friendly to directly implement time rendering for additional options.

I suggest extending the time rendering functionality to the "Add Option" field, allowing users to input time in a similar manner. This enhancement would streamline the process and provide a consistent experience across the poll creation interface.

Implementation Details:

When users type a time in the "Add Option" field, the system should recognize and render it accordingly.
Ensure that the time rendering follows the same format as when entered in the compose box.
Benefits:

Improved user experience by eliminating the need to copy-paste time from the compose box to the "Add Option" field.
Consistency in time rendering across different input fields.
I believe this enhancement would make the poll creation process even more efficient and user-friendly. I'd be happy to contribute to the implementation if needed.

The decision should be made by project contributors to include the above suggestion or not.

Copy link
Collaborator

@bupd bupd left a comment

Choose a reason for hiding this comment

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

It works.

@alya
Copy link
Contributor

alya commented Jan 4, 2024

Thanks! For polls, links and emoji look good to me, but the time should be rendered like it is in messages. Compare:

Screenshot 2024-01-04 at 10 54 22 AM

@alya
Copy link
Contributor

alya commented Jan 4, 2024

For todo lists:

  1. The elements should work in the description part of the item as well, not just the first part.
  2. These changes break the crossed out formatting for checked items.

Screenshot 2024-01-04 at 11 00 04 AM

@alya
Copy link
Contributor

alya commented Jan 4, 2024

@bupd I agree that we should ideally have a better way to input times (and emoji), but let's make sure we get the rendering part of this working first.

@roanster007 roanster007 force-pushed the iss-12947 branch 3 times, most recently from 3c80967 to d4bae1a Compare January 11, 2024 18:23
@roanster007
Copy link
Collaborator Author

@alya I have updated the PR and screenshots as per the feedback.

@alya
Copy link
Contributor

alya commented Jan 17, 2024

Thanks! It looks like the space after the : and before the descriptions might have disappeared?

@alya
Copy link
Contributor

alya commented Jan 17, 2024

Other than that, the screenshots look good to me. You can add the "maintainer review" label (via Zulipbot) and ping @N-Shar-ma to take a look once that's been fixed.

@roanster007
Copy link
Collaborator Author

@zulipbot add "maintainer review"

@zulipbot zulipbot added the maintainer review PR is ready for review by Zulip maintainers. label Jan 20, 2024
@roanster007
Copy link
Collaborator Author

@N-Shar-ma could you have a look at this..

Copy link
Collaborator

@N-Shar-ma N-Shar-ma left a comment

Choose a reason for hiding this comment

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

Reviewed the frontend code and have left some comments.

Someone else who is familiar with the backend markdown processor will be much better suited to review those parts; sorry I've not worked on that part of the codebase so far

const html = render_widgets_poll_widget_results(widget_data);
$elem.find("ul.poll-widget").html(html);

render_poll_timestamp($elem);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Directly pass $elem.find("ul.poll-widget") instead to this function. That will make it more generalised, so also reusable by todo widgets, eliminating the near duplicate function in todo_widget.js

Copy link
Collaborator

Choose a reason for hiding this comment

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

Would be even better if you could extract this as a function in rendered_markdown where this code is from, and call that here.

We always want to minimize code duplication as much as possible

Copy link
Collaborator Author

@roanster007 roanster007 Feb 2, 2024

Choose a reason for hiding this comment

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

I felt using the update_elements of rendered_markdown would be unreasonable since that method would try to look out for lot of other elements too apart form time in $elem like mentions, codehilite,... but those for sure won't be rendered inside the widget by the inline processor.

Moreover, importing rendered_markdown.js method into poll_widget.ts is causing Could not find a declaration file for module './rendered_markdown'. 'rendered_markdown.js' implicitly has an 'any' type

Copy link
Collaborator

Choose a reason for hiding this comment

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

I meant extracting just the relevant code as a new function and calling that, not the pre existing whole update_elements function.

But yes, the non typescript file import into this typescript file still remains an issue 🤔

@@ -166,7 +181,7 @@
.poll-names {
color: hsl(0deg 0% 45%);
padding-left: 4px;
padding-top: 28px;
padding-top: 2px;
Copy link
Collaborator

Choose a reason for hiding this comment

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

This can be increased to 3 or 4px... It currently looks a little off to me:
image

Copy link
Collaborator

Choose a reason for hiding this comment

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

Actually you might have to rethink the html structure here... For a multiline option the voters' names take up an entire column of space:
image

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

How about now?
image

Copy link
Collaborator

Choose a reason for hiding this comment

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

Hmm, the 1st line being spaced extra from the rest due to the vote count button looks a little odd... I think we want to keep that button in its own column, but keep the option and voter names inline. Would this be possible?

Copy link
Collaborator Author

@roanster007 roanster007 Feb 11, 2024

Choose a reason for hiding this comment

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

image

does this look good?

@@ -8,9 +8,9 @@
</div>
<div>
{{#if completed}}
<strike><strong>{{ task }}</strong>{{#if desc }}: {{ desc }}{{/if}}</strike>
<strike><strong class="task_complete">{{{ task }}}</strong>{{#if desc }}<span class="task_desc_complete"">: </span><span class="description_complete"">{{{ desc }}}</span>{{/if}}</strike>
Copy link
Collaborator

Choose a reason for hiding this comment

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

There's an extra " after the task_desc_complete class... Also, can you explain why these new classes are needed?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Extra " after description_complete class too

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Oh sorry... I missed it. So the reason for these new classes was -- task, : and description are now rendered as separate elements. So without them, sometimes the : is not staying inline, while other times, all three of them go to the next line. So I thought I would enclose them within tags to make them inline separately.

@roanster007 roanster007 force-pushed the iss-12947 branch 2 times, most recently from cf1080f to 1197b5f Compare February 12, 2024 12:57
@timabbott timabbott added the integration review Added by maintainers when a PR may be ready for integration. label Feb 13, 2024
@alya alya removed the maintainer review PR is ready for review by Zulip maintainers. label Feb 16, 2024
This commit creates an inline only markdown processor, that
renders inline patterns.
This commit allows polls to render inline patterns using the
inline markdown processor.

Fixes zulip#21917.
This commit allows todo to render inline patterns using the
inline markdown processor.
@nimishmedatwal
Copy link
Collaborator

I believe this pr also fixes #21674 #16821 #12947 and #21674.

@zulipbot
Copy link
Member

Heads up @roanster007, we just merged some commits that conflict with the changes you made in this pull request! You can review this repository's recent commits to see where the conflicts occur. Please rebase your feature branch against the upstream/main branch and resolve your pull request's merge conflicts accordingly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: widgets Poll and similar widgets feedback wanted has conflicts integration review Added by maintainers when a PR may be ready for integration. priority: high size: XL
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support some Markdown in polls
7 participants