How can I ignore leading and trailing linebreaks within an html "code" block using css, javascript or jquery?

You could use this hack:

pre:first-line {
    line-height: 0;
}

That's how pre works by default: it honors line breaks and whitespace. If you don't want the newline to render, then you have to remove it. Either outright remove it from the source or comment it out if you care how the source looks.

http://jsfiddle.net/VL8tG/

<pre><code class="cpp"><!--
-->double myNumber = (double)4;<!--
--></code></pre>

Here's another approach using Javascript that also solves the problem:

<script>
    window.onload = function (){
        // remove leading linebreaks from code blocks.
        var pre = document.getElementsByTagName("code");
        for (var i = 0, len = pre.length; i < len; i++) {
            var text = pre[i].firstChild.nodeValue;
            pre[i].firstChild.nodeValue = text.replace(/^\n+|\n+$/g, "");
        }
    }
</script>

Someone else posted this, then deleted their answer, but I thought it was worth preserving.