js: Fix type issue with FormatJS rich text elements.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
Anders Kaseorg 2022-11-03 12:14:03 -07:00 committed by Tim Abbott
parent b582d5886c
commit 3a718d786f
10 changed files with 54 additions and 22 deletions

View File

@ -247,7 +247,7 @@ locally to the translation:
```js
$t_html(
{defaultMessage: "<b>HTML</b> linking to the <z-link>login page</z-link>"},
{"z-link": (content_html) => `<a href="/login/">${content_html}</a>`},
{"z-link": (content_html) => `<a href="/login/">${content_html.join("")}</a>`},
)
```

View File

@ -60,7 +60,7 @@ run_test("$tr", () => {
},
{
stream_name: "l'abonnement",
"z-link": (content_html) => `<a href='#streams/all'>${content_html}</a>`,
"z-link": (content_html) => `<a href='#streams/all'>${content_html.join("")}</a>`,
},
),
"<p>Le canal <b>l&#39;abonnement</b> n'existe pas.</p><p>Gérez vos abonnements <a href='#streams/all'>sur votre page canaux</a>.</p>",

View File

@ -13,7 +13,7 @@ exports.intl = createIntl(
["b", "code", "em", "i", "kbd", "p", "strong"].map((tag) => [
tag,
/* istanbul ignore next */
(content_html) => `<${tag}>${content_html}</${tag}>`,
(content_html) => `<${tag}>${content_html.join("")}</${tag}>`,
]),
),
},
@ -33,7 +33,7 @@ exports.$t = (descriptor, values) =>
const default_html_elements = Object.fromEntries(
["b", "code", "em", "i", "kbd", "p", "strong"].map((tag) => [
tag,
(content_html) => `<${tag}>${content_html}</${tag}>`,
(content_html) => `<${tag}>${content_html.join("")}</${tag}>`,
]),
);

View File

@ -392,7 +392,8 @@ export function validation_error(error_type, stream_name) {
},
{
stream_name,
"z-link": (content_html) => `<a href='#streams/all'>${content_html}</a>`,
"z-link": (content_html) =>
`<a href='#streams/all'>${content_html.join("")}</a>`,
},
);
compose_error.show(response, $("#stream_message_recipient_stream"));

View File

@ -30,7 +30,7 @@ export const $t = intl.formatMessage.bind(intl);
export const default_html_elements = Object.fromEntries(
["b", "code", "em", "i", "kbd", "p", "strong"].map((tag) => [
tag,
(content_html: string) => `<${tag}>${content_html}</${tag}>`,
(content_html: string[]) => `<${tag}>${content_html.join("")}</${tag}>`,
]),
);

View File

@ -141,7 +141,9 @@ def zulip():
},
{
"z-link": (content_html) =>
`<a target="_blank" rel="noopener noreferrer" href="https://pygments.org/docs/lexers/">${content_html}</a>`,
`<a target="_blank" rel="noopener noreferrer" href="https://pygments.org/docs/lexers/">${content_html.join(
"",
)}</a>`,
},
),
},
@ -177,7 +179,9 @@ This text won't be visible until the user clicks.
},
{
"z-link": (content_html) =>
`<a target="_blank" rel="noopener noreferrer" href="https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet#wiki-tables">${content_html}</a>`,
`<a target="_blank" rel="noopener noreferrer" href="https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet#wiki-tables">${content_html.join(
"",
)}</a>`,
},
),
},

View File

@ -15,7 +15,8 @@ const SPECTATOR_STREAM_NARROW_BANNER = {
defaultMessage: "This is not a <z-link>publicly accessible</z-link> conversation.",
},
{
"z-link": (content_html) => `<a href="/help/public-access-option">${content_html}</a>`,
"z-link": (content_html) =>
`<a href="/help/public-access-option">${content_html.join("")}</a>`,
},
),
};
@ -74,7 +75,9 @@ function pick_empty_narrow_banner() {
},
{
"z-link": (content_html) =>
`<a href="#" class="empty_feed_compose_stream">${content_html}</a>`,
`<a href="#" class="empty_feed_compose_stream">${content_html.join(
"",
)}</a>`,
},
),
};
@ -162,7 +165,7 @@ function pick_empty_narrow_banner() {
},
{
"z-link": (content_html) =>
`<a href="/help/star-a-message">${content_html}</a>`,
`<a href="/help/star-a-message">${content_html.join("")}</a>`,
},
),
};
@ -175,7 +178,9 @@ function pick_empty_narrow_banner() {
},
{
"z-link": (content_html) =>
`<a href="/help/mention-a-user-or-group">${content_html}</a>`,
`<a href="/help/mention-a-user-or-group">${content_html.join(
"",
)}</a>`,
},
),
};
@ -191,7 +196,9 @@ function pick_empty_narrow_banner() {
// TODO: The href here is a bit weird; we probably want to migrate
// this to a button element down the line.
"z-link": (content_html) =>
`<a href="#" class="empty_feed_compose_private">${content_html}</a>`,
`<a href="#" class="empty_feed_compose_private">${content_html.join(
"",
)}</a>`,
},
),
};
@ -241,7 +248,9 @@ function pick_empty_narrow_banner() {
},
{
"z-button": (content_html) =>
`<button class="button white rounded stream_sub_unsub_button sea-green" type="button" name="subscription">${content_html}</button>`,
`<button class="button white rounded stream_sub_unsub_button sea-green" type="button" name="subscription">${content_html.join(
"",
)}</button>`,
},
),
};
@ -286,7 +295,9 @@ function pick_empty_narrow_banner() {
},
{
"z-link": (content_html) =>
`<a href="#" class="empty_feed_compose_private">${content_html}</a>`,
`<a href="#" class="empty_feed_compose_private">${content_html.join(
"",
)}</a>`,
},
),
};
@ -301,7 +312,9 @@ function pick_empty_narrow_banner() {
},
{
"z-link": (content_html) =>
`<a href="#" class="empty_feed_compose_private">${content_html}</a>`,
`<a href="#" class="empty_feed_compose_private">${content_html.join(
"",
)}</a>`,
},
),
};
@ -314,7 +327,9 @@ function pick_empty_narrow_banner() {
},
{
"z-link": (content_html) =>
`<a href="#" class="empty_feed_compose_private">${content_html}</a>`,
`<a href="#" class="empty_feed_compose_private">${content_html.join(
"",
)}</a>`,
},
),
};
@ -341,7 +356,9 @@ function pick_empty_narrow_banner() {
},
{
"z-link": (content_html) =>
`<a href="#" class="empty_feed_compose_private">${content_html}</a>`,
`<a href="#" class="empty_feed_compose_private">${content_html.join(
"",
)}</a>`,
},
),
};

View File

@ -57,7 +57,9 @@ export function show_user_list(message_id) {
{
num_of_people: users.length,
"z-link": (content_html) =>
`<a href="/help/read-receipts">${content_html}</a>`,
`<a href="/help/read-receipts">${content_html.join(
"",
)}</a>`,
},
),
);

View File

@ -714,7 +714,9 @@ export function set_up() {
},
{
"z-link": (content_html) =>
`<a target="_blank" href="/#organization/organization-profile">${content_html}</a>`,
`<a target="_blank" href="/#organization/organization-profile">${content_html.join(
"",
)}</a>`,
},
);
let rendered_error_msg;

View File

@ -104,7 +104,10 @@ function user_default_language_modal_post_render() {
defaultMessage:
"Saved. Please <z-link>reload</z-link> for the change to take effect.",
},
{"z-link": (content_html) => `<a class='reload_link'>${content_html}</a>`},
{
"z-link": (content_html) =>
`<a class='reload_link'>${content_html.join("")}</a>`,
},
),
true,
);
@ -196,7 +199,10 @@ export function set_up(settings_panel) {
defaultMessage:
"Saved. Please <z-link>reload</z-link> for the change to take effect.",
},
{"z-link": (content_html) => `<a class='reload_link'>${content_html}</a>`},
{
"z-link": (content_html) =>
`<a class='reload_link'>${content_html.join("")}</a>`,
},
),
true,
);