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

Better class name detection #1772

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions plugins/line-numbers/prism-line-numbers.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* @type {String}
*/
var PLUGIN_NAME = 'line-numbers';

/**
* Regular expression used for determining line breaks
* @type {RegExp}
Expand Down Expand Up @@ -73,7 +73,7 @@

// works only for <code> wrapped inside <pre> (not inline)
var pre = env.element.parentNode;
var clsReg = /\s*\bline-numbers\b\s*/;
var clsReg = /(?:^|\s)line-numbers(?:\s|$)/;
if (
!pre || !/pre/i.test(pre.nodeName) ||
// Abort only if nor the <pre> nor the <code> have the class
Expand Down Expand Up @@ -123,7 +123,7 @@
env.plugins = env.plugins || {};
env.plugins.lineNumbers = true;
});

/**
* Global exports
*/
Expand Down Expand Up @@ -156,4 +156,4 @@
}
};

}());
}());
2 changes: 1 addition & 1 deletion plugins/line-numbers/prism-line-numbers.min.js

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

2 changes: 1 addition & 1 deletion plugins/normalize-whitespace/prism-normalize-whitespace.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ Prism.hooks.add('before-sanity-check', function (env) {

// Normal mode
var pre = env.element.parentNode;
var clsReg = /\bno-whitespace-normalization\b/;
var clsReg = /(?:^|\s)no-whitespace-normalization(?:\s|$)/;
if (!env.code || !pre || pre.nodeName.toLowerCase() !== 'pre' ||
clsReg.test(pre.className) || clsReg.test(env.element.className))
return;
Expand Down

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

Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ if (typeof self === 'undefined' || !self.Prism || !self.document) {
Prism.hooks.add('before-sanity-check', function (env) {
if (env.code) {
var pre = env.element.parentNode;
var clsReg = /\s*\bkeep-initial-line-feed\b\s*/;
var clsReg = /(?:^|\s)keep-initial-line-feed(?:\s|$)/;
if (
pre && pre.nodeName.toLowerCase() === 'pre' &&
// Apply only if nor the <pre> or the <code> have the class
Expand All @@ -18,4 +18,4 @@ Prism.hooks.add('before-sanity-check', function (env) {
}
});

}());
}());

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