UNPKG

@time4peter/foam-cli

Version:

CLI tool for Foam knowledge management - verify wikilinks and more

39 lines 1.25 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.parseWikilinks = parseWikilinks; exports.normalizeWikilinkTarget = normalizeWikilinkTarget; const WIKILINK_REGEX = /\[\[([^\]|]+)(\|([^\]]+))?\]\]/g; function parseWikilinks(content, filePath) { const links = []; const lines = content.split('\n'); lines.forEach((line, lineIndex) => { let match; WIKILINK_REGEX.lastIndex = 0; while ((match = WIKILINK_REGEX.exec(line)) !== null) { const raw = match[0]; const target = match[1].trim(); const alias = match[3]?.trim(); links.push({ raw, target, alias, line: lineIndex + 1, column: match.index + 1, }); } }); return { path: filePath, links, }; } function normalizeWikilinkTarget(target) { // Remove file extension if present const withoutExt = target.replace(/\.(md|mdx)$/i, ''); // Convert to lowercase and replace spaces with hyphens // This matches common Foam behavior return withoutExt .toLowerCase() .replace(/\s+/g, '-'); } //# sourceMappingURL=wikilink-parser.js.map