Akshay Akshay - 4 months ago 23
jQuery Question

Remove white space from pre/code tags

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">
&lt;div class="test_class"&gt;&lt;/div&gt;
</code>
</pre>


white space

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>




Answer

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>