【问题标题】:Google Prettify line color beyond visible area (pre-scrollable)超出可见区域的 Google Prettify 线条颜色(可预滚动)
【发布时间】: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


【解决方案1】:

我遇到了同样的问题,发现下面的 CSS 修复了它:

pre {
    display: flex;
}

现在我可以横向滚动代码,这些行会正确突出显示。

这样,没有代码的区域不会扩展到可用宽度,因此不同的代码 sn-ps 将使用不同的宽度显示。要解决这个问题,您还需要这样做:

ol.linenums {
    flex: 1;
}

希望这会有所帮助。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-08-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-17
    • 2013-01-29
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多