mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-06-24 01:18:55 +00:00
4bc168dffb
## Description: make usernames linkable in news now: <img width="399" height="153" alt="image" src="https://github.com/user-attachments/assets/39644fe2-9af1-4765-b839-9f8b5f9d0418" /> before: <img width="409" height="82" alt="image" src="https://github.com/user-attachments/assets/d7a1c37e-63cf-4417-ac61-c6db39a33851" /> ## Please complete the following: - [x] I have added screenshots for all UI updates - [x] I process any text displayed to the user through translateText() and I've added it to the en.json file - [x] I have added relevant tests to the test directory - [x] I confirm I have thoroughly tested these changes and take full responsibility for any bugs introduced ## Please put your Discord username so you can be contacted if a bug or regression is found: w.o.n Co-authored-by: iamlewis <lewismmmm@gmail.com>
31 lines
1.1 KiB
TypeScript
31 lines
1.1 KiB
TypeScript
const GITHUB_PR_URL_REGEX =
|
|
/(?<!\()\bhttps:\/\/github\.com\/openfrontio\/OpenFrontIO\/pull\/(\d+)\b/g;
|
|
const GITHUB_COMPARE_URL_REGEX =
|
|
/(?<!\()\bhttps:\/\/github\.com\/openfrontio\/OpenFrontIO\/compare\/([\w.-]+)\b/g;
|
|
const GITHUB_MENTION_REGEX =
|
|
/(^|[^\w/[`])@([a-z\d](?:[a-z\d-]{0,37}[a-z\d])?)(?![\w-])/gim;
|
|
|
|
export function normalizeNewsMarkdown(markdown: string): string {
|
|
return (
|
|
markdown
|
|
// Convert bold header lines (e.g. "**Title**") into real Markdown headers.
|
|
// Exclude lines starting with - or * to avoid converting bullet points.
|
|
.replace(/^([^\-*\s].*?) \*\*(.+?)\*\*$/gm, "## $1 $2")
|
|
.replace(
|
|
GITHUB_PR_URL_REGEX,
|
|
(_match, prNumber) =>
|
|
`[#${prNumber}](https://github.com/openfrontio/OpenFrontIO/pull/${prNumber})`,
|
|
)
|
|
.replace(
|
|
GITHUB_COMPARE_URL_REGEX,
|
|
(_match, comparison) =>
|
|
`[${comparison}](https://github.com/openfrontio/OpenFrontIO/compare/${comparison})`,
|
|
)
|
|
.replace(
|
|
GITHUB_MENTION_REGEX,
|
|
(_match, prefix, username) =>
|
|
`${prefix}[@${username}](https://github.com/${username})`,
|
|
)
|
|
);
|
|
}
|