* Whether a note body references at least one local asset (any * markdown link / image whose href looks like a relative file path * with a known asset extension). Quick heuristic — used purely for * the sidebar "has attachments" indicator. Skips fenced / inline code.
(body: string)
| 1520 | * the sidebar "has attachments" indicator. Skips fenced / inline code. |
| 1521 | */ |
| 1522 | function bodyHasLocalAsset(body: string): boolean { |
| 1523 | if (!body.includes('](') && !body.includes('![[')) return false |
| 1524 | const stripped = stripCodeContent(body) |
| 1525 | const linkRe = /(!?)\[[^\]]*\]\((<[^>]+>|[^)\s]+)(?:\s+"[^"]*")?\)/g |
| 1526 | const embedRe = /!\[\[([^\]|]+?)(?:\|[^\]]+)?\]\]/g |
| 1527 | let m: RegExpExecArray | null |
| 1528 | while ((m = linkRe.exec(stripped)) !== null) { |
| 1529 | let href = (m[2] ?? '').trim() |
| 1530 | if (href.startsWith('<') && href.endsWith('>')) href = href.slice(1, -1) |
| 1531 | if (!href || href.startsWith('#') || href.startsWith('//')) continue |
| 1532 | // Skip URLs (anything with a scheme like http:, mailto:, file:, …). |
| 1533 | if (/^[a-zA-Z][a-zA-Z\d+.-]*:/.test(href)) continue |
| 1534 | if (localAssetTargetKind(href)) return true |
| 1535 | } |
| 1536 | while ((m = embedRe.exec(stripped)) !== null) { |
| 1537 | if (localAssetTargetKind((m[1] ?? '').trim())) return true |
| 1538 | } |
| 1539 | return false |
| 1540 | } |
| 1541 | |
| 1542 | /** Pull unique `[[wikilink]]` targets out of markdown text. Supports |
| 1543 | * `[[target|label]]` by discarding the label. Ignores fenced/inline code. */ |
no test coverage detected