Saturday, February 15, 2014

How to display code in Blogger

After a little search on the internet how I could display code in a webpage I came across two solutions:
I've already used SyntaxHighlighter in another project so I decided to use google-code-prettify.

How to embed google-code-prettify in your page


add to the post template in your blogger dashboard:
<script src="https://google-code-prettify.googlecode.com/svn/loader/run_prettify.js?lang=css&skin=sunburst"></script>

And place your code in this tag: <pre class="prettyprint"> </pre>

Default supported languages: "bsh", "c", "cc", "cpp", "cs", "csh", "cyc", "cv", "htm", "html", "java", "js", "m", "mxml", "perl", "pl", "pm", "py", "rb", "sh", "xhtml", "xml", "xsl"

Result

// Say hello world until the user starts questioning
// the meaningfulness of their existence.
function helloWorld(world) {
  for (var i = 42; --i >= 0;) {
    alert('Hello ' + String(world));
  }
}

No comments:

Post a Comment