forked from remarkjs/react-markdown
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuri-transformer.js
More file actions
39 lines (30 loc) Β· 794 Bytes
/
uri-transformer.js
File metadata and controls
39 lines (30 loc) Β· 794 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
const protocols = ['http', 'https', 'mailto', 'tel']
module.exports = function uriTransformer(uri) {
const url = (uri || '').trim()
const first = url.charAt(0)
if (first === '#' || first === '/') {
return url
}
const colon = url.indexOf(':')
if (colon === -1) {
return url
}
const length = protocols.length
let index = -1
while (++index < length) {
const protocol = protocols[index]
if (colon === protocol.length && url.slice(0, protocol.length).toLowerCase() === protocol) {
return url
}
}
index = url.indexOf('?')
if (index !== -1 && colon > index) {
return url
}
index = url.indexOf('#')
if (index !== -1 && colon > index) {
return url
}
// eslint-disable-next-line no-script-url
return 'javascript:void(0)'
}