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

poll time widget: Add time widget markdown parser to polls
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

[Poll Time Widget] Add time widget markdown parser to poll question

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.
Fixes zulip#16821

[Poll Time Widget] Add time widget markdown parser to poll question

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

Remove unused-vars
Fixes zulip#16821

Fixed linting issue in `poll_widget.js`

Fixes zulip#16821
  • Loading branch information
godlike786 committed Mar 15, 2021
1 parent a551b96 commit fb26470
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
12 changes: 11 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,24 @@
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", {});

markdown.initialize([], markdown_config.get_helpers());

run_test("PollData my question", () => {
const is_my_poll = true;
const question = "Favorite color?";
Expand Down
13 changes: 11 additions & 2 deletions static/js/poll_widget.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import render_widgets_poll_widget from "../templates/widgets/poll_widget.hbs";
import render_widgets_poll_widget_results from "../templates/widgets/poll_widget_results.hbs";

import * as people from "./people";
const marked = require("../third/marked/lib/marked");

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

export class PollData {
// This object just holds data for a poll, although it
Expand Down Expand Up @@ -204,8 +207,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-question-header");
elem.find(".poll-question-header").toggle(!input_mode);
elem.find(".poll-question-header").text(question);
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 fb26470

Please sign in to comment.