Skip to content

Commit

Permalink
Move removal of initial line feed to a plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
Golmote committed Aug 17, 2015
1 parent 14f3f80 commit ed9f2b2
Show file tree
Hide file tree
Showing 7 changed files with 77 additions and 9 deletions.
5 changes: 5 additions & 0 deletions components.js
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,11 @@ var components = {
"title": "Highlight Keywords",
"owner": "vkbansal",
"noCSS": true
},
"remove-initial-line-feed": {
"title": "Remove initial line feed",
"owner": "Golmote",
"noCSS": true
}
}
};
4 changes: 0 additions & 4 deletions components/prism-core.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,10 +181,6 @@ var _ = _self.Prism = {
code: code
};

if(code) {
env.code = code.replace(/^(?:\r?\n|\r)/, '');
}

if (!code || !grammar) {
_.hooks.run('complete', env);
return;
Expand Down
2 changes: 1 addition & 1 deletion components/prism-core.min.js

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

57 changes: 57 additions & 0 deletions plugins/remove-initial-line-feed/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<!DOCTYPE html>
<html lang="en">
<head>

<meta charset="utf-8" />
<link rel="shortcut icon" href="favicon.png" />
<title>Remove initial line feed ▲ Prism plugins</title>
<base href="../.." />
<link rel="stylesheet" href="style.css" />
<link rel="stylesheet" href="themes/prism.css" data-noprefix />
<script src="prefixfree.min.js"></script>

<script>var _gaq = [['_setAccount', 'UA-33746269-1'], ['_trackPageview']];</script>
<script src="http://www.google-analytics.com/ga.js" async></script>
</head>
<body>

<header>
<div class="intro" data-src="templates/header-plugins.html" data-type="text/html"></div>

<h2>Remove initial line feed</h2>
<p>Removes the initial line feed in code blocks.</p>
</header>

<section class="language-markup">
<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>
</section>

<section>
<h1>Examples</h1>

<h2>Without adding the class</h2>
<pre class="language-markup"><code>
&lt;div>&lt;/div>
</code></pre>

<h2>With the class added</h2>
<pre class="language-markup remove-initial-line-feed"><code>
&lt;div>&lt;/div>
</code></pre>

</section>

<footer data-src="templates/footer.html" data-type="text/html"></footer>

<script src="prism.js"></script>
<script src="plugins/remove-initial-line-feed/prism-remove-initial-line-feed.js"></script>
<script src="utopia.js"></script>
<script src="components.js"></script>
<script src="code.js"></script>


</body>
</html>
13 changes: 13 additions & 0 deletions plugins/remove-initial-line-feed/prism-remove-initial-line-feed.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Prism.hooks.add('before-highlight', function(env) {
if (env.code) {
var pre = env.element.parentNode;
var clsReg = /\s*\bremove-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))
) {
env.code = env.code.replace(/^(?:\r?\n|\r)/, '');
}
}
});

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

4 changes: 0 additions & 4 deletions prism.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,10 +186,6 @@ var _ = _self.Prism = {
code: code
};

if(code) {
env.code = code.replace(/^(?:\r?\n|\r)/, '');
}

if (!code || !grammar) {
_.hooks.run('complete', env);
return;
Expand Down

0 comments on commit ed9f2b2

Please sign in to comment.