Skip to content

Commit

Permalink
Add class that disables the normalize whitespace plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
zeitgeist87 committed Jun 5, 2016
1 parent 1158e46 commit 9385c54
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
3 changes: 3 additions & 0 deletions plugins/normalize-whitespace/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ <h1>How to use</h1>
<p>By default the plugin trims all leading and trailing whitespace of every code block.
It also removes extra indents and trailing whitespace on every line.</p>

<p>The plugin can be disabled for a particular code block by adding the class <code>no-whitespace-normalization</code> to
either the <code>&lt;pre></code> or <code>&lt;code></code> tag.</p>

<p>The default settings can be overridden with the <code class="language-javascript">setDefaults()</code> method
like so:</p>

Expand Down
4 changes: 3 additions & 1 deletion plugins/normalize-whitespace/prism-normalize-whitespace.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,10 @@ Prism.plugins.NormalizeWhitespace = new NormalizeWhitespace({

Prism.hooks.add('before-highlight', function (env) {
var pre = env.element.parentNode;
var clsReg = /\bno-whitespace-normalization\b/;
if (!env.code || !pre || pre.nodeName.toLowerCase() !== 'pre' ||
(env.settings && env.settings['whitespace-normalization'] === false))
(env.settings && env.settings['whitespace-normalization'] === false) ||
clsReg.test(pre.className) || clsReg.test(env.element.className))
return;

var children = pre.childNodes,
Expand Down

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

0 comments on commit 9385c54

Please sign in to comment.