Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added new Not all plugin #2074

Merged
merged 13 commits into from
Dec 2, 2019
2 changes: 1 addition & 1 deletion components.js

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions components.json
Original file line number Diff line number Diff line change
Expand Up @@ -1209,6 +1209,12 @@
"description": "Highlights the code inside diff blocks.",
"owner": "RunDevelopment",
"require": "diff"
},
"filter-highlight-all": {
"title": "Filter highlightAll",
"description": "Filters the elements the <code>highlightAll</code> and <code>highlightAllUnder</code> methods actually highlight.",
"owner": "RunDevelopment",
"noCSS": true
}
}
}
45 changes: 24 additions & 21 deletions components/prism-core.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,6 @@ var Prism = (function (_self){
var lang = /\blang(?:uage)?-([\w-]+)\b/i;
var uniqueId = 0;

/**
* Returns the Prism language of the given element set by a `language-xxxx` or `lang-xxxx` class.
*
* If no language is set for the element or the element is `null` or `undefined`, `none` will be returned.
*
* @param {Element} element
* @returns {string}
*/
function getLanguage(element) {
while (element && !lang.test(element.className)) {
element = element.parentNode;
}
if (element) {
return (element.className.match(lang) || [, 'none'])[1].toLowerCase();
}
return 'none';
}


var _ = {
manual: _self.Prism && _self.Prism.manual,
Expand Down Expand Up @@ -103,6 +85,24 @@ var _ = {
}
},

/**
* Returns the Prism language of the given element set by a `language-xxxx` or `lang-xxxx` class.
*
* If no language is set for the element or the element is `null` or `undefined`, `none` will be returned.
*
* @param {Element} element
* @returns {string}
*/
getLanguage: function (element) {
while (element && !lang.test(element.className)) {
element = element.parentElement;
}
if (element) {
return (element.className.match(lang) || [, 'none'])[1].toLowerCase();
}
return 'none';
},

/**
* Returns the script element that is currently executing.
*
Expand Down Expand Up @@ -236,21 +236,24 @@ var _ = {
highlightAllUnder: function(container, async, callback) {
var env = {
callback: callback,
container: container,
selector: 'code[class*="language-"], [class*="language-"] code, code[class*="lang-"], [class*="lang-"] code'
};

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

var elements = container.querySelectorAll(env.selector);
env.elements = Array.prototype.slice.apply(env.container.querySelectorAll(env.selector));

_.hooks.run('before-all-elements-highlight', env);

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

highlightElement: function(element, async, callback) {
// Find language
var language = getLanguage(element);
var language = _.util.getLanguage(element);
var grammar = _.languages[language];

// Set language on the element, if not present
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.

Loading