Skip to content

Commit

Permalink
Added support for URIs (#2708)
Browse files Browse the repository at this point in the history
  • Loading branch information
RunDevelopment authored Jan 24, 2021
1 parent b37987d commit bbc77d1
Show file tree
Hide file tree
Showing 18 changed files with 708 additions and 94 deletions.
2 changes: 1 addition & 1 deletion components.js

Large diffs are not rendered by default.

11 changes: 10 additions & 1 deletion components.json
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,8 @@
"css",
"javascript",
"json",
"markup"
"markup",
"uri"
],
"owner": "danielgtaylor"
},
Expand Down Expand Up @@ -1210,6 +1211,14 @@
"alias": ["uscript", "uc"],
"owner": "RunDevelopment"
},
"uri": {
"title": "URI",
"alias": "url",
"aliasTitles": {
"url": "URL"
},
"owner": "RunDevelopment"
},
"v": {
"title": "V",
"require": "clike",
Expand Down
3 changes: 2 additions & 1 deletion components/prism-http.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
'request-target': {
pattern: /^(\s)(?:https?:\/\/|\/)\S*(?=\s)/,
lookbehind: true,
alias: 'url'
alias: 'url',
inside: Prism.languages.uri
},
// HTTP Version
'http-version': {
Expand Down
2 changes: 1 addition & 1 deletion components/prism-http.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

96 changes: 96 additions & 0 deletions components/prism-uri.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
// 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]{0,2})$/
}
}
}
},
'path': {
pattern: /^[\w\-.~!$&'()*+,;=%:@/]+/m,
inside: {
'path-separator': /\//
}
}
};

Prism.languages.url = Prism.languages.uri;
1 change: 1 addition & 0 deletions components/prism-uri.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions examples/prism-uri.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<h2>Full example</h2>
<pre><code>https://john.doe@www.example.com:123/forum/questions/?tag=networking&order=newest#top
https://example.com/path/resource.txt#fragment
ldap://[2001:db8::7]/c=GB?objectClass?one
mailto:John.Doe@example.com
news:comp.infosystems.www.servers.unix
tel:+1-816-555-1212
telnet://192.0.2.16:80/
urn:oasis:names:specification:docbook:dtd:xml:4.1.2
//example.com/path/resource.txt
/path/resource.txt
path/resource.txt
</code></pre>
1 change: 1 addition & 0 deletions plugins/autoloader/prism-autoloader.js
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@
"tsconfig": "typoscript",
"uscript": "unrealscript",
"uc": "unrealscript",
"url": "uri",
"vb": "visual-basic",
"vba": "visual-basic",
"xeoracube": "xeora",
Expand Down
2 changes: 1 addition & 1 deletion plugins/autoloader/prism-autoloader.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions plugins/show-language/prism-show-language.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,8 @@
"tsconfig": "TSConfig",
"uscript": "UnrealScript",
"uc": "UnrealScript",
"uri": "URI",
"url": "URL",
"vbnet": "VB.Net",
"vhdl": "VHDL",
"vim": "vim",
Expand Down
Loading

0 comments on commit bbc77d1

Please sign in to comment.