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 |
Init commit
Diffstat (limited to 'src')
-rw-r--r-- | src/index.js | 27 | ||||
-rw-r--r-- | src/schemes.js | 99 |
2 files changed, 126 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; + diff --git a/src/schemes.js b/src/schemes.js new file mode 100644 index 0000000..fecc1dd --- /dev/null +++ b/src/schemes.js @@ -0,0 +1,99 @@ +'use strict'; + +module.exports = [ + 'aaa', + 'aaas', + 'about', + 'acap', + 'acct', + 'cap', + 'cid', + 'coap', + 'coap+tcp', + 'coap+ws', + 'coaps', + 'coaps+tcp', + 'coaps+ws', + 'crid', + 'data', + 'dav', + 'dict', + 'dns', + 'example', + 'file', + 'ftp', + 'geo', + 'go', + 'gopher', + 'h323', + 'http', + 'https', + 'iax', + 'icap', + 'im', + 'imap', + 'info', + 'ipp', + 'ipps', + 'iris', + 'iris.beep', + 'iris.lwz', + 'iris.xpc', + 'iris.xpcs', + 'jabber', + 'ldap', + 'leaptofrogans', + 'mailto', + 'mid', + 'msrp', + 'msrps', + 'mtqp', + 'mupdate', + 'news', + 'nfs', + 'ni', + 'nih', + 'nntp', + 'opaquelocktoken', + 'pkcs11', + 'pop', + 'pres', + 'reload', + 'rtsp', + 'rtsps', + 'rtspu', + 'service', + 'session', + 'shttp', + 'sieve', + 'sip', + 'sips', + 'sms', + 'snmp', + 'soap.beep', + 'soap.beeps', + 'stun', + 'stuns', + 'tag', + 'tel', + 'telnet', + 'tftp', + 'thismessage', + 'tip', + 'tn3270', + 'turn', + 'turns', + 'tv', + 'urn', + 'vemmi', + 'vnc', + 'ws', + 'wss', + 'xcon', + 'xcon-userid', + 'xmlrpc.beep', + 'xmlrpc.beeps', + 'xmpp', + 'z39.50r', + 'z39.50s', +]; |