16

我正在尝试使用 Google prettify 突出显示一些语法,但到目前为止,它不起作用。

<link href="prettify.css" type="text/css" rel="stylesheet" />
<script type="text/javascript" src="prettify.js"></script>

<body onload="prettyPrint()" bgcolor="white">

<pre class="prettyprint">
  <code class="language-css">
  // Some source code

    class Foo {
      public int Bar { get; set; }
    }
  </code>
</pre>

有没有一种解决方案可以使这项工作在不与引导程序中已经存在的 pre 标签混淆太多的情况下进行?

4

3 回答 3

25

EDIT: for twitter bootstrap 2.0.x, it works fine with 2.1.x

Use the those 2 files instead of using the method describe in the doc.

http://twitter.github.com/bootstrap/assets/js/google-code-prettify/prettify.css

http://twitter.github.com/bootstrap/assets/js/google-code-prettify/prettify.js

This works for me

<!DOCTYPE html>
<html lang="en">
<head>
<link href="css/bootstrap.css" type="text/css" rel="stylesheet" />
<link href="prettify.css" type="text/css" rel="stylesheet" />
<script type="text/javascript" src="prettify.js"></script>
</head>
<body onload="prettyPrint()" bgcolor="white">
<pre class="prettyprint linenums languague-css">
// Some source code
class Foo {
    public int Bar { get; set; }
}
</pre>
</body>
</html>
于 2012-06-02T11:52:24.150 回答
3

不知道为什么不建议修改:

<script>
    // Activate Google Prettify in this page
    addEventListener('load', prettyPrint, false);
    $(document).ready(function(){
        // Add prettyprint class to pre elements
        $('pre').addClass('prettyprint');           
    }); // end document.ready
</script>
于 2013-06-21T16:37:42.513 回答
2

链接到 2 个文件 prettify.css 后,prettify.js 将此代码添加到您的页脚

<script>
// @prettify
!function ($) {
  $(function(){
  window.prettyPrint && prettyPrint()   
  })
}(window.jQuery);
// #prettify
</script>
于 2012-12-25T19:09:23.840 回答