markdown: Move helper function to rendered_markdown.js.

This commit is contained in:
Rohitt Vashishtha 2020-05-21 07:45:27 +05:30 committed by Tim Abbott
parent fa9431c0a4
commit bb579742a2
4 changed files with 21 additions and 19 deletions

View File

@ -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 :)';

View File

@ -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');
});

View File

@ -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;

View File

@ -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);
}
}
});