Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(38)

Unified Diff: polymer_1.0.4/bower_components/prism/plugins/autolinker/prism-autolinker.js

Issue 1205703007: Add polymer 1.0 to npm_modules (Closed) Base URL: https://chromium.googlesource.com/infra/third_party/npm_modules.git@master
Patch Set: Renamed folder to 1.0.4 Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: polymer_1.0.4/bower_components/prism/plugins/autolinker/prism-autolinker.js
diff --git a/polymer_1.0.4/bower_components/prism/plugins/autolinker/prism-autolinker.js b/polymer_1.0.4/bower_components/prism/plugins/autolinker/prism-autolinker.js
new file mode 100644
index 0000000000000000000000000000000000000000..a26b26304746b640c7141148898fce79a8ae5fcc
--- /dev/null
+++ b/polymer_1.0.4/bower_components/prism/plugins/autolinker/prism-autolinker.js
@@ -0,0 +1,66 @@
+(function(){
+
+if (!self.Prism) {
+ return;
+}
+
+var url = /\b([a-z]{3,7}:\/\/|tel:)[\w\-+%~/.:#=?&]+/,
+ email = /\b\S+@[\w.]+[a-z]{2}/,
+ linkMd = /\[([^\]]+)]\(([^)]+)\)/,
+
+ // Tokens that may contain URLs and emails
+ candidates = ['comment', 'url', 'attr-value', 'string'];
+
+for (var language in Prism.languages) {
+ var tokens = Prism.languages[language];
+
+ Prism.languages.DFS(tokens, 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;
+ }
+ });
+
+ tokens['url-link'] = url;
+ tokens['email-link'] = email;
+}
+
+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;
+ }
+});
+
+})();

Powered by Google App Engine
This is Rietveld 408576698