fix: improve backtick heuristic

This commit is contained in:
shiftinv 2023-07-10 21:38:28 +02:00
parent 580832dd0c
commit 73969e8520
1 changed files with 3 additions and 1 deletions

View File

@ -6,7 +6,9 @@ function maybeTransformText(s: string): string {
// If length exceeds limit, add backticks since they might otherwise be removed
const suffix = "…\n```";
const maxLen = EMBED_LIMIT - suffix.length;
if (s.includes("```") && s.length > maxLen) {
// n.b. this heuristic is by no means perfect; it might add backticks when not necessary,
// but I really don't want to implement a markdown parser here c:
if (s.length > maxLen && s.substring(maxLen).includes("```")) {
s = s.substring(0, maxLen) + suffix;
}
return s;