Post ruby or html, css, sql sourcecode in your wordpress.com blog

June 26, 2009

To correctly post Ruby (or HTML, CSS, SQL, etc.) source code you should use the following tags, and not the useless <code> tag. This way you don’t need to escape the HTML tags, the code will be highlighted and numbered.

I found out about this just now, so posting it for anyone who might get into the same trouble.

[sourcecode language='ruby']
5.times do
something
end
[/sourcecode]

This will show up like this:

5.times do
 something
end

I do not see any way to add a shortcut to this on the “Edit/Create Post”, so it’s not as comfortable as it could be, but still much better than using an external converter.

You can use one of the following params for the language attribute:
bash
cpp
csharp
css
delphi
html
java
jscript
php
python
ruby
shell
sql
vb
xml

More info here

Entry Filed under: Uncategorized. Tags: .

2 Comments Add your own

  • 1. Wolf  |  November 2, 2009 at 10:44 pm

    Hi there
    I have tried the above however it never formats as it does in your snippet.
    The code I’m using is

    <img src="hh" alt="" width="475" />

    and the result is that it doesn’t shoe the HTML but it only shows:

    [/sourcecode]

    Did you have to install a plugin or something?

    Wolf Skafte-Zauss
    http://handsoninternetmarketing.com.au
    Discover how to increase your sales using e-commerce

    Reply
    • 2. allaboutruby  |  November 4, 2009 at 1:19 am

      do you use square brackets? it should work fine, recheck what you type there

      Reply

Leave a Comment

Required

Required, hidden

Some HTML allowed:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <pre> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Trackback this post  |  Subscribe to the comments via RSS Feed


Recent posts

Starting to learn Rails?

Archive

Recent comments

gogetakame on Installing Rails on Windows (3…
gogetakame on Installing Rails on Windows (3…
allaboutruby on Installing Rails on Windows (3…
Harsha on Installing Rails on Windows (3…
Eddy Josafat on Google Maps API in Rails (YM4R…