/macros/DisplayCode
Type: /type/macro
description: Macro to display code with syntax highlighting and line numbers
macro: value: $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>