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 ++++++++++++++++ src/schemes.js | 99 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 126 insertions(+) create mode 100644 src/index.js create mode 100644 src/schemes.js (limited to 'src') 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', +]; -- cgit v1.2.3