UNPKG

@theguild/components

Version:
14 lines (13 loc) 332 B
import { visit } from "unist-util-visit"; const EXTERNAL_URL_RE = /^https?:\/\//; const remarkLinkRewrite = ({ pattern, replace }) => (ast) => { visit(ast, "link", (node) => { if (EXTERNAL_URL_RE.test(node.url)) { return; } node.url = node.url.replace(pattern, replace); }); }; export { remarkLinkRewrite };