Skip to content

Commit

Permalink
Remove the behaviour of Remove initial line feed plugin (remove by de…
Browse files Browse the repository at this point in the history
…fault, allow to keep with a CSS class)
  • Loading branch information
Golmote committed Aug 17, 2015
1 parent a88936a commit b8d098e
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
5 changes: 3 additions & 2 deletions plugins/remove-initial-line-feed/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ <h2>Remove initial line feed</h2>
<h1>How to use</h1>

<p>Obviously, this is supposed to work only for code blocks (<code>&lt;pre>&lt;code></code>) and not for inline code.</p>
<p>Add class <strong>remove-initial-line-feed</strong> to your desired <code>&lt;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>&lt;pre></code>.</p>
</section>

<section>
Expand All @@ -38,7 +39,7 @@ <h2>Without adding the class</h2>
</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>
&lt;div>&lt;/div>
</code></pre>

Expand Down
Original file line number Diff line number Diff line change
@@ -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)/, '');
}
Expand Down

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

0 comments on commit b8d098e

Please sign in to comment.