fix(markdown): open local file links

This commit is contained in:
Bohdan Triapitsyn
2026-08-14 00:13:03 +03:00
parent 1b02310a28
commit 29e7a2380d
6 changed files with 65 additions and 3 deletions
@@ -24,6 +24,29 @@ export const normalizeReferencePath = (value: string): string => normalizeFilePa
export const isAbsoluteReferencePath = (value: string): boolean => isAbsoluteFilePath(value);
export const localPathFromFileUrl = (value: string): string | null => {
let parsed: URL;
try {
parsed = new URL(value.trim());
} catch {
return null;
}
if (parsed.protocol !== 'file:' || (parsed.hostname && parsed.hostname !== 'localhost')) {
return null;
}
try {
const decodedPath = decodeURIComponent(parsed.pathname);
if (/^\/[A-Za-z]:\//.test(decodedPath)) {
return decodedPath.slice(1);
}
return decodedPath.startsWith('/') ? decodedPath : null;
} catch {
return null;
}
};
const trimPathCandidate = (value: string): string => {
let next = (value || '').trim();
if (!next) {