Skip to content

Commit

Permalink
[Poll Time Widget] Add time widget markdown parser to poll question
Browse files Browse the repository at this point in the history
The time widget markdown parser is added to poll question header. This
is done giving a `marked` question value to the poll question header and
upon updating the elements using `rendered_markdown`, the `<time>` tags
get updated accordingly. The `poll_widget` test file is modified to
incorporate markdown processing.
Fixes zulip#16821
  • Loading branch information
godlike786 committed Mar 5, 2021
1 parent 5af58b8 commit 34c1cd8
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
14 changes: 13 additions & 1 deletion frontend_tests/node_tests/poll_widget.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,26 @@
const {strict: assert} = require("assert");

const {stub_templates} = require("../zjsunit/handlebars");
const {zrequire} = require("../zjsunit/namespace");
const {zrequire, set_global} = require("../zjsunit/namespace");
const {run_test} = require("../zjsunit/test");
const $ = require("../zjsunit/zjquery");

const markdown = zrequire("markdown");
const markdown_config = zrequire("markdown_config");
const poll_widget = zrequire("poll_widget");

const people = zrequire("people");

zrequire("message_store");
zrequire("user_groups");
zrequire("stream_data");
zrequire("hash_util");
set_global("page_params", {});

const return_false = () => false;
const return_true = () => true;
markdown.initialize([], markdown_config.get_helpers());

run_test("PollData my question", () => {
const is_my_poll = true;
const question = "Favorite color?";
Expand Down
10 changes: 7 additions & 3 deletions static/js/poll_widget.js
Original file line number Diff line number Diff line change
Expand Up @@ -209,10 +209,14 @@ 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");
const content = elem.find(".poll-question-header");
elem.find(".poll-question-header").toggle(!input_mode);
elem.find(".poll-question-header").append(marked(question));
rendered_markdown.update_elements(content);
if (/<time:([^>]+)>/.test(question)) {
elem.find(".poll-question-header").append(marked(question));
rendered_markdown.update_elements(content);
} else {
elem.find(".poll-question-header").text(question);
}
elem.find(".poll-edit-question").toggle(can_edit);
update_edit_controls();

Expand Down

0 comments on commit 34c1cd8

Please sign in to comment.