2007-09-02

Publishing code snippets to blogger

I'm using blogger for some month now but was still looking for an easy way to post code snippets. Of course, I'm not the only one looking for such a feature. It's somehow amazing that blogger doesn't offer better support for this.

But tonight, I discovered Alex Gorbatchev's SyntaxHighligher which seems to be what I was looking for. I googled a bit more and found this HOWTO: post code (thanks gPowered.net). A few minutes later, the SyntaxHighlighter library was uploaded and my blogger template updated to enable it.

Let's try it now with a classical HelloWorld sample :
 
/**
* The HelloWorld class is an application that
* displays "Hello World!" to the standard output.
*/
public class HelloWorld {

// Display "Hello World!"
public static void main(String args[]) {
System.out.println("Hello World!");
}
}
So, how does it looks like ?

Oh, by the way, Thomas Walloschke created a neat extension for Apache configuration files. Nice. I might use his "brush" too.

16 comments:

  1. my webspace changed to http://homepage.hamburg.de/bandara/shBrush
    The old provider didn't allow a redirect.

    Thomas Walloschke

    ReplyDelete
  2. Thanks Thomas, the post has been updated accordingly.

    ReplyDelete
  3. Thank you for this information. I implemented it on my .NET blog.

    http://mctscertification.blogspot.com/

    I had a little bit of trouble and found some information that helped here:
    http://morten.lyhr.dk/2007/12/how-to-get-syntax-highlighting-in.html

    Alex's site also helped:
    http://code.google.com/p/syntaxhighlighter/wiki/BloggerMode

    ReplyDelete
  4. HOw do you upload the SyntaxHighlighter library?

    ReplyDelete
  5. skrymer,

    I didn't explain it but the whole thing is only possible if you use your own domain. If you do, you need to set a missing files host in the Advanced Settings of the Publishing tab in the Settings of your blog. It has to be a subdomain in the same domain as the blog. Blogger will then use this host if a file can't be served by the regular domain. This subdomain is where you have to upload the files.

    Pascal

    ReplyDelete
  6. See Smart way to publish code without downloading and uploading js and css files
    here.
    Don't forget to say thanks If it helps. :)

    ReplyDelete
  7. Dude, are you saying that I'm not smart ? Just kidding :)

    Thank you anyway, it's in deed more simple if we don't have to upload anything.

    But, to be honest, I don't like the idea of using files from the trunk. I'll update my template to use a tagged version and, if it works, I'll repost an updated version of this blog entry.

    BTW, SyntaxHighlighter 2.0 is out. Yeah baby !

    ReplyDelete
  8. Following is infact the much simpler method.

    http://www.blogpandit.com/2009/05/add-code-snippet-to-blogger-mystery.html

    ReplyDelete
  9. After a very, very long time here is an update of my apache brush...

    SEE
    http://homepage.hamburg.de/bandara/shBrush/HttpdApacheConf.js.html
    http://homepage.hamburg.de/bandara/shBrush/HttpdApacheConfV13.html
    http://homepage.hamburg.de/bandara/shBrush/HttpdApacheConfV22.html - NEW

    The apache config files now will be highlighted (v1.5 at this moment - but migration to v.2x follows asap) at:

    * strings
    * comments
    * directives, tags
    * arguments
    * numbers
    * variables
    * handlers
    * verbs (HTTP methods, RFC compliant)
    * urls (expertimental=RFC non-compliant)
    * adresses, ip:port
    * email (RFC compliant)
    * modules

    Todo:

    * supporting of paths (recently there is a collision with url/uri regexp - see uri support)
    * fixing uri support (tbd: shorter/weaker rfc compliant uri regex; rfc includes paths)
    * supporting of mime-types (validity checked, not as a path...)
    * migration to SyntaxHighlighter v2.x

    Hope it is helpful - thomas walloschke

    ReplyDelete
  10. After a very, very long time here is an update of my apache brush...

    SEE
    http://homepage.hamburg.de/bandara/shBrush/HttpdApacheConf.js.html
    http://homepage.hamburg.de/bandara/shBrush/HttpdApacheConfV13.html
    http://homepage.hamburg.de/bandara/shBrush/HttpdApacheConfV22.html - NEW
    http://homepage.hamburg.de/bandara/shBrush/HttpdApacheConfEx.html - NEW

    The apache config files now will be highlighted (v1.5 at this moment - but migration to v.2x follows asap) at:

    * strings
    * comments
    * directives, tags
    * arguments
    * numbers
    * variables
    * handlers
    * verbs (HTTP methods, RFC compliant)
    * urls (expertimental=not RFC compliant)
    * adresses, ip:port
    * email (RFC compliant)
    * modules
    * media-types (IANA and RFC compliant)

    Todo:

    * supporting of paths (recently there is a collision with url/uri regexp - see uri support)
    * fixing uri support (tbd: shorter/weaker rfc compliant uri regex; rfc includes paths)
    * migration to SyntaxHighlighter v2.x

    Remark:

    * some browser use very lousy js-machines
    * best js-performer is Safari at this moment

    Hope it is helpful - thomas walloschke

    ReplyDelete
  11. After a very, very long time here is an update of my apache brush...

    SEE
    http://homepage.hamburg.de/bandara/shBrush/HttpdApacheConf.js.html
    http://homepage.hamburg.de/bandara/shBrush/HttpdApacheConfV13.html
    http://homepage.hamburg.de/bandara/shBrush/HttpdApacheConfV22.html - NEW
    http://homepage.hamburg.de/bandara/shBrush/HttpdApacheConfEx.html - NEW

    The apache config files now will be highlighted (v1.5 at this moment - but migration to v.2x follows asap) at:

    * strings
    * comments
    * directives, tags
    * arguments
    * numbers
    * variables
    * handlers
    * verbs (HTTP methods, RFC compliant)
    * urls (expertimental=not RFC compliant)
    * adresses, ip:port
    * email (RFC compliant)
    * modules
    * media-types (IANA and RFC compliant)

    Todo:

    * supporting of paths (recently there is a collision with url/uri regexp - see uri support)
    * fixing uri support (tbd: shorter/weaker rfc compliant uri regex; rfc includes paths)
    * migration to SyntaxHighlighter v2.x

    Remark:

    * some browser use very lousy js-machines
    * best js-performer is Safari at this moment

    Hope it is helpful - thomas walloschke

    ReplyDelete
  12. HOw do you upload the SyntaxHighlighter library?

    ReplyDelete
  13. Hi tҺere, I enjoy reading all of your ρost. I wanted to write a lіttle commеent to
    support ʏou.

    My ԝeb-site Spanish subjunctive quizas

    ReplyDelete
  14. Hi! I just wanted to ask if you ever have any trouble with hackers?
    My last blog (wordpress) was hacked and I ended up
    losing many months of hard work due to no back up. Do you have any solutions to stop
    hackers?

    - videtesboules
    - videtesboules
    - videtesboules
    - videtesboules
    - videtesboules
    - videtesboules

    my webpage ... videtesboules

    ReplyDelete
  15. One can minecraft pocket edition cheats search unlimited mobile
    games. To get scores, it gives you an answer. Devil's badvocateThe package's high point is
    where mobile games downloading that has been minecraft pocket edition cheats designed for womens to make
    the choice pretty wisely. The birds should be played after release for testing,
    references are king! Mobile phones are not only source of the
    game of real buttons instead, restart your PC.

    ReplyDelete