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

Function stripCodeContent

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

* Blank out fenced and inline code spans so the #tag / [[link]] / asset * scanners never read code as content. Fence detection is line-based and * indentation-tolerant: a fence nested under a list item is still a code block, * so its contents (e.g. a C `#include` line) must not be scanned. A * c

(body: string)

Source from the content-addressed store, hash-verified

1458 * apps/server/internal/vault/parse.go — keep the three in sync.
1459 */
1460function stripCodeContent(body: string): string {
1461 if (!body.includes('`') && !body.includes('~')) return body
1462 const lines = body.split('\n')
1463 let inFence = false
1464 let fenceChar = ''
1465 let fenceLen = 0
1466 for (let i = 0; i < lines.length; i++) {
1467 const line = lines[i] as string
1468 const m = /^[ \t]*(`{3,}|~{3,})(.*)$/.exec(line)
1469 if (m) {
1470 const marker = m[1] as string
1471 const char = marker[0] as string
1472 const rest = m[2] as string
1473 if (!inFence) {
1474 // A backtick fence's info string may not contain a backtick (CommonMark),
1475 // which keeps a single-line ``` ```inline``` ``` out of fence handling.
1476 if (char === '~' || !rest.includes('`')) {
1477 inFence = true
1478 fenceChar = char
1479 fenceLen = marker.length
1480 lines[i] = ' '
1481 continue
1482 }
1483 } else if (char === fenceChar && marker.length >= fenceLen && rest.trim() === '') {
1484 inFence = false
1485 lines[i] = ' '
1486 continue
1487 }
1488 }
1489 if (inFence) lines[i] = ' '
1490 }
1491 return lines.join('\n').replace(/`[^`\n]*`/g, ' ')
1492}
1493
1494function localAssetTargetKind(target: string): ImportedAssetKind | null {
1495 const clean = target.split('#')[0]?.split('?')[0] ?? target

Callers 5

extractTagsFunction · 0.70
bodyHasLocalAssetFunction · 0.70
extractWikilinksFunction · 0.70
extractAssetEmbedsFunction · 0.70
buildExcerptFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected