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 Feb 27, 2021
1 parent 9a2e293 commit f60d0cc
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
3 changes: 3 additions & 0 deletions static/js/poll_widget.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const render_widgets_poll_widget = require("../templates/widgets/poll_widget.hbs
const render_widgets_poll_widget_results = require("../templates/widgets/poll_widget_results.hbs");

const people = require("./people");
const rendered_markdown = require("./rendered_markdown");

class PollData {
// This object just holds data for a poll, although it
Expand Down Expand Up @@ -207,8 +208,10 @@ exports.activate = function (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 @@ -166,6 +166,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 f60d0cc

Please sign in to comment.