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

Function extractAssetEmbeds

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

Pull unique asset-embed targets out of markdown — both `![[asset]]` (which * extractWikilinks deliberately skips) and `![](path)` image/file embeds. The * raw targets are resolved to assets per-note by the renderer (relative path + * basename fallback), to show which notes use each asset.

(body: string)

Source from the content-addressed store, hash-verified

1562 * raw targets are resolved to assets per-note by the renderer (relative path +
1563 * basename fallback), to show which notes use each asset. */
1564function extractAssetEmbeds(body: string): string[] {
1565 const stripped = stripCodeContent(body)
1566 const seen = new Set<string>()
1567 if (stripped.includes('![[')) {
1568 const re = /!\[\[([^\]|]+?)(?:\|[^\]]+)?\]\]/g
1569 let m: RegExpExecArray | null
1570 while ((m = re.exec(stripped)) !== null) {
1571 const t = (m[1] ?? '').trim()
1572 if (t && localAssetTargetKind(t)) seen.add(t)
1573 }
1574 }
1575 if (stripped.includes('](')) {
1576 const re = /!\[[^\]]*\]\(\s*<?([^)>\s]+)>?[^)]*\)/g
1577 let m: RegExpExecArray | null
1578 while ((m = re.exec(stripped)) !== null) {
1579 const raw = (m[1] ?? '').trim()
1580 if (!raw || raw.startsWith('#') || /^[a-zA-Z][\w+.-]*:/.test(raw)) continue // skip URLs/anchors
1581 try {
1582 seen.add(decodeURIComponent(raw))
1583 } catch {
1584 seen.add(raw)
1585 }
1586 }
1587 }
1588 return [...seen]
1589}
1590
1591/** Build a short plaintext preview from markdown. */
1592function buildExcerpt(body: string): string {

Callers 1

readMetaFunction · 0.85

Calls 2

stripCodeContentFunction · 0.70
localAssetTargetKindFunction · 0.70

Tested by

no test coverage detected