Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Prettify with Bootstrap: Line Numbers Not Showing

I am using Google Prettify with Twitter Bootstrap. It is working, but for some reason, the line numbers are not appearing.

Here is the markup:

<pre class="prettyprint linenums">
    <ol class="linenums">
        <li class="L0">
            <span class="kwd">public</span>
            <span class="pln"> </span>
            <span class="kwd">override</span>
            <span class="pln"> </span>
            <span class="kwd">void</span>
            <span class="pln"> </span>
            <span class="typ">Dispose</span>
            <span class="pun">()</span>
        </li>
        <li class="L1">
            <span class="pln"> </span>
            <span class="pun">{</span>
        </li>
        <li class="L2">
            <span class="pln"> </span>
            <span class="kwd">base</span>
            <span class="pun">.</span>
            <span class="typ">Dispose</span>
            <span class="pun">();</span>
        </li>
            <li class="L3">
            <span class="pln"> </span>
            <span class="pun">}</span>
        </li>
    </ol>
</pre>

and I call it like this:

<script type="text/javascript">
    $(document).ready(function () {
        prettyPrint();
    });
</script>

I don't have any custom CSS.. just using the Bootstrap CSS only..

like image 202
Matt Avatar asked Jul 26 '12 07:07

Matt


3 Answers

I recommend you use those 2 files:

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

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

and add this in your footer:

<script>
  !function ($) {
    $(function(){
      window.prettyPrint && prettyPrint()   
    })
  }(window.jQuery)
</script>

found in application.js from http://twitter.github.com/

like image 116
baptme Avatar answered Nov 18 '22 18:11

baptme


Make sure you don't have list-style: none; anywhere in your CSS file.

like image 4
henrywright Avatar answered Nov 18 '22 19:11

henrywright


The operative part of the default stylesheet is

li.L0,
li.L1,
li.L2,
li.L3,
li.L5,
li.L6,
li.L7,
li.L8 { list-style-type: none }

which turns off list bulleting for all items with index i where (i % 10) ∉ (4,9).

Adding a high priority style will override the default in prettify.css so you don't need to come up with your own theme.

<style>
li.L0,
li.L1,
li.L2,
li.L3,
li.L5,
li.L6,
li.L7,
li.L8 { list-style-type: decimal !important }
</style>

should do it.

like image 2
Mike Samuel Avatar answered Nov 18 '22 18:11

Mike Samuel