diff options
author | ache <ache@ache.one> | 2019-03-03 02:13:07 +0100 |
---|---|---|
committer | ache <ache@ache.one> | 2019-03-03 02:14:59 +0100 |
commit | 6f054ca562d847b49544d2cb6e24fc91abede082 (patch) | |
tree | 4a3db33251fc7c789cb77bb9b7544cdd60c851c1 /src/index.js |
Init commit
Diffstat (limited to 'src/index.js')
-rw-r--r-- | src/index.js | 27 |
1 files changed, 27 insertions, 0 deletions
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; + |