Skip to content

Commit

Permalink
Implemented @zeitgeist87’s suggestion in #890 re: env.elements
Browse files Browse the repository at this point in the history
  • Loading branch information
LeaVerou committed Feb 15, 2016
1 parent 49a3324 commit af8da8e
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 17 deletions.
16 changes: 8 additions & 8 deletions components/prism-core.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,19 +89,19 @@ var _ = _self.Prism = {
insertBefore: function (inside, before, insert, root) {
root = root || _.languages;
var grammar = root[inside];

if (arguments.length == 2) {
insert = arguments[1];

for (var newToken in insert) {
if (insert.hasOwnProperty(newToken)) {
grammar[newToken] = insert[newToken];
}
}

return grammar;
}

var ret = {};

for (var token in grammar) {
Expand All @@ -121,7 +121,7 @@ var _ = _self.Prism = {
ret[token] = grammar[token];
}
}

// Update references in other language definitions
_.languages.DFS(_.languages, function(key, value) {
if (value === root[inside] && key != inside) {
Expand Down Expand Up @@ -152,16 +152,16 @@ var _ = _self.Prism = {
}
},
plugins: {},

highlightAll: function(async, callback) {
var env = {
callback: callback,
selector: 'code[class*="language-"], [class*="language-"] code, code[class*="lang-"], [class*="lang-"] code'
};

_.hooks.run("before-highlightall", env);
var elements = document.querySelectorAll(env.selector);

var elements = env.elements || document.querySelectorAll(env.selector);

for (var i=0, element; element = elements[i++];) {
_.highlightElement(element, async === true, env.callback);
Expand Down
2 changes: 1 addition & 1 deletion components/prism-core.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 15 additions & 8 deletions prism.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,19 +94,19 @@ var _ = _self.Prism = {
insertBefore: function (inside, before, insert, root) {
root = root || _.languages;
var grammar = root[inside];

if (arguments.length == 2) {
insert = arguments[1];

for (var newToken in insert) {
if (insert.hasOwnProperty(newToken)) {
grammar[newToken] = insert[newToken];
}
}

return grammar;
}

var ret = {};

for (var token in grammar) {
Expand All @@ -126,7 +126,7 @@ var _ = _self.Prism = {
ret[token] = grammar[token];
}
}

// Update references in other language definitions
_.languages.DFS(_.languages, function(key, value) {
if (value === root[inside] && key != inside) {
Expand Down Expand Up @@ -157,12 +157,19 @@ var _ = _self.Prism = {
}
},
plugins: {},

highlightAll: function(async, callback) {
var elements = document.querySelectorAll('code[class*="language-"], [class*="language-"] code, code[class*="lang-"], [class*="lang-"] code');
var env = {
callback: callback,
selector: 'code[class*="language-"], [class*="language-"] code, code[class*="lang-"], [class*="lang-"] code'
};

_.hooks.run("before-highlightall", env);

var elements = env.elements || document.querySelectorAll(env.selector);

for (var i=0, element; element = elements[i++];) {
_.highlightElement(element, async === true, callback);
_.highlightElement(element, async === true, env.callback);
}
},

Expand Down

0 comments on commit af8da8e

Please sign in to comment.