webforai
Version:
A library that provides a web interface for AI
19 lines (18 loc) • 417 B
JavaScript
// src/link-replacer.ts
var linkReplacer = (markdown, base) => {
const regex = /(!?\[.*?\]\()([^)\s]+)(\))/g;
return markdown.replace(regex, (match, pre, url, post) => {
if (/^(https?:|#)/.test(url)) {
return match;
}
try {
const absoluteUrl = new URL(url, base).href;
return `${pre}${absoluteUrl}${post}`;
} catch {
return match;
}
});
};
export {
linkReplacer
};