diff --git a/frontend_tests/node_tests/markdown.js b/frontend_tests/node_tests/markdown.js index e9dbd0b517..125eecc86b 100644 --- a/frontend_tests/node_tests/markdown.js +++ b/frontend_tests/node_tests/markdown.js @@ -771,10 +771,16 @@ test("backend_only_linkifiers", () => { }); test("translate_emoticons_to_names", () => { + const get_emoticon_translations = emoji.get_emoticon_translations; + + function translate_emoticons_to_names(src) { + return markdown.translate_emoticons_to_names({src, get_emoticon_translations}); + } + // Simple test const test_text = "Testing :)"; const expected = "Testing :smile:"; - const result = markdown.translate_emoticons_to_names(test_text); + const result = translate_emoticons_to_names(test_text); assert.equal(result, expected); // Extensive tests. @@ -813,7 +819,7 @@ test("translate_emoticons_to_names", () => { expected: `Hello ${full_name}!`, }, ]) { - const result = markdown.translate_emoticons_to_names(original); + const result = translate_emoticons_to_names(original); assert.equal(result, expected); } } diff --git a/static/js/markdown.js b/static/js/markdown.js index 230579dda1..befe396238 100644 --- a/static/js/markdown.js +++ b/static/js/markdown.js @@ -39,9 +39,9 @@ function contains_preview_link(content) { return preview_regexes.some((re) => re.test(content)); } -export function translate_emoticons_to_names(text) { +export function translate_emoticons_to_names({src, get_emoticon_translations}) { // Translates emoticons in a string to their colon syntax. - let translated = text; + let translated = src; let replacement_text; const terminal_symbols = ",.;?!()[] \"'\n\t"; // From composebox_typeahead const symbols_except_space = terminal_symbols.replace(" ", ""); @@ -67,7 +67,7 @@ export function translate_emoticons_to_names(text) { return match; }; - for (const translation of helpers.get_emoticon_translations()) { + for (const translation of get_emoticon_translations()) { // We can't pass replacement_text directly into // emoticon_replacer, because emoticon_replacer is // a callback for `replace()`. Instead we just mutate @@ -490,7 +490,10 @@ export function parse({raw_content, helper_config}) { // In this scenario, the message has to be from the user, so the only // requirement should be that they have the setting on. - return translate_emoticons_to_names(src); + return translate_emoticons_to_names({ + src, + get_emoticon_translations: helper_config.get_emoticon_translations, + }); } // Disable headings