Hide quoted text in replies preview

This commit is contained in:
dtonon 2026-08-27 18:55:30 +01:00
parent c793203d9f
commit 9950c4337a

View file

@ -28,11 +28,20 @@ export function excerpt(markdown: string, max = 160): string {
} }
// The whole body flattened to one plain-text line, trimmed to `max` chars. // The whole body flattened to one plain-text line, trimmed to `max` chars.
// Headings, bare media URLs, code fences and block markers are dropped. // Headings, bare media URLs, code blocks, quoted text and list markers are
// dropped, so a reply reads as its own words.
export function summarize(markdown: string, max = 200): string { export function summarize(markdown: string, max = 200): string {
const lines = markdown let inCode = false;
.split("\n") const lines: string[] = [];
.map((l) => l.trim().replace(/^(?:>\s*|[-*+]\s+|\d+[.)]\s+)+/, "")) for (const raw of markdown.split("\n")) {
.filter((l) => isProse(l) && !l.startsWith("```")); const l = raw.trim();
if (l.startsWith("```")) {
inCode = !inCode;
continue;
}
if (inCode || l.startsWith(">")) continue;
const line = l.replace(/^(?:[-*+]\s+|\d+[.)]\s+)+/, "");
if (isProse(line)) lines.push(line);
}
return truncate(stripInline(lines.join(" ")), max); return truncate(stripInline(lines.join(" ")), max);
} }