Syntax highlighting on twitter bootstrap

后端 未结 3 1371
没有蜡笔的小新
没有蜡笔的小新 2021-02-07 09:05

I am trying to highlight some syntax using Google prettify but so far, its not working.



        
相关标签:
3条回答
  • 2021-02-07 09:11

    After linking to the 2 files prettify.css, prettify.js add this code to your footer

    <script>
    // @prettify
    !function ($) {
      $(function(){
      window.prettyPrint && prettyPrint()   
      })
    }(window.jQuery);
    // #prettify
    </script>
    
    0 讨论(0)
  • 2021-02-07 09:18

    Not sure why it wasn't suggested to modify with:

    <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>
    
    0 讨论(0)
  • 2021-02-07 09:21

    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>
    
    0 讨论(0)
提交回复
热议问题