如何可以忽略html“代码”中的前导和尾随线断裂。块使用css,javascript或jquery? [英] How can I ignore leading and trailing linebreaks within an html "code" block using css, javascript or jquery?
问题描述
在我的HTML源代码中,我有一个代码块,如下所示(我在本页使用了showdown和highlight.js):
In my HTML source code, I have a code block like the following (I use showdown and highlight.js on this page):
<pre><code class="cpp">
double myNumber = (double)4;
</code></pre>
我的问题是第一个linebreak仍然是代码块的一部分。这可能是因为封闭的pre块,但我需要那里,因为highlight.js期望它(也显然是HTML5标准 recommended it )。代码呈现如下(注意开头的行符):
My problem is that the first linebreak remains part of the "code" block. It's probably because of the enclosing "pre" block, but I need that there because highlight.js expects it (also apparently the HTML5 standard recommends it). The code is rendered like this (note the leading line break):
所以我的问题是,使用css,javascript或jquery,如何从 block like this one?
So my question is, using css, javascript or jquery, how can I remove leading or trailing linebreaks from "code" blocks like this one?
推荐答案
您可以使用此黑客:
pre:first-line {
line-height: 0px;
}
这篇关于如何可以忽略html“代码”中的前导和尾随线断裂。块使用css,javascript或jquery?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!