如何可以忽略html“代码”中的前导和尾随线断裂。块使用css,javascript或jquery? [英] How can I ignore leading and trailing linebreaks within an html "code" block using css, javascript or jquery?

查看:74
本文介绍了如何可以忽略html“代码”中的前导和尾随线断裂。块使用css,javascript或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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆