feat: own escape for bun.report urls

This commit is contained in:
Jozef Steinhübl 2024-05-01 13:23:35 +02:00
parent c858d66a3f
commit c72e4c5917
No known key found for this signature in database
GPG key ID: E6BC90C91973B08F

View file

@ -2,6 +2,8 @@ import { GuildMember } from "@lilybird/transformers";
import { BUN_EMOJIS } from "./constants.ts"; import { BUN_EMOJIS } from "./constants.ts";
import { parse, formatMarkdown } from "bun-tracestrings"; import { parse, formatMarkdown } from "bun-tracestrings";
const URL_REGEX = /\(\s*(https?:\/\/[^\s\[\]]+)\s*\)/gi;
export function safeSlice<T extends string | Array<any>>( export function safeSlice<T extends string | Array<any>>(
input: T, input: T,
length: number length: number
@ -63,10 +65,22 @@ export async function getBunReportDetailsInMarkdown(
} }
const json = await res.json(); const json = await res.json();
console.log(json);
return formatMarkdown({ let content = formatMarkdown({
...parsed, ...parsed,
...json, ...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;
} }