domingo, 5 de febrero de 2012

Syntax highlighting

Looks like I finally have syntax highlighting... thanks to this!
Turns out the previous link worked only for Java and XML and I'm too lazy to compile my own version for supporting other languages, so I'm now resorting to google-code-prettify. To make it work here, I followed this tutorial.
I didn't quite like the default style as I wanted line numbers for every single line. Also, I didn't want it to have a completely white background, so after linking the default CSS file, I overrode some styles:
<style type="text/css">
pre.prettyprint, code.prettyprint {
        background-color: #C4C4C4;
}
li.L0, li.L1, li.L2, li.L3, li.L4, li.L5, li.L6, li.L7, li.L8, li.L9
{
    background: #F7F7F7;
    list-style-type: decimal;
}
</style>
Java example:
public class SyntaxHighlighterWorksFineHere
{
    public static void main(String[] args)
    {
        System.out.println("Yes!");
    }
}
In order to avoid to having to place the script loading line each time, I just added it to the HTML template. Et voilà!

No hay comentarios:

Publicar un comentario