cynarAI 6c7eed7580 Initial clean evOo-local from f00577b
Fresh history cut from cynarAI/evoo antigravity-handoff/project-timeline
(Voice First + project timeline). Brand docs/titles as evOo; keep @rakazo/*
packages as tech debt. Excludes node_modules, caches, secrets, voice blobs.
2026-09-20 17:15:16 +02:00

28 lines
914 B
TypeScript

const MAX_PREVIEW_WORDS = 12;
export function previewSnippet(markdown: string, maxWords = MAX_PREVIEW_WORDS): string {
const words = stripMarkdown(markdown).split(/\s+/).filter(Boolean);
return words.slice(0, maxWords).join(" ");
}
function stripMarkdown(markdown: string): string {
return markdown
.replace(/\r\n/g, "\n")
.replace(/```[\w-]*\n?([\s\S]*?)```/g, "$1")
.replace(/~~~[\w-]*\n?([\s\S]*?)~~~/g, "$1")
.replace(/!\[([^\]]*)\]\([^)]+\)/g, "$1")
.replace(/\[([^\]]+)\]\([^)]+\)/g, "$1")
.replace(/`([^`]+)`/g, "$1")
.replace(/^#{1,6}\s+/gm, "")
.replace(/^>\s+/gm, "")
.replace(/^\s*[-*+]\s+/gm, "")
.replace(/^\s*\d+\.\s+/gm, "")
.replace(/^\s*[-*_]{3,}\s*$/gm, "")
.replace(/(\*\*|__)(.*?)\1/g, "$2")
.replace(/(\*|_)([^*_\n]+)\1/g, "$2")
.replace(/~~(.*?)~~/g, "$1")
.replace(/<[^>]+>/g, " ")
.replace(/\s+/g, " ")
.trim();
}