Files
factory/lib/wiki-graph/src/parser.ts
vitya ca669d96e1 feat(lib): bundle MCP servers from .common/lib into factory/lib/
Copies source (no node_modules, dist, .tasks, .wiki, __pycache__) for:
- projects-meta-mcp v2.25.0 (TypeScript/Node)
- wiki-graph v0.3.1 (TypeScript/Node)
- interns-mcp v0.3.3 (Python/FastMCP)

.gitignore: exclude lib build artefacts (node_modules, dist, .venv, __pycache__, *.pyc)
bootstrap.ps1: add MCP build step — npm install+build for TS servers, venv+pip for Python

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-11 13:17:29 +03:00

31 lines
848 B
TypeScript

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;
}