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

Function extractWikilinks

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

Pull unique `[[wikilink]]` targets out of markdown text. Supports * `[[target|label]]` by discarding the label. Ignores fenced/inline code.

(body: string)

Source from the content-addressed store, hash-verified

1542/** Pull unique `[[wikilink]]` targets out of markdown text. Supports
1543 * `[[target|label]]` by discarding the label. Ignores fenced/inline code. */
1544function extractWikilinks(body: string): string[] {
1545 if (!body.includes('[[')) return []
1546 const stripped = stripCodeContent(body)
1547 const re = /(!?)\[\[([^\]|]+?)(?:\|[^\]]+)?\]\]/g
1548 const seen = new Set<string>()
1549 let m: RegExpExecArray | null
1550 while ((m = re.exec(stripped)) !== null) {
1551 const bang = m[1] ?? ''
1552 const target = (m[2] ?? '').trim()
1553 if (!target) continue
1554 if (bang === '!' && localAssetTargetKind(target)) continue
1555 seen.add(target)
1556 }
1557 return [...seen]
1558}
1559
1560/** Pull unique asset-embed targets out of markdown — both `![[asset]]` (which
1561 * extractWikilinks deliberately skips) and `![](path)` image/file embeds. The

Callers 1

readMetaFunction · 0.70

Calls 2

stripCodeContentFunction · 0.70
localAssetTargetKindFunction · 0.70

Tested by

no test coverage detected