Remove the behaviour of Remove initial line feed plugin (remove by default, allow to keep with a CSS class)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
diff --git a/plugins/remove-initial-line-feed/index.html b/plugins/remove-initial-line-feed/index.html
index 2af0b66..d981fbb 100644
--- a/plugins/remove-initial-line-feed/index.html
+++ b/plugins/remove-initial-line-feed/index.html
@@ -26,7 +26,8 @@
<h1>How to use</h1>
<p>Obviously, this is supposed to work only for code blocks (<code><pre><code></code>) and not for inline code.</p>
- <p>Add class <strong>remove-initial-line-feed</strong> to your desired <code><pre></code>.</p>
+ <p>With this plugin included, any initial line feed will be removed by default.</p>
+ <p>To bypass this behaviour, you may add the class <strong>keep-initial-line-feed</strong> to your desired <code><pre></code>.</p>
</section>
<section>
@@ -38,7 +39,7 @@
</code></pre>
<h2>With the class added</h2>
- <pre class="language-markup remove-initial-line-feed"><code>
+ <pre class="language-markup keep-initial-line-feed"><code>
<div></div>
</code></pre>
diff --git a/plugins/remove-initial-line-feed/prism-remove-initial-line-feed.js b/plugins/remove-initial-line-feed/prism-remove-initial-line-feed.js
index c4d3d0e..0b24fb5 100644
--- a/plugins/remove-initial-line-feed/prism-remove-initial-line-feed.js
+++ b/plugins/remove-initial-line-feed/prism-remove-initial-line-feed.js
@@ -1,11 +1,11 @@
Prism.hooks.add('before-highlight', function(env) {
if (env.code) {
var pre = env.element.parentNode;
- var clsReg = /\s*\bremove-initial-line-feed\b\s*/;
+ var clsReg = /\s*\bkeep-initial-line-feed\b\s*/;
if (
pre && pre.nodeName.toLowerCase() === 'pre' &&
- // Apply only if the <pre> or the <code> have the class
- (clsReg.test(pre.className) || clsReg.test(env.element.className))
+ // Apply only if nor the <pre> or the <code> have the class
+ (!clsReg.test(pre.className) && !clsReg.test(env.element.className))
) {
env.code = env.code.replace(/^(?:\r?\n|\r)/, '');
}
diff --git a/plugins/remove-initial-line-feed/prism-remove-initial-line-feed.min.js b/plugins/remove-initial-line-feed/prism-remove-initial-line-feed.min.js
index 083381a..a8930b6 100644
--- a/plugins/remove-initial-line-feed/prism-remove-initial-line-feed.min.js
+++ b/plugins/remove-initial-line-feed/prism-remove-initial-line-feed.min.js
@@ -1 +1 @@
-Prism.hooks.add("before-highlight",function(e){if(e.code){var o=e.element.parentNode,a=/\s*\bremove-initial-line-feed\b\s*/;o&&"pre"===o.nodeName.toLowerCase()&&(a.test(o.className)||a.test(e.element.className))&&(e.code=e.code.replace(/^(?:\r?\n|\r)/,""))}});
\ No newline at end of file
+Prism.hooks.add("before-highlight",function(e){if(e.code){var a=e.element.parentNode,o=/\s*\bkeep-initial-line-feed\b\s*/;!a||"pre"!==a.nodeName.toLowerCase()||o.test(a.className)||o.test(e.element.className)||(e.code=e.code.replace(/^(?:\r?\n|\r)/,""))}});
\ No newline at end of file