It's my pretty, my beautiful pretty...
Since I would like to post code snippet, I would like to see them pretty, highlighted and well-indented.
I've tried Google Prettify, but I cannot getting it work.
So I go through JQuery Syntax Highlighter, and that's it!
With few lines of code added to the <head> tag for your html page, you just have to add the attribute class="highlight" to a <pre> to get it highlighted:
Here's the code to add to <head>:
<script type="text/javascript"> $.SyntaxHighlighter.init({ 'wrapLines':false, 'lineNumbers': false, 'theme': 'google', 'themes': ['google'] }); </script>
Heres the code to add to <body> for a code block:
<pre class="highlight"> <!-- Insert your code here --> <!-- Support bsh, c, html, java, js, mxml, perl, pl, xhtml, xml, xsl & many more --> </pre>
Here is an example of Java code:
public static String documentToString(Document d) throws Exception { String xmlString = ""; if (d != null) { StringWriter stw = new StringWriter(); Transformer serializer = TransformerFactory.newInstance().newTransformer(); serializer.transform(new DOMSource(d), new StreamResult(stw)); xmlString = stw.toString(); } return xmlString; }
However, the first snippet was HTML code. Since the browser interpreted directly the HTML code, you should to specify to the css that it is Html and replace the < & > by the correct html code < & > :
<pre class="language-html"> <pre class="highlight"> <!-- Insert your code here --> <!-- Support bsh, c, html, java, js, mxml, perl, pl, xhtml, xml, xsl & many more --> </pre> </pre>
So that's pretty easy and it's pretty well!
Julien















