From c72e4c5917c5dbdfc9ef3ab339cbf56f89ee8f9b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jozef=20Steinh=C3=BCbl?= Date: Wed, 1 May 2024 13:23:35 +0200 Subject: [PATCH] feat: own escape for bun.report urls --- src/util.ts | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/util.ts b/src/util.ts index c2f0a77..0ba30e6 100644 --- a/src/util.ts +++ b/src/util.ts @@ -2,6 +2,8 @@ import { GuildMember } from "@lilybird/transformers"; import { BUN_EMOJIS } from "./constants.ts"; import { parse, formatMarkdown } from "bun-tracestrings"; +const URL_REGEX = /\(\s*(https?:\/\/[^\s\[\]]+)\s*\)/gi; + export function safeSlice>( input: T, length: number @@ -63,10 +65,22 @@ export async function getBunReportDetailsInMarkdown( } const json = await res.json(); - console.log(json); - return formatMarkdown({ + let content = formatMarkdown({ ...parsed, ...json, }); + + for (const match of content.matchAll(URL_REGEX)) { + let url = match[1]; + if (url.endsWith(")")) { + url = url.slice(0, -1); + } + + if (!url.startsWith("<")) { + content = content.replace(url, `<${url}>`); + } + } + + return content; }