Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
markdown: Inject function for emoticon translations.
Steve Howell17b60efdc769
diff --git a/frontend_tests/node_tests/markdown.js b/frontend_tests/node_tests/markdown.jsindex e9dbd0b5177..125eecc86bc 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 testconst 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.jsindex 230579dda18..befe3962382 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_typeaheadconst 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