Hide quoted text in replies preview
This commit is contained in:
parent
c793203d9f
commit
9950c4337a
1 changed files with 14 additions and 5 deletions
|
|
@ -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);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue