mirror of
https://github.com/zulip/zulip.git
synced 2025-11-03 05:23:35 +00:00
markdown: Inject function for emoticon translations.
We want our parser to be as re-entrant as possible.
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user