diff --git a/components.js b/components.js index 0674d04acb..35417088ec 100644 --- a/components.js +++ b/components.js @@ -645,6 +645,11 @@ var components = { "owner": "zeitgeist87", "after": "unescaped-markup", "noCSS": true + }, + "data-uri-highlight": { + "title": "Data-URI Highlight", + "owner": "Golmote", + "noCSS": true } } }; diff --git a/plugins/autolinker/prism-autolinker.js b/plugins/autolinker/prism-autolinker.js index e56303f8ed..03b6815b77 100644 --- a/plugins/autolinker/prism-autolinker.js +++ b/plugins/autolinker/prism-autolinker.js @@ -14,36 +14,42 @@ var url = /\b([a-z]{3,7}:\/\/|tel:)[\w\-+%~/.:#=?&]+/, // Tokens that may contain URLs and emails candidates = ['comment', 'url', 'attr-value', 'string']; -Prism.hooks.add('before-highlight', function(env) { - // Abort if grammar has already been processed - if (!env.grammar || env.grammar['url-link']) { - return; - } - Prism.languages.DFS(env.grammar, function (key, def, type) { - if (candidates.indexOf(type) > -1 && Prism.util.type(def) !== 'Array') { - if (!def.pattern) { - def = this[key] = { - pattern: def - }; - } +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 || {}; + 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; + 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; + } +}; - def.inside['email-link'] = email; - } - }); - env.grammar['url-link'] = url; - env.grammar['email-link'] = email; +Prism.hooks.add('before-highlight', function(env) { + Prism.plugins.autolinker.processGrammar(env.grammar); }); Prism.hooks.add('wrap', function(env) { diff --git a/plugins/autolinker/prism-autolinker.min.js b/plugins/autolinker/prism-autolinker.min.js index 3e2aeced56..de389b8c0f 100644 --- a/plugins/autolinker/prism-autolinker.min.js +++ b/plugins/autolinker/prism-autolinker.min.js @@ -1 +1 @@ -!function(){if(("undefined"==typeof self||self.Prism)&&("undefined"==typeof global||global.Prism)){var i=/\b([a-z]{3,7}:\/\/|tel:)[\w\-+%~\/.:#=?&]+/,n=/\b\S+@[\w.]+[a-z]{2}/,e=/\[([^\]]+)]\(([^)]+)\)/,t=["comment","url","attr-value","string"];Prism.hooks.add("before-highlight",function(a){a.grammar&&!a.grammar["url-link"]&&(Prism.languages.DFS(a.grammar,function(a,r,l){t.indexOf(l)>-1&&"Array"!==Prism.util.type(r)&&(r.pattern||(r=this[a]={pattern:r}),r.inside=r.inside||{},"comment"==l&&(r.inside["md-link"]=e),"attr-value"==l?Prism.languages.insertBefore("inside","punctuation",{"url-link":i},r):r.inside["url-link"]=i,r.inside["email-link"]=n)}),a.grammar["url-link"]=i,a.grammar["email-link"]=n)}),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}})}}(); \ No newline at end of file +!function(){if(("undefined"==typeof self||self.Prism)&&("undefined"==typeof global||global.Prism)){var i=/\b([a-z]{3,7}:\/\/|tel:)[\w\-+%~\/.:#=?&]+/,n=/\b\S+@[\w.]+[a-z]{2}/,e=/\[([^\]]+)]\(([^)]+)\)/,t=["comment","url","attr-value","string"];Prism.plugins.autolinker={processGrammar:function(a){a&&!a["url-link"]&&(Prism.languages.DFS(a,function(a,r,l){t.indexOf(l)>-1&&"Array"!==Prism.util.type(r)&&(r.pattern||(r=this[a]={pattern:r}),r.inside=r.inside||{},"comment"==l&&(r.inside["md-link"]=e),"attr-value"==l?Prism.languages.insertBefore("inside","punctuation",{"url-link":i},r):r.inside["url-link"]=i,r.inside["email-link"]=n)}),a["url-link"]=i,a["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}})}}(); \ No newline at end of file diff --git a/plugins/data-uri-highlight/index.html b/plugins/data-uri-highlight/index.html new file mode 100644 index 0000000000..ac817e44b3 --- /dev/null +++ b/plugins/data-uri-highlight/index.html @@ -0,0 +1,60 @@ + + +
+ + + +Highlights data-URI contents.
+Data-URIs will be highlighted automatically, provided the needed grammar is loaded. + The grammar to use is guessed using the MIME type information.
+div {
+ border: 40px solid transparent;
+ border-image: 33.334% url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" width="30" height="30"> \
+ <circle cx="5" cy="5" r="5" fill="%23ab4"/><circle cx="15" cy="5" r="5" fill="%23655"/> \
+ <circle cx="25" cy="5" r="5" fill="%23e07"/><circle cx="5" cy="15" r="5" fill="%23655"/> \
+ <circle cx="15" cy="15" r="5" fill="hsl(15, 25%, 75%)"/> \
+ <circle cx="25" cy="15" r="5" fill="%23655"/><circle cx="5" cy="25" r="5" fill="%23fb3"/> \
+ <circle cx="15" cy="25" r="5" fill="%23655"/><circle cx="25" cy="25" r="5" fill="%2358a"/></svg>');
+ padding: 1em;
+ max-width: 20em;
+ font: 130%/1.6 Baskerville, Palatino, serif;
+}
+
+