export interface WikiLink { /** Raw target slug as written inside [[...]], left of any `|`. */ target: string; /** Display alias after `|`, or null when absent. */ alias: string | null; } const LINK_RE = /\[\[([^\]]+)\]\]/g; /** * Extract `[[wikilinks]]` from page content. * `[[slug]]` → { target: 'slug', alias: null }. * `[[slug|Label]]` → { target: 'slug', alias: 'Label' }. */ export function extractLinks(content: string): WikiLink[] { const links: WikiLink[] = []; for (const match of content.matchAll(LINK_RE)) { const inner = match[1]; const pipe = inner.indexOf('|'); if (pipe === -1) { links.push({ target: inner.trim(), alias: null }); } else { links.push({ target: inner.slice(0, pipe).trim(), alias: inner.slice(pipe + 1).trim(), }); } } return links; }