I am using prism.js to highlight code.This is the code that i used to make a simple output.The problem is that there are unwanted white spaces on top and bottom. Live example
<pre>
<code class="language-css">
<div class="test_class"></div>
</code>
</pre>
Is there a way to remove the unwanted spaces(the part shown in the red part) using css or jquery ?
<script src="https://cdnjs.cloudflare.com/ajax/libs/prism/0.0.1/prism.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/prism/0.0.1/prism.min.css" type="text/css">
<pre>
<code class="language-css">
.some_code{
}
</code>
</pre>
It seems that the line-breaks inside of the <code>
block is being taken into account. I guess you will have to trim your code.
<script src="https://cdnjs.cloudflare.com/ajax/libs/prism/0.0.1/prism.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/prism/0.0.1/prism.min.css" type="text/css">
<pre>
<code class="language-css">.some_code{
}</code></pre>
Prism.js has a few unfriendly quirks. I updated to this new behaviour today and could not possibly fix all of my blog posts manually.
Just run this code on page load to trim leading/trailing whitespace from all code blocks.
$(document).ready(function(){
$("code[class^='language-']").each(function(){
$(this).html($(this).html().trim());
});
Prism.highlightAll();
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With