MCPcopy Create free account
hub / github.com/ZenNotes/zennotes / buildExcerpt

Function buildExcerpt

apps/desktop/src/main/vault.ts:1592–1610  ·  view source on GitHub ↗

Build a short plaintext preview from markdown.

(body: string)

Source from the content-addressed store, hash-verified

1590
1591/** Build a short plaintext preview from markdown. */
1592function buildExcerpt(body: string): string {
1593 const withoutFront = body.startsWith('---\n') ? body.replace(/^---\n[\s\S]*?\n---\n/, '') : body
1594 let text = stripCodeContent(withoutFront)
1595 if (text.includes('](')) {
1596 text = text
1597 .replace(/!\[[^\]]*\]\([^)]*\)/g, ' ')
1598 .replace(/\[([^\]]+)\]\([^)]*\)/g, '$1')
1599 }
1600 if (text.includes('![[')) {
1601 text = text.replace(/!\[\[([^\]|]+)(?:\|([^\]]+))?\]\]/g, (_, a, b) => b || a)
1602 }
1603 if (text.includes('[[')) {
1604 text = text.replace(/\[\[([^\]|]+)(?:\|([^\]]+))?\]\]/g, (_, a, b) => b || a)
1605 }
1606 if (text.includes('#')) text = text.replace(/^#{1,6}\s+/gm, '')
1607 if (/[*_~>]/.test(text)) text = text.replace(/[*_~>]+/g, '')
1608 text = text.replace(/\s+/g, ' ').trim()
1609 return text.slice(0, 220)
1610}
1611
1612function escapeRegex(value: string): string {
1613 return value.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')

Callers 1

readMetaFunction · 0.70

Calls 1

stripCodeContentFunction · 0.70

Tested by

no test coverage detected