Skip to content

Commit c9762c6

Browse files
Better class name detection for plugins (#1772)
This improves the class name regex of a few plugins to avoid false positives.
1 parent a2d445d commit c9762c6

File tree

6 files changed

+10
-10
lines changed

6 files changed

+10
-10
lines changed

plugins/line-numbers/prism-line-numbers.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* @type {String}
1010
*/
1111
var PLUGIN_NAME = 'line-numbers';
12-
12+
1313
/**
1414
* Regular expression used for determining line breaks
1515
* @type {RegExp}
@@ -73,7 +73,7 @@
7373

7474
// works only for <code> wrapped inside <pre> (not inline)
7575
var pre = env.element.parentNode;
76-
var clsReg = /\s*\bline-numbers\b\s*/;
76+
var clsReg = /(?:^|\s)line-numbers(?:\s|$)/;
7777
if (
7878
!pre || !/pre/i.test(pre.nodeName) ||
7979
// Abort only if nor the <pre> nor the <code> have the class
@@ -123,7 +123,7 @@
123123
env.plugins = env.plugins || {};
124124
env.plugins.lineNumbers = true;
125125
});
126-
126+
127127
/**
128128
* Global exports
129129
*/
@@ -156,4 +156,4 @@
156156
}
157157
};
158158

159-
}());
159+
}());

plugins/line-numbers/prism-line-numbers.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

plugins/normalize-whitespace/prism-normalize-whitespace.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ Prism.hooks.add('before-sanity-check', function (env) {
148148

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

plugins/normalize-whitespace/prism-normalize-whitespace.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

plugins/remove-initial-line-feed/prism-remove-initial-line-feed.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ if (typeof self === 'undefined' || !self.Prism || !self.document) {
77
Prism.hooks.add('before-sanity-check', function (env) {
88
if (env.code) {
99
var pre = env.element.parentNode;
10-
var clsReg = /\s*\bkeep-initial-line-feed\b\s*/;
10+
var clsReg = /(?:^|\s)keep-initial-line-feed(?:\s|$)/;
1111
if (
1212
pre && pre.nodeName.toLowerCase() === 'pre' &&
1313
// Apply only if nor the <pre> or the <code> have the class
@@ -18,4 +18,4 @@ Prism.hooks.add('before-sanity-check', function (env) {
1818
}
1919
});
2020

21-
}());
21+
}());

plugins/remove-initial-line-feed/prism-remove-initial-line-feed.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)