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

Unified Diff: lib/src/prism/plugins/autolinker/prism-autolinker.js

Issue 1418513006: update elements and fix some bugs (Closed) Base URL: git@github.com:dart-lang/polymer_elements.git@master
Patch Set: code review updates Created 5 years, 2 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
« no previous file with comments | « lib/src/prism/package.json ('k') | lib/src/prism/plugins/autolinker/prism-autolinker.min.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/src/prism/plugins/autolinker/prism-autolinker.js
diff --git a/lib/src/prism/plugins/autolinker/prism-autolinker.js b/lib/src/prism/plugins/autolinker/prism-autolinker.js
index a26b26304746b640c7141148898fce79a8ae5fcc..e56303f8edda3d8afd2c69599a0799c01676878a 100644
--- a/lib/src/prism/plugins/autolinker/prism-autolinker.js
+++ b/lib/src/prism/plugins/autolinker/prism-autolinker.js
@@ -1,6 +1,9 @@
(function(){
-if (!self.Prism) {
+if (
+ typeof self !== 'undefined' && !self.Prism ||
+ typeof global !== 'undefined' && !global.Prism
+) {
return;
}
@@ -11,19 +14,21 @@ var url = /\b([a-z]{3,7}:\/\/|tel:)[\w\-+%~/.:#=?&]+/,
// 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) {
+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
};
}
-
+
def.inside = def.inside || {};
-
+
if (type == 'comment') {
def.inside['md-link'] = linkMd;
}
@@ -33,14 +38,13 @@ for (var language in Prism.languages) {
else {
def.inside['url-link'] = url;
}
-
+
def.inside['email-link'] = email;
}
});
-
- tokens['url-link'] = url;
- tokens['email-link'] = email;
-}
+ env.grammar['url-link'] = url;
+ env.grammar['email-link'] = email;
+});
Prism.hooks.add('wrap', function(env) {
if (/-link$/.test(env.type)) {
@@ -63,4 +67,4 @@ Prism.hooks.add('wrap', function(env) {
}
});
-})();
+})();
« no previous file with comments | « lib/src/prism/package.json ('k') | lib/src/prism/plugins/autolinker/prism-autolinker.min.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698