【发布时间】:2018-06-05 14:25:20
【问题描述】:
我正在寻找使用 Google Prettify 扩展 pre 标签上的线条突出显示。这就是我所拥有的。我正在寻找一种尽可能延长线条突出显示的方法。
谢谢。
<html>
<head>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/prettify/r298/prettify.min.css">
<script src="https://cdn.rawgit.com/google/code-prettify/master/loader/run_prettify.js"></script>
<style>
pre {
max-height: 100%;
/* These aren't needed for Google Chrome, but are needed for Edge to force no-wrap*/
word-break: normal !important;
word-wrap: normal !important;
white-space: pre !important;
}
</style>
</head>
<body>
<pre id="code_insert" class="prettyprint linenums lang-java pre-scrollable">
public static void main(String[] args) {
System.out.println("If you scroll past the visible area, really really really really really far, the line highlighting is going to break......");
return;
}
</pre>
<script>
PR.prettyPrint();
</script>
</body>
</html>
这是在 Google Chrome 66 和 Microsoft Edge 41 (Windows 10) 上的输出。
【问题讨论】:
-
您的代码 sn-p 在通过 StackOverflow 运行时似乎在我的浏览器上没有出现问题,因为无法向右滚动更远?当然,那可能只是我。
-
我张贴了输出结果的图片。蓝/白线突出显示不起作用。
-
是的 - 我无法在 Safari 中复制它,因为线条环绕。屏幕截图确实清楚地说明了问题所在。
-
我添加了一些额外的 CSS 来强制不换行。
-
我深入研究了一下,Bootstrap 对预滚动类的实际操作是这样的:
.pre-scrollable { max-height: 340px; overflow-y: scroll; }因此,问题可能归结为overflow-y: scroll和 pretty-print 处理线条背景。
标签: javascript html css twitter-bootstrap pretty-print