From 6f054ca562d847b49544d2cb6e24fc91abede082 Mon Sep 17 00:00:00 2001 From: ache Date: Sun, 3 Mar 2019 02:13:07 +0100 Subject: Init commit --- src/index.js | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 src/index.js (limited to 'src/index.js') diff --git a/src/index.js b/src/index.js new file mode 100644 index 0000000..f1f0ce5 --- /dev/null +++ b/src/index.js @@ -0,0 +1,27 @@ +'use strict'; + +const visit = require('unist-util-visit'); +const schemes = require('./schemes.js'); + +function plugin() { + return transformer; + function transformer(tree) { + visit(tree, 'link', link => { + if (link.url) { + if (link.url[0] === '/') { // Local link + return; + } + + if (schemes.some(scheme => link.url.startsWith(scheme + ':'))) { + // Valide scheme + return; + } + + link.url = '/' + link.url; + } + }); + } +} + +module.exports = plugin; + -- cgit v1.2.3