MCPcopy
hub / github.com/streetwriters/notesnook / extractInternalLinks

Function extractInternalLinks

packages/core/src/utils/content-block.ts:24–43  ·  view source on GitHub ↗
(block: ContentBlock)

Source from the content-addressed store, hash-verified

22
23const INTERNAL_LINK_REGEX = /(?:\[\[(nn:\/\/note\/.+?)\]\])/gm;
24export 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
45function normalize(block: ContentBlock, links: InternalLinkWithOffset[]) {
46 let diff = 0;

Callers 2

highlightInternalLinksFunction · 0.85

Calls 3

parseInternalLinkFunction · 0.85
sliceMethod · 0.80
pushMethod · 0.45

Tested by

no test coverage detected