Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

typeahead: Rename highlighter_html to item_html.

Evy Kassirer20722cea897a
diff --git a/web/src/bootstrap_typeahead.ts b/web/src/bootstrap_typeahead.ts
index 6af49d5817a..0b890f03ed3 100644
--- a/web/src/bootstrap_typeahead.ts
+++ b/web/src/bootstrap_typeahead.ts
@@ -221,7 +221,7 @@ export class Typeahead<ItemType extends string | object> {
items: number;
matcher: (item: ItemType, query: string) => boolean;
sorter: (items: ItemType[], query: string) => ItemType[];
- highlighter_html: (item: ItemType, query: string) => string | undefined;
+ item_html: (item: ItemType, query: string) => string | undefined;
updater: (
item: ItemType,
query: string,
@@ -281,7 +281,7 @@ export class Typeahead<ItemType extends string | object> {
this.items = options.items ?? MAX_ITEMS;
this.matcher = options.matcher ?? ((item, query) => this.defaultMatcher(item, query));
this.sorter = options.sorter;
- this.highlighter_html = options.highlighter_html;
+ this.item_html = options.item_html;
this.updater = options.updater ?? ((items) => this.defaultUpdater(items));
this.$container = $(CONTAINER_HTML);
if (options.non_tippy_parent_element) {
@@ -544,7 +544,7 @@ export class Typeahead<ItemType extends string | object> {
const $items: JQuery[] = final_items.map((item) => {
const $i = $(ITEM_HTML);
this.values.set(the($i), item);
- const item_html = this.highlighter_html(item, this.query) ?? "";
+ const item_html = this.item_html(item, this.query) ?? "";
const $item_html = $i.find("a").html(item_html);
const option_label_html = this.option_label(matching_items, item);
@@ -894,7 +894,7 @@ export class Typeahead<ItemType extends string | object> {
* =========================== */
type TypeaheadOptions<ItemType> = {
- highlighter_html: (item: ItemType, query: string) => string | undefined;
+ item_html: (item: ItemType, query: string) => string | undefined;
items?: number;
source: (query: string, input_element: TypeaheadInputElement) => ItemType[];
// optional options
diff --git a/web/src/composebox_typeahead.ts b/web/src/composebox_typeahead.ts
index 68556b3a151..76e594a14bb 100644
--- a/web/src/composebox_typeahead.ts
+++ b/web/src/composebox_typeahead.ts
@@ -52,10 +52,10 @@ const MAX_LOOKBACK_FOR_TYPEAHEAD_COMPLETION = 60 + 6 + 20;
// **********************************
// They do not do any HTML escaping, at all.
// And your input to them is rendered as though it were HTML by
-// the default highlighter.
+// the default `item_html`.
//
// So if you are not using trusted input, you MUST use a
-// highlighter that escapes (i.e. one that calls
+// custom `item_html` that escapes (i.e. one that calls
// Handlebars.Utils.escapeExpression).
// ---------------- TYPE DECLARATIONS ----------------
@@ -1109,7 +1109,7 @@ export function get_candidates(
return [];
}
-export function content_highlighter_html(item: TypeaheadSuggestion): string | undefined {
+export function content_item_html(item: TypeaheadSuggestion): string | undefined {
switch (item.type) {
case "emoji":
return typeahead_helper.render_emoji(item);
@@ -1397,7 +1397,7 @@ export function initialize_topic_edit_typeahead(
};
return new Typeahead(bootstrap_typeahead_input, {
dropup,
- highlighter_html(item: string): string {
+ item_html(item: string): string {
const is_empty_string_topic = item === "";
const topic_display_name = util.get_final_topic_display_name(item);
return typeahead_helper.render_typeahead_item({
@@ -1457,7 +1457,7 @@ export function initialize_compose_typeahead($element: JQuery<HTMLTextAreaElemen
// O(n) behavior in the number of users in the organization
// inside the typeahead library.
source: get_candidates,
- highlighter_html: content_highlighter_html,
+ item_html: content_item_html,
matcher() {
return true;
},
@@ -1529,7 +1529,7 @@ export function initialize({
return topics_seen_for(compose_state.stream_id());
},
items: max_num_items,
- highlighter_html(item: string): string {
+ item_html(item: string): string {
const is_empty_string_topic = item === "";
const topic_display_name = util.get_final_topic_display_name(item);
return typeahead_helper.render_typeahead_item({
@@ -1572,7 +1572,7 @@ export function initialize({
source: get_pm_people,
items: max_num_items,
dropup: true,
- highlighter_html(item: UserGroupPillData | UserPillData) {
+ item_html(item: UserGroupPillData | UserPillData) {
return typeahead_helper.render_person_or_user_group(item);
},
matcher(): boolean {
diff --git a/web/src/custom_profile_fields_ui.ts b/web/src/custom_profile_fields_ui.ts
index c26c449161d..150c6193c84 100644
--- a/web/src/custom_profile_fields_ui.ts
+++ b/web/src/custom_profile_fields_ui.ts
@@ -375,7 +375,7 @@ export function initialize_custom_pronouns_type_fields(element_id: string): void
sorter(items, query) {
return bootstrap_typeahead.defaultSorter(items, query);
},
- highlighter_html(item) {
+ item_html(item) {
return typeahead_helper.render_typeahead_item({primary: item});
},
});
diff --git a/web/src/pill_typeahead.ts b/web/src/pill_typeahead.ts
index 5e79a37f162..23ce41acc5f 100644
--- a/web/src/pill_typeahead.ts
+++ b/web/src/pill_typeahead.ts
@@ -47,7 +47,7 @@ export function set_up_user(
source(_query: string): UserPillData[] {
return user_pill.typeahead_source(pills, exclude_bots);
},
- highlighter_html(item: UserPillData, _query: string): string {
+ item_html(item: UserPillData, _query: string): string {
return typeahead_helper.render_person(item);
},
matcher(item: UserPillData, query: string): boolean {
@@ -96,7 +96,7 @@ export function set_up_stream(
source(_query: string): StreamPillData[] {
return stream_pill.typeahead_source(pills, opts.invite_streams);
},
- highlighter_html(item: StreamPillData, _query: string): string {
+ item_html(item: StreamPillData, _query: string): string {
return typeahead_helper.render_stream(item);
},
matcher(item: StreamPillData, query: string): boolean {
@@ -147,7 +147,7 @@ export function set_up_user_group(
.user_group_source()
.map((user_group) => ({type: "user_group", ...user_group}));
},
- highlighter_html(item: UserGroupPillData, _query: string): string {
+ item_html(item: UserGroupPillData, _query: string): string {
return typeahead_helper.render_user_group(item);
},
matcher(item: UserGroupPillData, query: string): boolean {
@@ -194,7 +194,7 @@ export function set_up_group_setting_typeahead(
return source;
},
- highlighter_html(item: GroupSettingTypeaheadItem, _query: string): string {
+ item_html(item: GroupSettingTypeaheadItem, _query: string): string {
if (item.type === "user_group") {
return typeahead_helper.render_user_group(item);
}
@@ -320,7 +320,7 @@ export function set_up_combined(
}
return source;
},
- highlighter_html(item: TypeaheadItem, query: string): string {
+ item_html(item: TypeaheadItem, query: string): string {
if (include_streams(query) && item.type === "stream") {
return typeahead_helper.render_stream(item);
}
diff --git a/web/src/search.ts b/web/src/search.ts
index bd819bd6e50..6ab6cae4035 100644
--- a/web/src/search.ts
+++ b/web/src/search.ts
@@ -193,7 +193,7 @@ export function initialize(opts: {on_narrow_search: OnNarrowSearch}): void {
helpOnEmptyStrings: true,
stopAdvance: true,
requireHighlight: false,
- highlighter_html(item: string): string {
+ item_html(item: string): string {
const obj = search_map.get(item);
return render_search_list_item(obj);
},
diff --git a/web/src/settings_playgrounds.ts b/web/src/settings_playgrounds.ts
index 39bb58c7b5f..11b76d86eb2 100644
--- a/web/src/settings_playgrounds.ts
+++ b/web/src/settings_playgrounds.ts
@@ -171,7 +171,7 @@ function build_page(): void {
return [...language_labels.keys()];
},
helpOnEmptyStrings: true,
- highlighter_html: (item: string): string =>
+ item_html: (item: string): string =>
render_typeahead_item({primary: language_labels.get(item)}),
matcher(item: string, query: string): boolean {
const q = query.trim().toLowerCase();
diff --git a/web/src/topic_list.ts b/web/src/topic_list.ts
index 5187674168f..89ff6c7b453 100644
--- a/web/src/topic_list.ts
+++ b/web/src/topic_list.ts
@@ -560,7 +560,7 @@ export function setup_topic_search_typeahead(): void {
}
return [...filter_options.keys()];
},
- highlighter_html(item: string) {
+ item_html(item: string) {
return typeahead_helper.render_topic_state(item);
},
matcher(item: string, query: string) {
diff --git a/web/tests/composebox_typeahead.test.cjs b/web/tests/composebox_typeahead.test.cjs
index 499f0b06ddd..3c7f220cfd4 100644
--- a/web/tests/composebox_typeahead.test.cjs
+++ b/web/tests/composebox_typeahead.test.cjs
@@ -1200,9 +1200,9 @@ test("initialize", ({override, override_rewire, mock_template}) => {
let expected_value = sweden_topics_to_show;
assert.deepEqual(actual_value, expected_value);
- // options.highlighter_html()
+ // options.item_html()
options.query = "Kro";
- actual_value = options.highlighter_html("kronor");
+ actual_value = options.item_html("kronor");
expected_value =
'<div class="typeahead-text-container">\n' +
' <strong class="typeahead-strong-section">kronor</strong></div>\n';
@@ -1210,14 +1210,14 @@ test("initialize", ({override, override_rewire, mock_template}) => {
// Highlighted content should be escaped.
options.query = "<";
- actual_value = options.highlighter_html("<&>");
+ actual_value = options.item_html("<&>");
expected_value =
'<div class="typeahead-text-container">\n' +
' <strong class="typeahead-strong-section">&lt;&amp;&gt;</strong></div>\n';
assert.equal(actual_value, expected_value);
options.query = "even m";
- actual_value = options.highlighter_html("even more ice");
+ actual_value = options.item_html("even more ice");
expected_value =
'<div class="typeahead-text-container">\n' +
' <strong class="typeahead-strong-section">even more ice</strong></div>\n';
@@ -1437,13 +1437,13 @@ test("initialize", ({override, override_rewire, mock_template}) => {
assert.ok(caret_called);
othello.delivery_email = "[email protected]";
- // options.highlighter_html()
+ // options.item_html()
//
- // Again, here we only verify that the highlighter has been set to
- // content_highlighter_html.
+ // Again, here we only verify that the item_html has been set to
+ // content_item_html.
ct.get_or_set_completing_for_tests("mention");
ct.get_or_set_token_for_testing("othello");
- actual_value = options.highlighter_html(othello_item);
+ actual_value = options.item_html(othello_item);
expected_value =
` <span class="zulip-icon zulip-icon-user-circle-offline user-circle-offline user-circle"></span>\n` +
` <img class="typeahead-image" src="/avatar/${othello.user_id}" />\n` +
@@ -1456,7 +1456,7 @@ test("initialize", ({override, override_rewire, mock_template}) => {
ct.get_or_set_completing_for_tests("mention");
ct.get_or_set_token_for_testing("hamletcharacters");
- actual_value = options.highlighter_html(hamletcharacters);
+ actual_value = options.item_html(hamletcharacters);
expected_value =
' <i class="typeahead-image zulip-icon zulip-icon-user-group no-presence-circle" aria-hidden="true"></i>\n' +
'<div class="typeahead-text-container">\n' +
@@ -2256,7 +2256,7 @@ test("tokenizing", () => {
assert.equal(ct.tokenize_compose_str("foo #bar@foo"), "#bar@foo");
});
-test("content_highlighter_html", ({override_rewire}) => {
+test("content_item_html", ({override_rewire}) => {
ct.get_or_set_completing_for_tests("emoji");
const emoji = {emoji_name: "person shrugging", emoji_url: "¯\\_(ツ)_/¯", type: "emoji"};
let th_render_typeahead_item_called = false;
@@ -2264,7 +2264,7 @@ test("content_highlighter_html", ({override_rewire}) => {
assert.deepEqual(item, emoji);
th_render_typeahead_item_called = true;
});
- ct.content_highlighter_html(emoji);
+ ct.content_item_html(emoji);
ct.get_or_set_completing_for_tests("mention");
let th_render_person_called = false;
@@ -2272,14 +2272,14 @@ test("content_highlighter_html", ({override_rewire}) => {
assert.deepEqual(person, othello_item);
th_render_person_called = true;
});
- ct.content_highlighter_html(othello_item);
+ ct.content_item_html(othello_item);
let th_render_user_group_called = false;
override_rewire(typeahead_helper, "render_user_group", (user_group) => {
assert.deepEqual(user_group, backend);
th_render_user_group_called = true;
});
- ct.content_highlighter_html(backend);
+ ct.content_item_html(backend);
// We don't have any fancy rendering for slash commands yet.
ct.get_or_set_completing_for_tests("slash");
@@ -2296,7 +2296,7 @@ test("content_highlighter_html", ({override_rewire}) => {
});
th_render_slash_command_called = true;
});
- ct.content_highlighter_html(me_slash);
+ ct.content_item_html(me_slash);
ct.get_or_set_completing_for_tests("stream");
let th_render_stream_called = false;
@@ -2304,7 +2304,7 @@ test("content_highlighter_html", ({override_rewire}) => {
assert.deepEqual(stream, denmark_stream);
th_render_stream_called = true;
});
- ct.content_highlighter_html(denmark_stream);
+ ct.content_item_html(denmark_stream);
ct.get_or_set_completing_for_tests("syntax");
th_render_typeahead_item_called = false;
@@ -2315,7 +2315,7 @@ test("content_highlighter_html", ({override_rewire}) => {
});
th_render_typeahead_item_called = true;
});
- ct.content_highlighter_html({type: "syntax", language: "py"});
+ ct.content_item_html({type: "syntax", language: "py"});
// Verify that all stub functions have been called.
assert.ok(th_render_typeahead_item_called);
diff --git a/web/tests/pill_typeahead.test.cjs b/web/tests/pill_typeahead.test.cjs
index 96da2803271..4cc688d4611 100644
--- a/web/tests/pill_typeahead.test.cjs
+++ b/web/tests/pill_typeahead.test.cjs
@@ -186,7 +186,7 @@ run_test("set_up_user", ({mock_template, override, override_rewire}) => {
assert.ok(config.stopAdvance);
assert.equal(typeof config.source, "function");
- assert.equal(typeof config.highlighter_html, "function");
+ assert.equal(typeof config.item_html, "function");
assert.equal(typeof config.matcher, "function");
assert.equal(typeof config.sorter, "function");
assert.equal(typeof config.updater, "function");
@@ -194,8 +194,8 @@ run_test("set_up_user", ({mock_template, override, override_rewire}) => {
// test queries
const person_query = "me";
- (function test_highlighter() {
- assert.equal(config.highlighter_html(me_item, person_query), $fake_rendered_person);
+ (function test_item_html() {
+ assert.equal(config.item_html(me_item, person_query), $fake_rendered_person);
})();
(function test_matcher() {
@@ -278,7 +278,7 @@ run_test("set_up_stream", ({mock_template, override, override_rewire}) => {
assert.ok(config.stopAdvance);
assert.equal(typeof config.source, "function");
- assert.equal(typeof config.highlighter_html, "function");
+ assert.equal(typeof config.item_html, "function");
assert.equal(typeof config.matcher, "function");
assert.equal(typeof config.sorter, "function");
assert.equal(typeof config.updater, "function");
@@ -286,11 +286,8 @@ run_test("set_up_stream", ({mock_template, override, override_rewire}) => {
// test queries
const stream_query = "#denmark";
- (function test_highlighter() {
- assert.equal(
- config.highlighter_html(denmark_item, stream_query),
- $fake_rendered_stream,
- );
+ (function test_item_html() {
+ assert.equal(config.item_html(denmark_item, stream_query), $fake_rendered_stream);
})();
(function test_matcher() {
@@ -374,15 +371,15 @@ run_test("set_up_user_group", ({mock_template, override, override_rewire}) => {
assert.ok(config.stopAdvance);
assert.equal(typeof config.source, "function");
- assert.equal(typeof config.highlighter_html, "function");
+ assert.equal(typeof config.item_html, "function");
assert.equal(typeof config.matcher, "function");
assert.equal(typeof config.sorter, "function");
assert.equal(typeof config.updater, "function");
const group_query = "testers";
- (function test_highlighter() {
- assert.equal(config.highlighter_html(testers_item, group_query), $fake_rendered_group);
+ (function test_item_html() {
+ assert.equal(config.item_html(testers_item, group_query), $fake_rendered_group);
})();
(function test_matcher() {
@@ -474,7 +471,7 @@ run_test("set_up_combined", ({mock_template, override, override_rewire}) => {
assert.ok(config.stopAdvance);
assert.equal(typeof config.source, "function");
- assert.equal(typeof config.highlighter_html, "function");
+ assert.equal(typeof config.item_html, "function");
assert.equal(typeof config.matcher, "function");
assert.equal(typeof config.sorter, "function");
assert.equal(typeof config.updater, "function");
@@ -484,31 +481,22 @@ run_test("set_up_combined", ({mock_template, override, override_rewire}) => {
const person_query = "me";
const group_query = "test";
- (function test_highlighter() {
+ (function test_item_html() {
if (opts.stream) {
- // Test stream highlighter_html for widgets that allow stream pills.
- assert.equal(
- config.highlighter_html(denmark_item, stream_query),
- $fake_rendered_stream,
- );
+ // Test stream item_html for widgets that allow stream pills.
+ assert.equal(config.item_html(denmark_item, stream_query), $fake_rendered_stream);
}
if (opts.user_group && opts.user) {
// If user is also allowed along with user_group
// then we should check that each of them rendered correctly.
- assert.equal(
- config.highlighter_html(testers_item, group_query),
- $fake_rendered_group,
- );
- assert.equal(config.highlighter_html(me_item, person_query), $fake_rendered_person);
+ assert.equal(config.item_html(testers_item, group_query), $fake_rendered_group);
+ assert.equal(config.item_html(me_item, person_query), $fake_rendered_person);
}
if (opts.user && !opts.user_group) {
- assert.equal(config.highlighter_html(me_item, person_query), $fake_rendered_person);
+ assert.equal(config.item_html(me_item, person_query), $fake_rendered_person);
}
if (!opts.user && opts.user_group) {
- assert.equal(
- config.highlighter_html(testers_item, group_query),
- $fake_rendered_group,
- );
+ assert.equal(config.item_html(testers_item, group_query), $fake_rendered_group);
}
})();
@@ -770,7 +758,7 @@ run_test("set_up_group_setting_typeahead", ({mock_template, override, override_r
assert.ok(config.stopAdvance);
assert.equal(typeof config.source, "function");
- assert.equal(typeof config.highlighter_html, "function");
+ assert.equal(typeof config.item_html, "function");
assert.equal(typeof config.matcher, "function");
assert.equal(typeof config.sorter, "function");
assert.equal(typeof config.updater, "function");
@@ -779,11 +767,11 @@ run_test("set_up_group_setting_typeahead", ({mock_template, override, override_r
const person_query = "me";
const group_query = "test";
- (function test_highlighter() {
+ (function test_item_html() {
// If user is also allowed along with user_group
// then we should check that each of them rendered correctly.
- assert.equal(config.highlighter_html(testers_item, group_query), $fake_rendered_group);
- assert.equal(config.highlighter_html(me_item, person_query), $fake_rendered_person);
+ assert.equal(config.item_html(testers_item, group_query), $fake_rendered_group);
+ assert.equal(config.item_html(me_item, person_query), $fake_rendered_person);
})();
(function test_matcher() {
diff --git a/web/tests/search.test.cjs b/web/tests/search.test.cjs
index 2d5c79eb562..2eebf721823 100644
--- a/web/tests/search.test.cjs
+++ b/web/tests/search.test.cjs
@@ -117,12 +117,12 @@ run_test("initialize", ({override, override_rewire, mock_template}) => {
const source = opts.source("ver");
assert.deepStrictEqual(source, expected_source_value);
- /* Test highlighter */
+ /* Test item_html */
let expected_value = `<div class="search_list_item">\n <span>Search for ver</span>\n</div>\n`;
- assert.equal(opts.highlighter_html(source[0]), expected_value);
+ assert.equal(opts.item_html(source[0]), expected_value);
expected_value = `<div class="search_list_item">\n <span>Stream Verona</span>\n</div>\n`;
- assert.equal(opts.highlighter_html(source[1]), expected_value);
+ assert.equal(opts.item_html(source[1]), expected_value);
/* Test sorter */
assert.equal(opts.sorter(search_suggestions.strings), search_suggestions.strings);
@@ -205,18 +205,18 @@ run_test("initialize", ({override, override_rewire, mock_template}) => {
const source = opts.source("zo");
assert.deepStrictEqual(source, expected_source_value);
- /* Test highlighter */
+ /* Test item_html */
let expected_value = `<div class="search_list_item">\n <span>Search for zo</span>\n</div>\n`;
- assert.equal(opts.highlighter_html(source[0]), expected_value);
+ assert.equal(opts.item_html(source[0]), expected_value);
expected_value = `<div class="search_list_item">\n <span>sent by</span>\n <span class="pill-container">\n <div class='pill ' tabindex=0>\n <img class="pill-image" src="https://secure.gravatar.com/avatar/0f030c97ab51312c7bbffd3966198ced?d&#x3D;identicon&amp;version&#x3D;1" />\n <div class="pill-image-border"></div>\n <span class="pill-label">\n <span class="pill-value">\n Zoe\n </span></span>\n <div class="exit">\n <a role="button" class="zulip-icon zulip-icon-close pill-close-button"></a>\n </div>\n</div>\n </span>\n</div>\n`;
- assert.equal(opts.highlighter_html(source[1]), expected_value);
+ assert.equal(opts.item_html(source[1]), expected_value);
expected_value = `<div class="search_list_item">\n <span>direct messages with</span>\n <span class="pill-container">\n <div class='pill ' tabindex=0>\n <img class="pill-image" src="https://secure.gravatar.com/avatar/0f030c97ab51312c7bbffd3966198ced?d&#x3D;identicon&amp;version&#x3D;1" />\n <div class="pill-image-border"></div>\n <span class="pill-label">\n <span class="pill-value">\n Zoe\n </span></span>\n <div class="exit">\n <a role="button" class="zulip-icon zulip-icon-close pill-close-button"></a>\n </div>\n</div>\n </span>\n</div>\n`;
- assert.equal(opts.highlighter_html(source[2]), expected_value);
+ assert.equal(opts.item_html(source[2]), expected_value);
expected_value = `<div class="search_list_item">\n <span>group direct messages including</span>\n <span class="pill-container">\n <div class='pill ' tabindex=0>\n <img class="pill-image" src="https://secure.gravatar.com/avatar/0f030c97ab51312c7bbffd3966198ced?d&#x3D;identicon&amp;version&#x3D;1" />\n <div class="pill-image-border"></div>\n <span class="pill-label">\n <span class="pill-value">\n Zoe\n </span></span>\n <div class="exit">\n <a role="button" class="zulip-icon zulip-icon-close pill-close-button"></a>\n </div>\n</div>\n </span>\n</div>\n`;
- assert.equal(opts.highlighter_html(source[3]), expected_value);
+ assert.equal(opts.item_html(source[3]), expected_value);
/* Test sorter */
assert.equal(opts.sorter(search_suggestions.strings), search_suggestions.strings);