diff --git a/resources/js/components/linkified-text.tsx b/resources/js/components/linkified-text.tsx index b233e994ea..d972236ea9 100644 --- a/resources/js/components/linkified-text.tsx +++ b/resources/js/components/linkified-text.tsx @@ -1,4 +1,5 @@ import { Link, usePage } from '@inertiajs/react'; +import { Root as TooltipRoot } from '@radix-ui/react-tooltip'; import { Fragment } from 'react'; import type { ReactNode, SVGAttributes } from 'react'; import CommitController from '@/actions/App/Http/Controllers/CommitController'; @@ -12,10 +13,12 @@ import { CodebergIcon } from '@/components/codeberg-icon'; import { GitHubIcon } from '@/components/github-icon'; import { GitLabIcon } from '@/components/gitlab-icon'; import { GuildIcon } from '@/components/guild-icon'; +import { TooltipContent, TooltipTrigger } from '@/components/ui/tooltip'; import { UserPreview } from '@/components/user-preview'; import { typedProse, withoutCode } from '@/lib/code'; import type { Color } from '@/lib/colors'; import { colorsIn } from '@/lib/colors'; +import flagNames from '@/lib/flag-names.json'; import { hashtagPattern } from '@/lib/hashtags'; import { mentionPattern } from '@/lib/mentions'; import { pasteisParts } from '@/lib/pasteis'; @@ -34,6 +37,9 @@ import type { GuildBadge, GuildMentions } from '@/types/guild'; // A link to a commit on dev/null itself, nothing after its id, so it can show as the author and the commit's hash. const commitLinkPattern = /^https?:\/\/(?:www\.)?dev-null\.sh\/@([A-Za-z0-9](?:[A-Za-z0-9]|-(?=[A-Za-z0-9])){0,38})\/commits\/([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})$/i; +const flagPattern = /\p{Regional_Indicator}{2}/gu; +// Current flag names from https://en.wikipedia.org/wiki/Regional_indicator_symbol +const flagNamesByEmoji = new Map(Object.entries(flagNames)); const gitHubHostPattern = /^(?:www\.)?github\.com$/i; const gitHubOwnerPattern = /^[A-Za-z0-9](?:[A-Za-z0-9]|-(?=[A-Za-z0-9])){0,38}$/; @@ -739,11 +745,13 @@ export function Hashtag({ ); } +type RenderProse = (text: string, offset: number) => ReactNode[]; + function withHashtags( text: string, offset: number, hashtags: RegExpExecArray[], - pasteisMode: boolean, + renderProse: RenderProse, guildMentions: GuildMentions | undefined, ): ReactNode[] { const parts: ReactNode[] = []; @@ -757,11 +765,7 @@ function withHashtags( } parts.push( - ...withWordmarks( - text.slice(position, index), - offset + position, - pasteisMode, - ), + ...renderProse(text.slice(position, index), offset + position), { + const parts: ReactNode[] = []; + let position = 0; + + const slice = prose.slice(offset, offset + text.length); + + for (const flag of slice.matchAll(flagPattern)) { + const name = flagNamesByEmoji.get(flag[0]); + + if (name === undefined) { + continue; + } + + parts.push( + ...withWordmarks( + text.slice(position, flag.index), + offset + position, + pasteisMode, + ), + // Keep the narrow inline trigger mounted so one pointer entry opens the tooltip. + + + + {flag[0]} + + + {name} + , + ); + + position = flag.index + flag[0].length; + } + + parts.push( + ...withWordmarks( + text.slice(position), + offset + position, + pasteisMode, + ), + ); + + return parts; + }; let position = 0; for (const match of text.matchAll(urlPattern)) { @@ -980,7 +1025,7 @@ export function LinkifiedText({ organizationMentions, colors, hashtags, - pasteisMode, + renderProse, isStatic, linksEveryMention, guildMentions, @@ -1028,7 +1073,7 @@ export function LinkifiedText({ organizationMentions, colors, hashtags, - pasteisMode, + renderProse, isStatic, linksEveryMention, guildMentions, diff --git a/resources/js/lib/flag-names.json b/resources/js/lib/flag-names.json new file mode 100644 index 0000000000..74672432d7 --- /dev/null +++ b/resources/js/lib/flag-names.json @@ -0,0 +1,261 @@ +{ + "๐Ÿ‡ฆ๐Ÿ‡จ": "Ascension Island", + "๐Ÿ‡ฆ๐Ÿ‡ฉ": "Andorra", + "๐Ÿ‡ฆ๐Ÿ‡ช": "United Arab Emirates", + "๐Ÿ‡ฆ๐Ÿ‡ซ": "Afghanistan", + "๐Ÿ‡ฆ๐Ÿ‡ฌ": "Antigua & Barbuda", + "๐Ÿ‡ฆ๐Ÿ‡ฎ": "Anguilla", + "๐Ÿ‡ฆ๐Ÿ‡ฑ": "Albania", + "๐Ÿ‡ฆ๐Ÿ‡ฒ": "Armenia", + "๐Ÿ‡ฆ๐Ÿ‡ด": "Angola", + "๐Ÿ‡ฆ๐Ÿ‡ถ": "Antarctica", + "๐Ÿ‡ฆ๐Ÿ‡ท": "Argentina", + "๐Ÿ‡ฆ๐Ÿ‡ธ": "American Samoa", + "๐Ÿ‡ฆ๐Ÿ‡น": "Austria", + "๐Ÿ‡ฆ๐Ÿ‡บ": "Australia", + "๐Ÿ‡ฆ๐Ÿ‡ผ": "Aruba", + "๐Ÿ‡ฆ๐Ÿ‡ฝ": "ร…land Islands", + "๐Ÿ‡ฆ๐Ÿ‡ฟ": "Azerbaijan", + "๐Ÿ‡ง๐Ÿ‡ฆ": "Bosnia & Herzegovina", + "๐Ÿ‡ง๐Ÿ‡ง": "Barbados", + "๐Ÿ‡ง๐Ÿ‡ฉ": "Bangladesh", + "๐Ÿ‡ง๐Ÿ‡ช": "Belgium", + "๐Ÿ‡ง๐Ÿ‡ซ": "Burkina Faso", + "๐Ÿ‡ง๐Ÿ‡ฌ": "Bulgaria", + "๐Ÿ‡ง๐Ÿ‡ญ": "Bahrain", + "๐Ÿ‡ง๐Ÿ‡ฎ": "Burundi", + "๐Ÿ‡ง๐Ÿ‡ฏ": "Benin", + "๐Ÿ‡ง๐Ÿ‡ฑ": "St. Barthรฉlemy", + "๐Ÿ‡ง๐Ÿ‡ฒ": "Bermuda", + "๐Ÿ‡ง๐Ÿ‡ณ": "Brunei", + "๐Ÿ‡ง๐Ÿ‡ด": "Bolivia", + "๐Ÿ‡ง๐Ÿ‡ถ": "Caribbean Netherlands", + "๐Ÿ‡ง๐Ÿ‡ท": "Brazil", + "๐Ÿ‡ง๐Ÿ‡ธ": "Bahamas", + "๐Ÿ‡ง๐Ÿ‡น": "Bhutan", + "๐Ÿ‡ง๐Ÿ‡ป": "Bouvet Island", + "๐Ÿ‡ง๐Ÿ‡ผ": "Botswana", + "๐Ÿ‡ง๐Ÿ‡พ": "Belarus", + "๐Ÿ‡ง๐Ÿ‡ฟ": "Belize", + "๐Ÿ‡จ๐Ÿ‡ฆ": "Canada", + "๐Ÿ‡จ๐Ÿ‡จ": "Cocos (Keeling) Islands", + "๐Ÿ‡จ๐Ÿ‡ฉ": "Congo-Kinshasa", + "๐Ÿ‡จ๐Ÿ‡ซ": "Central African Republic", + "๐Ÿ‡จ๐Ÿ‡ฌ": "Congo-Brazzaville", + "๐Ÿ‡จ๐Ÿ‡ญ": "Switzerland", + "๐Ÿ‡จ๐Ÿ‡ฎ": "Cรดte d'Ivoire", + "๐Ÿ‡จ๐Ÿ‡ฐ": "Cook Islands", + "๐Ÿ‡จ๐Ÿ‡ฑ": "Chile", + "๐Ÿ‡จ๐Ÿ‡ฒ": "Cameroon", + "๐Ÿ‡จ๐Ÿ‡ณ": "China", + "๐Ÿ‡จ๐Ÿ‡ด": "Colombia", + "๐Ÿ‡จ๐Ÿ‡ต": "Clipperton Island", + "๐Ÿ‡จ๐Ÿ‡ถ": "Sark", + "๐Ÿ‡จ๐Ÿ‡ท": "Costa Rica", + "๐Ÿ‡จ๐Ÿ‡บ": "Cuba", + "๐Ÿ‡จ๐Ÿ‡ป": "Cape Verde", + "๐Ÿ‡จ๐Ÿ‡ผ": "Curaรงao", + "๐Ÿ‡จ๐Ÿ‡ฝ": "Christmas Island", + "๐Ÿ‡จ๐Ÿ‡พ": "Cyprus", + "๐Ÿ‡จ๐Ÿ‡ฟ": "Czechia", + "๐Ÿ‡ฉ๐Ÿ‡ช": "Germany", + "๐Ÿ‡ฉ๐Ÿ‡ฌ": "Diego Garcia", + "๐Ÿ‡ฉ๐Ÿ‡ฏ": "Djibouti", + "๐Ÿ‡ฉ๐Ÿ‡ฐ": "Denmark", + "๐Ÿ‡ฉ๐Ÿ‡ฒ": "Dominica", + "๐Ÿ‡ฉ๐Ÿ‡ด": "Dominican Republic", + "๐Ÿ‡ฉ๐Ÿ‡ฟ": "Algeria", + "๐Ÿ‡ช๐Ÿ‡ฆ": "Ceuta & Melilla", + "๐Ÿ‡ช๐Ÿ‡จ": "Ecuador", + "๐Ÿ‡ช๐Ÿ‡ช": "Estonia", + "๐Ÿ‡ช๐Ÿ‡ฌ": "Egypt", + "๐Ÿ‡ช๐Ÿ‡ญ": "Western Sahara", + "๐Ÿ‡ช๐Ÿ‡ท": "Eritrea", + "๐Ÿ‡ช๐Ÿ‡ธ": "Spain", + "๐Ÿ‡ช๐Ÿ‡น": "Ethiopia", + "๐Ÿ‡ช๐Ÿ‡บ": "European Union", + "๐Ÿ‡ซ๐Ÿ‡ฎ": "Finland", + "๐Ÿ‡ซ๐Ÿ‡ฏ": "Fiji", + "๐Ÿ‡ซ๐Ÿ‡ฐ": "Falkland Islands", + "๐Ÿ‡ซ๐Ÿ‡ฒ": "Micronesia", + "๐Ÿ‡ซ๐Ÿ‡ด": "Faroe Islands", + "๐Ÿ‡ซ๐Ÿ‡ท": "France", + "๐Ÿ‡ฌ๐Ÿ‡ฆ": "Gabon", + "๐Ÿ‡ฌ๐Ÿ‡ง": "United Kingdom", + "๐Ÿ‡ฌ๐Ÿ‡ฉ": "Grenada", + "๐Ÿ‡ฌ๐Ÿ‡ช": "Georgia", + "๐Ÿ‡ฌ๐Ÿ‡ซ": "French Guiana", + "๐Ÿ‡ฌ๐Ÿ‡ฌ": "Guernsey", + "๐Ÿ‡ฌ๐Ÿ‡ญ": "Ghana", + "๐Ÿ‡ฌ๐Ÿ‡ฎ": "Gibraltar", + "๐Ÿ‡ฌ๐Ÿ‡ฑ": "Greenland", + "๐Ÿ‡ฌ๐Ÿ‡ฒ": "Gambia", + "๐Ÿ‡ฌ๐Ÿ‡ณ": "Guinea", + "๐Ÿ‡ฌ๐Ÿ‡ต": "Guadeloupe", + "๐Ÿ‡ฌ๐Ÿ‡ถ": "Equatorial Guinea", + "๐Ÿ‡ฌ๐Ÿ‡ท": "Greece", + "๐Ÿ‡ฌ๐Ÿ‡ธ": "South Georgia & South Sandwich Islands", + "๐Ÿ‡ฌ๐Ÿ‡น": "Guatemala", + "๐Ÿ‡ฌ๐Ÿ‡บ": "Guam", + "๐Ÿ‡ฌ๐Ÿ‡ผ": "Guinea-Bissau", + "๐Ÿ‡ฌ๐Ÿ‡พ": "Guyana", + "๐Ÿ‡ญ๐Ÿ‡ฐ": "Hong Kong SAR China", + "๐Ÿ‡ญ๐Ÿ‡ฒ": "Heard Island & McDonald Islands", + "๐Ÿ‡ญ๐Ÿ‡ณ": "Honduras", + "๐Ÿ‡ญ๐Ÿ‡ท": "Croatia", + "๐Ÿ‡ญ๐Ÿ‡น": "Haiti", + "๐Ÿ‡ญ๐Ÿ‡บ": "Hungary", + "๐Ÿ‡ฎ๐Ÿ‡จ": "Canary Islands", + "๐Ÿ‡ฎ๐Ÿ‡ฉ": "Indonesia", + "๐Ÿ‡ฎ๐Ÿ‡ช": "Ireland", + "๐Ÿ‡ฎ๐Ÿ‡ฑ": "Israel", + "๐Ÿ‡ฎ๐Ÿ‡ฒ": "Isle of Man", + "๐Ÿ‡ฎ๐Ÿ‡ณ": "India", + "๐Ÿ‡ฎ๐Ÿ‡ด": "British Indian Ocean Territory", + "๐Ÿ‡ฎ๐Ÿ‡ถ": "Iraq", + "๐Ÿ‡ฎ๐Ÿ‡ท": "Iran", + "๐Ÿ‡ฎ๐Ÿ‡ธ": "Iceland", + "๐Ÿ‡ฎ๐Ÿ‡น": "Italy", + "๐Ÿ‡ฏ๐Ÿ‡ช": "Jersey", + "๐Ÿ‡ฏ๐Ÿ‡ฒ": "Jamaica", + "๐Ÿ‡ฏ๐Ÿ‡ด": "Jordan", + "๐Ÿ‡ฏ๐Ÿ‡ต": "Japan", + "๐Ÿ‡ฐ๐Ÿ‡ช": "Kenya", + "๐Ÿ‡ฐ๐Ÿ‡ฌ": "Kyrgyzstan", + "๐Ÿ‡ฐ๐Ÿ‡ญ": "Cambodia", + "๐Ÿ‡ฐ๐Ÿ‡ฎ": "Kiribati", + "๐Ÿ‡ฐ๐Ÿ‡ฒ": "Comoros", + "๐Ÿ‡ฐ๐Ÿ‡ณ": "St. Kitts & Nevis", + "๐Ÿ‡ฐ๐Ÿ‡ต": "North Korea", + "๐Ÿ‡ฐ๐Ÿ‡ท": "South Korea", + "๐Ÿ‡ฐ๐Ÿ‡ผ": "Kuwait", + "๐Ÿ‡ฐ๐Ÿ‡พ": "Cayman Islands", + "๐Ÿ‡ฐ๐Ÿ‡ฟ": "Kazakhstan", + "๐Ÿ‡ฑ๐Ÿ‡ฆ": "Laos", + "๐Ÿ‡ฑ๐Ÿ‡ง": "Lebanon", + "๐Ÿ‡ฑ๐Ÿ‡จ": "St. Lucia", + "๐Ÿ‡ฑ๐Ÿ‡ฎ": "Liechtenstein", + "๐Ÿ‡ฑ๐Ÿ‡ฐ": "Sri Lanka", + "๐Ÿ‡ฑ๐Ÿ‡ท": "Liberia", + "๐Ÿ‡ฑ๐Ÿ‡ธ": "Lesotho", + "๐Ÿ‡ฑ๐Ÿ‡น": "Lithuania", + "๐Ÿ‡ฑ๐Ÿ‡บ": "Luxembourg", + "๐Ÿ‡ฑ๐Ÿ‡ป": "Latvia", + "๐Ÿ‡ฑ๐Ÿ‡พ": "Libya", + "๐Ÿ‡ฒ๐Ÿ‡ฆ": "Morocco", + "๐Ÿ‡ฒ๐Ÿ‡จ": "Monaco", + "๐Ÿ‡ฒ๐Ÿ‡ฉ": "Moldova", + "๐Ÿ‡ฒ๐Ÿ‡ช": "Montenegro", + "๐Ÿ‡ฒ๐Ÿ‡ซ": "St. Martin", + "๐Ÿ‡ฒ๐Ÿ‡ฌ": "Madagascar", + "๐Ÿ‡ฒ๐Ÿ‡ญ": "Marshall Islands", + "๐Ÿ‡ฒ๐Ÿ‡ฐ": "North Macedonia", + "๐Ÿ‡ฒ๐Ÿ‡ฑ": "Mali", + "๐Ÿ‡ฒ๐Ÿ‡ฒ": "Myanmar (Burma)", + "๐Ÿ‡ฒ๐Ÿ‡ณ": "Mongolia", + "๐Ÿ‡ฒ๐Ÿ‡ด": "Macao SAR China", + "๐Ÿ‡ฒ๐Ÿ‡ต": "Northern Mariana Islands", + "๐Ÿ‡ฒ๐Ÿ‡ถ": "Martinique", + "๐Ÿ‡ฒ๐Ÿ‡ท": "Mauritania", + "๐Ÿ‡ฒ๐Ÿ‡ธ": "Montserrat", + "๐Ÿ‡ฒ๐Ÿ‡น": "Malta", + "๐Ÿ‡ฒ๐Ÿ‡บ": "Mauritius", + "๐Ÿ‡ฒ๐Ÿ‡ป": "Maldives", + "๐Ÿ‡ฒ๐Ÿ‡ผ": "Malawi", + "๐Ÿ‡ฒ๐Ÿ‡ฝ": "Mexico", + "๐Ÿ‡ฒ๐Ÿ‡พ": "Malaysia", + "๐Ÿ‡ฒ๐Ÿ‡ฟ": "Mozambique", + "๐Ÿ‡ณ๐Ÿ‡ฆ": "Namibia", + "๐Ÿ‡ณ๐Ÿ‡จ": "New Caledonia", + "๐Ÿ‡ณ๐Ÿ‡ช": "Niger", + "๐Ÿ‡ณ๐Ÿ‡ซ": "Norfolk Island", + "๐Ÿ‡ณ๐Ÿ‡ฌ": "Nigeria", + "๐Ÿ‡ณ๐Ÿ‡ฎ": "Nicaragua", + "๐Ÿ‡ณ๐Ÿ‡ฑ": "Netherlands", + "๐Ÿ‡ณ๐Ÿ‡ด": "Norway", + "๐Ÿ‡ณ๐Ÿ‡ต": "Nepal", + "๐Ÿ‡ณ๐Ÿ‡ท": "Nauru", + "๐Ÿ‡ณ๐Ÿ‡บ": "Niue", + "๐Ÿ‡ณ๐Ÿ‡ฟ": "New Zealand", + "๐Ÿ‡ด๐Ÿ‡ฒ": "Oman", + "๐Ÿ‡ต๐Ÿ‡ฆ": "Panama", + "๐Ÿ‡ต๐Ÿ‡ช": "Peru", + "๐Ÿ‡ต๐Ÿ‡ซ": "French Polynesia", + "๐Ÿ‡ต๐Ÿ‡ฌ": "Papua New Guinea", + "๐Ÿ‡ต๐Ÿ‡ญ": "Philippines", + "๐Ÿ‡ต๐Ÿ‡ฐ": "Pakistan", + "๐Ÿ‡ต๐Ÿ‡ฑ": "Poland", + "๐Ÿ‡ต๐Ÿ‡ฒ": "St. Pierre & Miquelon", + "๐Ÿ‡ต๐Ÿ‡ณ": "Pitcairn Islands", + "๐Ÿ‡ต๐Ÿ‡ท": "Puerto Rico", + "๐Ÿ‡ต๐Ÿ‡ธ": "Palestinian Territories", + "๐Ÿ‡ต๐Ÿ‡น": "Portugal", + "๐Ÿ‡ต๐Ÿ‡ผ": "Palau", + "๐Ÿ‡ต๐Ÿ‡พ": "Paraguay", + "๐Ÿ‡ถ๐Ÿ‡ฆ": "Qatar", + "๐Ÿ‡ท๐Ÿ‡ช": "Rรฉunion", + "๐Ÿ‡ท๐Ÿ‡ด": "Romania", + "๐Ÿ‡ท๐Ÿ‡ธ": "Serbia", + "๐Ÿ‡ท๐Ÿ‡บ": "Russia", + "๐Ÿ‡ท๐Ÿ‡ผ": "Rwanda", + "๐Ÿ‡ธ๐Ÿ‡ฆ": "Saudi Arabia", + "๐Ÿ‡ธ๐Ÿ‡ง": "Solomon Islands", + "๐Ÿ‡ธ๐Ÿ‡จ": "Seychelles", + "๐Ÿ‡ธ๐Ÿ‡ฉ": "Sudan", + "๐Ÿ‡ธ๐Ÿ‡ช": "Sweden", + "๐Ÿ‡ธ๐Ÿ‡ฌ": "Singapore", + "๐Ÿ‡ธ๐Ÿ‡ญ": "St. Helena, Ascension & Tristan da Cunha", + "๐Ÿ‡ธ๐Ÿ‡ฎ": "Slovenia", + "๐Ÿ‡ธ๐Ÿ‡ฏ": "Svalbard & Jan Mayen", + "๐Ÿ‡ธ๐Ÿ‡ฐ": "Slovakia", + "๐Ÿ‡ธ๐Ÿ‡ฑ": "Sierra Leone", + "๐Ÿ‡ธ๐Ÿ‡ฒ": "San Marino", + "๐Ÿ‡ธ๐Ÿ‡ณ": "Senegal", + "๐Ÿ‡ธ๐Ÿ‡ด": "Somalia", + "๐Ÿ‡ธ๐Ÿ‡ท": "Suriname", + "๐Ÿ‡ธ๐Ÿ‡ธ": "South Sudan", + "๐Ÿ‡ธ๐Ÿ‡น": "Sรฃo Tomรฉ & Prรญncipe", + "๐Ÿ‡ธ๐Ÿ‡ป": "El Salvador", + "๐Ÿ‡ธ๐Ÿ‡ฝ": "Sint Maarten", + "๐Ÿ‡ธ๐Ÿ‡พ": "Syria", + "๐Ÿ‡ธ๐Ÿ‡ฟ": "Eswatini", + "๐Ÿ‡น๐Ÿ‡ฆ": "Tristan da Cunha", + "๐Ÿ‡น๐Ÿ‡จ": "Turks & Caicos Islands", + "๐Ÿ‡น๐Ÿ‡ฉ": "Chad", + "๐Ÿ‡น๐Ÿ‡ซ": "French Southern and Antarctic Lands", + "๐Ÿ‡น๐Ÿ‡ฌ": "Togo", + "๐Ÿ‡น๐Ÿ‡ญ": "Thailand", + "๐Ÿ‡น๐Ÿ‡ฏ": "Tajikistan", + "๐Ÿ‡น๐Ÿ‡ฐ": "Tokelau", + "๐Ÿ‡น๐Ÿ‡ฑ": "Timor-Leste", + "๐Ÿ‡น๐Ÿ‡ฒ": "Turkmenistan", + "๐Ÿ‡น๐Ÿ‡ณ": "Tunisia", + "๐Ÿ‡น๐Ÿ‡ด": "Tonga", + "๐Ÿ‡น๐Ÿ‡ท": "Tรผrkiye", + "๐Ÿ‡น๐Ÿ‡น": "Trinidad & Tobago", + "๐Ÿ‡น๐Ÿ‡ป": "Tuvalu", + "๐Ÿ‡น๐Ÿ‡ผ": "Taiwan", + "๐Ÿ‡น๐Ÿ‡ฟ": "Tanzania", + "๐Ÿ‡บ๐Ÿ‡ฆ": "Ukraine", + "๐Ÿ‡บ๐Ÿ‡ฌ": "Uganda", + "๐Ÿ‡บ๐Ÿ‡ฒ": "U.S. Outlying Islands", + "๐Ÿ‡บ๐Ÿ‡ณ": "United Nations", + "๐Ÿ‡บ๐Ÿ‡ธ": "United States", + "๐Ÿ‡บ๐Ÿ‡พ": "Uruguay", + "๐Ÿ‡บ๐Ÿ‡ฟ": "Uzbekistan", + "๐Ÿ‡ป๐Ÿ‡ฆ": "Vatican City", + "๐Ÿ‡ป๐Ÿ‡จ": "St. Vincent & Grenadines", + "๐Ÿ‡ป๐Ÿ‡ช": "Venezuela", + "๐Ÿ‡ป๐Ÿ‡ฌ": "British Virgin Islands", + "๐Ÿ‡ป๐Ÿ‡ฎ": "U.S. Virgin Islands", + "๐Ÿ‡ป๐Ÿ‡ณ": "Vietnam", + "๐Ÿ‡ป๐Ÿ‡บ": "Vanuatu", + "๐Ÿ‡ผ๐Ÿ‡ซ": "Wallis & Futuna", + "๐Ÿ‡ผ๐Ÿ‡ธ": "Samoa", + "๐Ÿ‡ฝ๐Ÿ‡ฐ": "Kosovo", + "๐Ÿ‡พ๐Ÿ‡ช": "Yemen", + "๐Ÿ‡พ๐Ÿ‡น": "Mayotte", + "๐Ÿ‡ฟ๐Ÿ‡ฆ": "South Africa", + "๐Ÿ‡ฟ๐Ÿ‡ฒ": "Zambia", + "๐Ÿ‡ฟ๐Ÿ‡ผ": "Zimbabwe" +} diff --git a/tests/Unit/LinkifiedText.test.tsx b/tests/Unit/LinkifiedText.test.tsx index d66ad032cb..58f66660fc 100644 --- a/tests/Unit/LinkifiedText.test.tsx +++ b/tests/Unit/LinkifiedText.test.tsx @@ -14,6 +14,7 @@ import { typedGuildHandles, typedLinks, } from '../../resources/js/components/linkified-text'; +import { TooltipProvider } from '../../resources/js/components/ui/tooltip'; import { WordmarkText } from '../../resources/js/components/wordmark-text'; import { bodySegments } from '../../resources/js/lib/code'; import { bodyCharacterCount } from '../../resources/js/lib/commit'; @@ -106,22 +107,91 @@ function renderPage( ); } +test('labels each flag in commit prose, including flags from shortcodes', () => { + const markup = renderPage( + + + , + ); + + assert.deepEqual( + [ + ...markup.matchAll( + /]*>([^<]+)<\/span>/g, + ), + ].map(([, name, flag]) => [flag, name]), + [ + ['๐Ÿ‡ฆ๐Ÿ‡น', 'Austria'], + ['๐Ÿ‡ฉ๐Ÿ‡ช', 'Germany'], + ['๐Ÿ‡บ๐Ÿ‡ธ', 'United States'], + ['๐Ÿ‡จ๐Ÿ‡ฉ', 'Congo-Kinshasa'], + ], + ); + assert.doesNotMatch(markup, /]*\btabindex=/i); + assert.match(markup, / ๐Ÿ‡ฆ ๐Ÿ‡ฟ๐Ÿ‡ฟ ๐Ÿš€ ]*>๐Ÿ‡บ๐Ÿ‡ธ<\/code>/); + assert.match(markup, /href="https:\/\/example.com\/๐Ÿ‡บ๐Ÿ‡ธ"/); +}); + +test('keeps Pastรฉis mode and escaped words working next to flags', () => { + const content = ( + + + + ); + const enabled = renderPage(content, { + auth: { user: null, pasteis: { remaining: 1, day: '2026-11-18' } }, + }); + const disabled = renderPage(content); + const pastelIcon = + /]*src="\/pastel-de-nata\.svg"[^>]*alt="([^"]+)"[^>]*>/g; + + assert.deepEqual( + [...enabled.matchAll(pastelIcon)].map(([, word]) => word), + ['pastel', 'pastรฉis'], + ); + assert.match(enabled, /๐Ÿ‡บ๐Ÿ‡ธ<\/span>pastel ]*>pastel<\/code>/); + assert.doesNotMatch(disabled, pastelIcon); + assert.match(disabled, /๐Ÿ‡ฆ๐Ÿ‡น<\/span>pastel.*๐Ÿ‡ฉ๐Ÿ‡ช<\/span>pastรฉis/); + + for (const markup of [enabled, disabled]) { + assert.match(markup, /aria-label="Austria"/); + assert.match(markup, /aria-label="Germany"/); + assert.match(markup, /aria-label="United States"/); + assert.match(markup, /title="\/dev\/null"/); + assert.match(markup, /data-test="color"/); + assert.match(markup, /background-color:#ff0000/); + assert.match(markup, /href="https:\/\/example.com\/pastel"/); + } +}); + test('renders loaded guild badges on the first paint without a shared catalogue', () => { const content = ( - + + + ); const auth = { user: { id: 'viewer' }, pasteis: null }; const markup = renderPage(content, { @@ -130,6 +200,7 @@ test('renders loaded guild badges on the first paint without a shared catalogue' }); assert.equal((markup.match(/href="\/guilds\/jobs"/g) ?? []).length, 1); + assert.match(markup, /role="img" aria-label="Austria"/); assert.match(markup, /aria-label="Job Board, #JoBs guild"/); assert.match(markup, /href="\/search\?q=%23rust"/); assert.match(markup, /]*>#jobs<\/code>/); @@ -137,6 +208,7 @@ test('renders loaded guild badges on the first paint without a shared catalogue' const ordinary = renderPage(content, { auth, guildsEnabled: false }); assert.doesNotMatch(ordinary, /\/guilds\//); + assert.match(ordinary, /role="img" aria-label="Austria"/); assert.match(ordinary, /Job Board/); assert.match(ordinary, /data-test="guild-mention"/); });