Google Code Prettify for wordpress

This small wordpress plugin enable syntax highlighting of code snippets in your post using Google Code Prettify.

Notice: you will need to have JavaScript enabled in your browser for this to work.

I had developed another Source Code syntax highlighting plugin using Geshi before,but they are totally different things.with Geshi,code is parsed on the server side,no javascript is needed.

It’s hard to say which is the better,choose one based on your own needs.

Download Google Code Prettify for wordpress v1.1

Installation

This plugin requires WordPress v.2.0 or later.

  1. unzip and upload the files to your wp-content/plugins/ directory.
  2. Activate the plugin by logging into your WordPress administration panel, going to ‘Plugins’, then clicking the  ‘Activate’  button for  ‘Google Code Prettify’.
  3. Done,enjoy it.

Usage

Put code snippets in <pre class="prettyprint">…</pre> or <code class="prettyprint">…</code> and it will automatically be pretty printed.

Example

Bash

#!/bin/bash

# Fibonacci numbers
# Writes an infinite series to stdout, one entry per line
function fib() {
  local a=1
  local b=1
  while true ; do
    echo $a
    local tmp=$a
    a=$(( $a + $b ))
    b=$tmp
  done
}

# output the 10th element of the series and halt
fib | head -10 | tail -1

More examples

FAQ (from http://code.google.com/p/google-code-prettify/)

  1. Which languages does it work for?
    The comments in prettify.js are authoritative but the lexer should work on a number of languages including C and friends, Java, Python, Bash, SQL, HTML, XML, CSS, Javascript, and Makefiles. It works passably on Ruby, PHP and Awk and a decent subset of Perl, but, because of commenting conventions, doesn’t work on Smalltalk, Lisp-like, or CAML-like languages.
  2. How do I specify which language my code is in?
    There’s no way to tell it which language because would complicate the interface. If it doesn’t guess the language properly, that’s a bug.
  3. Which browsers does it work with?
    It’s been tested with IE 6, Firefox 1.5 & 2, and Safari 2.0.4. Look at the test page to see if it works in your browser.
Related posts:

TAGS: , , , , , ,


119 Comments »

« Previous12111098765...21Next »
life cell returns On August 27th, 2011 at 1:44 pm (#)

Great function, usually appreciate reading your content.

The Mighty On August 4th, 2011 at 11:29 pm (#)

Thanks for your great plugins. They area very useful for me.
http://www.iammightiest.com

Google Code Prettify for wordpressを入れてみた | すくりや On April 4th, 2011 at 11:16 pm (#)

[...] google-code-prettifyをWordPressに適用するGoogle Code Prettify for wordpressを入れてみました。SyntaxHighlighterはやり過ぎ感があって好きではないので、他にもっと軽いハイライトモジュールを探していてこれに決めました。 [...]

Claudie On February 19th, 2011 at 10:29 am (#)

Great goods from you, man. I’ve understand your stuff previous to and you’re just too great. I really like what you’ve acquired here, certainly like what you are saying and the way in which you say it. You make it enjoyable and you still care for to keep it smart. I cant wait to read much more from you. This is really a great web site. my website is about massey shoes. would like some feedback if possible

Xena On February 18th, 2011 at 5:48 am (#)

We are a group of volunteers and starting a new scheme in our community. Your website offered us with valuable info to work on. You have done an impressive job and our entire community will be thankful to you. my website is about white elephant nantucket. would like some feedback if possible

Nainar On January 16th, 2011 at 4:45 pm (#)

useful informative site

security tool virus removal On January 10th, 2011 at 10:55 am (#)

When are you heading to article again? You incredibly inform lots of people!

LIC India On October 8th, 2010 at 5:04 am (#)

this is nice plugin… I love it

wp-popular.com » Blog Archive » Google Code Prettify for wordpress — javascript syntax highlighter plugin : DEAN LEE:/DEV/BLOG On October 7th, 2010 at 12:44 am (#)

[...] is the original post: Google Code Prettify for wordpress — javascript syntax highlighter plugin : DEAN LEE:/DEV/BLOG Tags: code, highlight, prettify, source, [...]

Posting code in Wordpress « Jasdeep Gosal On August 20th, 2010 at 12:01 am (#)

[...] this from the WordPress admin page → Users → Your Profile.Then I installed this plugin: Google Code Prettifier, which uses Google Code Prettify to format the code with JS&CSS. But it required some [...]

« Previous12111098765...21Next »

Leave a comment


(will not be published)