Skip to content

Commit

Permalink
Allow any element being root instead of document. (#1230)
Browse files Browse the repository at this point in the history
(better compatibility than #397)
  • Loading branch information
tanakahisateru authored and Golmote committed Dec 5, 2017
1 parent 7dc1e45 commit 69f2e2c
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
6 changes: 5 additions & 1 deletion components/prism-core.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,14 +155,18 @@ var _ = _self.Prism = {
plugins: {},

highlightAll: function(async, callback) {
_.highlightAllUnder(document, async, callback);
},

highlightAllUnder: function(container, 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 = env.elements || document.querySelectorAll(env.selector);
var elements = env.elements || container.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.

6 changes: 5 additions & 1 deletion prism.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,14 +160,18 @@ var _ = _self.Prism = {
plugins: {},

highlightAll: function(async, callback) {
_.highlightAllUnder(document, async, callback);
},

highlightAllUnder: function(container, 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 = env.elements || document.querySelectorAll(env.selector);
var elements = env.elements || container.querySelectorAll(env.selector);

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

0 comments on commit 69f2e2c

Please sign in to comment.