(block: ContentBlock)
| 22 | |
| 23 | const INTERNAL_LINK_REGEX = /(?:\[\[(nn:\/\/note\/.+?)\]\])/gm; |
| 24 | export function extractInternalLinks(block: ContentBlock) { |
| 25 | const matches = block.content.matchAll(INTERNAL_LINK_REGEX); |
| 26 | |
| 27 | const links: InternalLinkWithOffset[] = []; |
| 28 | for (const match of matches) { |
| 29 | if (match.index === undefined) continue; |
| 30 | const url = match[1].slice(0, match[1].lastIndexOf("|")); |
| 31 | const text = match[1].slice(match[1].lastIndexOf("|") + 1); |
| 32 | const link = parseInternalLink(url); |
| 33 | if (!link) continue; |
| 34 | links.push({ |
| 35 | ...link, |
| 36 | start: match.index, |
| 37 | end: match.index + match[0].length, |
| 38 | text |
| 39 | }); |
| 40 | } |
| 41 | |
| 42 | return links; |
| 43 | } |
| 44 | |
| 45 | function normalize(block: ContentBlock, links: InternalLinkWithOffset[]) { |
| 46 | let diff = 0; |
no test coverage detected