javascript - Google Prettify 线条颜色超出可见区域(可预滚动)

标签 javascript html css twitter-bootstrap pretty-print

我正在寻找使用 Google Prettify 扩展预标记上的行突出显示。这就是我所拥有的。我正在寻找一种方法来尽可能延长行突出显示。

谢谢。

<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) 上的输出结果。

As you can see the line highlighting stops

最佳答案

我遇到了同样的问题,发现下面的 CSS 解决了这个问题:

pre {
    display: flex;
}

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

有了这个,没有代码的区域将不会扩展到可用宽度,因此不同的代码片段将使用不同的宽度显示。要解决此问题,您还需要执行以下操作:

ol.linenums {
    flex: 1;
}

希望这对您有所帮助。

关于javascript - Google Prettify 线条颜色超出可见区域(可预滚动),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50702559/

相关文章:

javascript - 查找某个时间范围内去年的某个日期

javascript - 在 div 中预览多个图像时出错

javascript - 如何在带有typekit的网站上使用Trajan字体?

javascript - 是否可以根据屏幕尺寸设置表格选项?

javascript - 我应该如何在 Node 中执行此操作?一条快路和一条慢路

javascript - 如何隐藏顶部菜单后面的下拉菜单?

javascript - 当覆盖菜单打开时隐藏主滚动条

html - 使用 Notepad++ 查找并替换为正则表达式

html - 为什么图像在 Foundation 6.4 Cards Component 中被拉伸(stretch)

css top nav - 左侧导航(菜单),中间标题,右侧(更多按钮) - howto?