From bb579742a2846496cb58ce2c4ead74c5415e6d69 Mon Sep 17 00:00:00 2001 From: Rohitt Vashishtha Date: Thu, 21 May 2020 07:45:27 +0530 Subject: [PATCH] markdown: Move helper function to rendered_markdown.js. --- frontend_tests/node_tests/markdown.js | 9 --------- frontend_tests/node_tests/rendered_markdown.js | 11 +++++++++++ static/js/markdown.js | 9 --------- static/js/rendered_markdown.js | 11 ++++++++++- 4 files changed, 21 insertions(+), 19 deletions(-) create mode 100644 frontend_tests/node_tests/rendered_markdown.js diff --git a/frontend_tests/node_tests/markdown.js b/frontend_tests/node_tests/markdown.js index a12ddfcf56..b4a8e94c54 100644 --- a/frontend_tests/node_tests/markdown.js +++ b/frontend_tests/node_tests/markdown.js @@ -594,15 +594,6 @@ run_test('katex_throws_unexpected_exceptions', () => { markdown.apply_markdown(message); }); -run_test('misc_helpers', () => { - const elem = $('.user-mention'); - markdown.set_name_in_mention_element(elem, 'Aaron'); - assert.equal(elem.text(), '@Aaron'); - elem.addClass('silent'); - markdown.set_name_in_mention_element(elem, 'Aaron, but silent'); - assert.equal(elem.text(), 'Aaron, but silent'); -}); - run_test('translate_emoticons_to_names', () => { // Simple test const test_text = 'Testing :)'; diff --git a/frontend_tests/node_tests/rendered_markdown.js b/frontend_tests/node_tests/rendered_markdown.js new file mode 100644 index 0000000000..8f9105a21d --- /dev/null +++ b/frontend_tests/node_tests/rendered_markdown.js @@ -0,0 +1,11 @@ +const rm = zrequire('rendered_markdown'); +set_global('$', global.make_zjquery()); + +run_test('misc_helpers', () => { + const elem = $.create('.user-mention'); + rm.set_name_in_mention_element(elem, 'Aaron'); + assert.equal(elem.text(), '@Aaron'); + elem.addClass('silent'); + rm.set_name_in_mention_element(elem, 'Aaron, but silent'); + assert.equal(elem.text(), 'Aaron, but silent'); +}); diff --git a/static/js/markdown.js b/static/js/markdown.js index f3a98ca244..a5eb10577a 100644 --- a/static/js/markdown.js +++ b/static/js/markdown.js @@ -28,15 +28,6 @@ const backend_only_markdown_re = [ /[^\s]*(?:twitter|youtube).com\/[^\s]*/, ]; -// Helper function to update a mentioned user's name. -exports.set_name_in_mention_element = function (element, name) { - if ($(element).hasClass('silent')) { - $(element).text(name); - } else { - $(element).text("@" + name); - } -}; - exports.translate_emoticons_to_names = (text) => { // Translates emoticons in a string to their colon syntax. let translated = text; diff --git a/static/js/rendered_markdown.js b/static/js/rendered_markdown.js index 988757f8e7..e94f708275 100644 --- a/static/js/rendered_markdown.js +++ b/static/js/rendered_markdown.js @@ -33,6 +33,15 @@ function get_user_group_id_for_mention_button(elem) { return; } +// Helper function to update a mentioned user's name. +exports.set_name_in_mention_element = function (element, name) { + if ($(element).hasClass('silent')) { + $(element).text(name); + } else { + $(element).text("@" + name); + } +}; + exports.update_elements = (content) => { // Set the rtl class if the text has an rtl direction if (rtl.get_direction(content.text()) === 'rtl') { @@ -56,7 +65,7 @@ exports.update_elements = (content) => { if (person !== undefined) { // Note that person might be undefined in some // unpleasant corner cases involving data import. - markdown.set_name_in_mention_element(this, person.full_name); + exports.set_name_in_mention_element(this, person.full_name); } } });