-
-
Notifications
You must be signed in to change notification settings - Fork 37
/
Copy pathuri.js
102 lines (100 loc) · 2.44 KB
/
uri.js
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
// @ts-nocheck
uri.displayName = 'uri'
uri.aliases = ['url']
/** @type {import('../core.js').Syntax} */
export default function uri(Prism) {
// https://tools.ietf.org/html/rfc3986#appendix-A
Prism.languages.uri = {
scheme: {
pattern: /^[a-z][a-z0-9+.-]*:/im,
greedy: true,
inside: {
'scheme-delimiter': /:$/
}
},
fragment: {
pattern: /#[\w\-.~!$&'()*+,;=%:@/?]*/,
inside: {
'fragment-delimiter': /^#/
}
},
query: {
pattern: /\?[\w\-.~!$&'()*+,;=%:@/?]*/,
inside: {
'query-delimiter': {
pattern: /^\?/,
greedy: true
},
'pair-delimiter': /[&;]/,
pair: {
pattern: /^[^=][\s\S]*/,
inside: {
key: /^[^=]+/,
value: {
pattern: /(^=)[\s\S]+/,
lookbehind: true
}
}
}
}
},
authority: {
pattern: RegExp(
/^\/\//.source +
// [ userinfo "@" ]
/(?:[\w\-.~!$&'()*+,;=%:]*@)?/.source +
// host
('(?:' +
// IP-literal
/\[(?:[0-9a-fA-F:.]{2,48}|v[0-9a-fA-F]+\.[\w\-.~!$&'()*+,;=]+)\]/
.source +
'|' +
// IPv4address or registered name
/[\w\-.~!$&'()*+,;=%]*/.source +
')') +
// [ ":" port ]
/(?::\d*)?/.source,
'm'
),
inside: {
'authority-delimiter': /^\/\//,
'user-info-segment': {
pattern: /^[\w\-.~!$&'()*+,;=%:]*@/,
inside: {
'user-info-delimiter': /@$/,
'user-info': /^[\w\-.~!$&'()*+,;=%:]+/
}
},
'port-segment': {
pattern: /:\d*$/,
inside: {
'port-delimiter': /^:/,
port: /^\d+/
}
},
host: {
pattern: /[\s\S]+/,
inside: {
'ip-literal': {
pattern: /^\[[\s\S]+\]$/,
inside: {
'ip-literal-delimiter': /^\[|\]$/,
'ipv-future': /^v[\s\S]+/,
'ipv6-address': /^[\s\S]+/
}
},
'ipv4-address':
/^(?:(?:[03-9]\d?|[12]\d{0,2})\.){3}(?:[03-9]\d?|[12]\d{0,2})$/
}
}
}
},
path: {
pattern: /^[\w\-.~!$&'()*+,;=%:@/]+/m,
inside: {
'path-separator': /\//
}
}
}
Prism.languages.url = Prism.languages.uri
}