reference/scripts/utils/rehypeUrls.mjs

6 lines
303 B
JavaScript
Raw Normal View History

2022-09-26 17:13:24 +08:00
export function rehypeUrls(node) {
2022-09-27 23:09:51 +08:00
if (node.type === 'element' && node.properties.href && /.md/.test(node.properties.href) && !/^(https?:\/\/)/.test(node.properties.href)) {
2022-09-26 17:13:24 +08:00
let href = node.properties.href;
node.properties.href = href.replace(/([^\.\/\\]+)\.(md|markdown)/gi, '$1.html');
}
}