Google Prettify with Bootstrap: Line Numbers Not Showing
Asked Answered
A

3

9

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..

Arie answered 26/7, 2012 at 7:58 Comment(0)
B
22

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/

Badoglio answered 26/7, 2012 at 11:36 Comment(1)
Can you please explain me what the script snippet is doing ?Bryce
S
4

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

Siler answered 13/10, 2012 at 1:17 Comment(0)
M
2

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.

Materse answered 21/6, 2013 at 19:7 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.