It looks like you're offline.
Open Library logo
additional options menu

Macro to display code with syntax highlighting and line numbers

This doc was last edited by Administrator March 16, 2009.

plugin upstream
Templates in the website are disabled now. Editing them will not have any effect on the live website.
   1
   2
   3
   4
   5
   6
   7
   8
   9
  10
  11
  12
  13
  14
  15
  16
  17
  18
  19
  20
  21
  22
  23
  24
  25
  26
  27
$def with (code, lang=None)

$add_stylesheet("/static/prettify/prettify.css")
$add_javascript("/static/prettify/prettify.js")

$if lang: 
    $ lang = "lang-" + lang

$def splitlines(text):
    $ n = text.count("\n") + 1
    <table>
    <tr>
    <td stype="vertical-align: top;">
    <pre class="prettyprint linenumbers" style="border: none; padding: none;">\
    $for i in range(n):<span class="nocode linenumber">$("%4d" % (i+1))</span>
    </pre>
    </td>
    <td stype="vertical-align: top;"><pre class="prettyprint $lang" style="border: none; padding: none;">$text</pre></td>
    </tr>
    </table>


<div class="contenttext">$:splitlines(code)</div>

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