aboutsummaryrefslogtreecommitdiff
path: root/node_modules/prismjs/plugins/autolinker
diff options
context:
space:
mode:
Diffstat (limited to 'node_modules/prismjs/plugins/autolinker')
-rw-r--r--node_modules/prismjs/plugins/autolinker/prism-autolinker.css3
-rw-r--r--node_modules/prismjs/plugins/autolinker/prism-autolinker.js81
-rw-r--r--node_modules/prismjs/plugins/autolinker/prism-autolinker.min.js1
3 files changed, 85 insertions, 0 deletions
diff --git a/node_modules/prismjs/plugins/autolinker/prism-autolinker.css b/node_modules/prismjs/plugins/autolinker/prism-autolinker.css
new file mode 100644
index 00000000..b5f76309
--- /dev/null
+++ b/node_modules/prismjs/plugins/autolinker/prism-autolinker.css
@@ -0,0 +1,3 @@
+.token a {
+ color: inherit;
+} \ No newline at end of file
diff --git a/node_modules/prismjs/plugins/autolinker/prism-autolinker.js b/node_modules/prismjs/plugins/autolinker/prism-autolinker.js
new file mode 100644
index 00000000..3913c98a
--- /dev/null
+++ b/node_modules/prismjs/plugins/autolinker/prism-autolinker.js
@@ -0,0 +1,81 @@
+(function(){
+
+if (
+ typeof self !== 'undefined' && !self.Prism ||
+ typeof global !== 'undefined' && !global.Prism
+) {
+ return;
+}
+
+var url = /\b([a-z]{3,7}:\/\/|tel:)[\w\-+%~/.:=&]+(?:\?[\w\-+%~/.:#=?&!$'()*,;]*)?(?:#[\w\-+%~/.:#=?&!$'()*,;]*)?/,
+ email = /\b\S+@[\w.]+[a-z]{2}/,
+ linkMd = /\[([^\]]+)]\(([^)]+)\)/,
+
+ // Tokens that may contain URLs and emails
+ candidates = ['comment', 'url', 'attr-value', 'string'];
+
+Prism.plugins.autolinker = {
+ processGrammar: function (grammar) {
+ // Abort if grammar has already been processed
+ if (!grammar || grammar['url-link']) {
+ return;
+ }
+ Prism.languages.DFS(grammar, function (key, def, type) {
+ if (candidates.indexOf(type) > -1 && Prism.util.type(def) !== 'Array') {
+ if (!def.pattern) {
+ def = this[key] = {
+ pattern: def
+ };
+ }
+
+ def.inside = def.inside || {};
+
+ if (type == 'comment') {
+ def.inside['md-link'] = linkMd;
+ }
+ if (type == 'attr-value') {
+ Prism.languages.insertBefore('inside', 'punctuation', { 'url-link': url }, def);
+ }
+ else {
+ def.inside['url-link'] = url;
+ }
+
+ def.inside['email-link'] = email;
+ }
+ });
+ grammar['url-link'] = url;
+ grammar['email-link'] = email;
+ }
+};
+
+Prism.hooks.add('before-highlight', function(env) {
+ Prism.plugins.autolinker.processGrammar(env.grammar);
+});
+
+Prism.hooks.add('wrap', function(env) {
+ if (/-link$/.test(env.type)) {
+ env.tag = 'a';
+
+ var href = env.content;
+
+ if (env.type == 'email-link' && href.indexOf('mailto:') != 0) {
+ href = 'mailto:' + href;
+ }
+ else if (env.type == 'md-link') {
+ // Markdown
+ var match = env.content.match(linkMd);
+
+ href = match[2];
+ env.content = match[1];
+ }
+
+ env.attributes.href = href;
+ }
+
+ // Silently catch any error thrown by decodeURIComponent (#1186)
+ try {
+ env.content = decodeURIComponent(env.content);
+ } catch(e) {}
+});
+
+})();
diff --git a/node_modules/prismjs/plugins/autolinker/prism-autolinker.min.js b/node_modules/prismjs/plugins/autolinker/prism-autolinker.min.js
new file mode 100644
index 00000000..9fdced95
--- /dev/null
+++ b/node_modules/prismjs/plugins/autolinker/prism-autolinker.min.js
@@ -0,0 +1 @@
+!function(){if(("undefined"==typeof self||self.Prism)&&("undefined"==typeof global||global.Prism)){var i=/\b([a-z]{3,7}:\/\/|tel:)[\w\-+%~\/.:=&]+(?:\?[\w\-+%~\/.:#=?&!$'()*,;]*)?(?:#[\w\-+%~\/.:#=?&!$'()*,;]*)?/,n=/\b\S+@[\w.]+[a-z]{2}/,e=/\[([^\]]+)]\(([^)]+)\)/,t=["comment","url","attr-value","string"];Prism.plugins.autolinker={processGrammar:function(r){r&&!r["url-link"]&&(Prism.languages.DFS(r,function(r,a,l){t.indexOf(l)>-1&&"Array"!==Prism.util.type(a)&&(a.pattern||(a=this[r]={pattern:a}),a.inside=a.inside||{},"comment"==l&&(a.inside["md-link"]=e),"attr-value"==l?Prism.languages.insertBefore("inside","punctuation",{"url-link":i},a):a.inside["url-link"]=i,a.inside["email-link"]=n)}),r["url-link"]=i,r["email-link"]=n)}},Prism.hooks.add("before-highlight",function(i){Prism.plugins.autolinker.processGrammar(i.grammar)}),Prism.hooks.add("wrap",function(i){if(/-link$/.test(i.type)){i.tag="a";var n=i.content;if("email-link"==i.type&&0!=n.indexOf("mailto:"))n="mailto:"+n;else if("md-link"==i.type){var t=i.content.match(e);n=t[2],i.content=t[1]}i.attributes.href=n}try{i.content=decodeURIComponent(i.content)}catch(r){}})}}(); \ No newline at end of file