Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for URIs #2708

Merged
merged 5 commits into from Jan 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion components.js

Large diffs are not rendered by default.

11 changes: 10 additions & 1 deletion components.json
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
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
@@ -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
@@ -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
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
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