Skip to content

Commit

Permalink
poll time widget: Add time widget markdown parser to polls
Browse files Browse the repository at this point in the history
Time widget markdown parser functionality added to poll question header.
The change is brought about by applying `update_elements` function on
the poll question header.And in `rendered_markdown.js` a parsing
function is added to render the timestamp
Fixes zulip#16821
  • Loading branch information
godlike786 committed Mar 5, 2021
1 parent 74c26d1 commit 01eb9e4
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
7 changes: 6 additions & 1 deletion static/js/poll_widget.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ import render_widgets_poll_widget_results from "../templates/widgets/poll_widget

import * as people from "./people";

export class PollData {
const people = require("./people");
const rendered_markdown = require("./rendered_markdown");

class PollData {
// This object just holds data for a poll, although it
// works closely with the widget's concept of how data
// should be represented for rendering, plus how the
Expand Down Expand Up @@ -204,8 +207,10 @@ export function activate(opts) {
const waiting = !is_my_poll && !has_question;
const author_help = is_my_poll && !has_question;

const content = elem.find(".poll-widget");
elem.find(".poll-question-header").toggle(!input_mode);
elem.find(".poll-question-header").text(question);
rendered_markdown.update_elements(content);
elem.find(".poll-edit-question").toggle(can_edit);
update_edit_controls();

Expand Down
20 changes: 20 additions & 0 deletions static/js/rendered_markdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,26 @@ export const update_elements = (content) => {
}
});

content.find("h4.poll-question-header").each(function () {
if ($(this).text().includes("<time:")) {
const text = $(this)
.text()
.match(/<time:(.*)>/)
.pop();
const time_string = $(this)
.text()
.match(/<time:(.*)>/)
.pop();
const rendered_time = timerender.render_markdown_timestamp(parseISO(time_string), text);
$(this).text(
$(this)
.text()
.replace(/<time:(.*)>/, ""),
);
$(this).append(`<time title="${rendered_time.title}">${rendered_time.text}</time>`);
}
});

content.find("span.timestamp-error").each(function () {
const time_str = $(this).text().replace("Invalid time format: ", "");
const text = i18n.t("Invalid time format: __timestamp__", {timestamp: time_str});
Expand Down

0 comments on commit 01eb9e4

Please sign in to comment.