RNM

September 26, 2011

Sourcecode markup tweaks in WordPress

Filed under: wordpress — rmoff @ 14:14

I noticed in Ed Stevens’ blog posting here that some sourcecode he’d posted had certain lines highlighted.

WordPress provides the sourcecode tag for marking up sourcecode in blog posts.
For example:

cd /some/random/folder
ls -l
# do not run this next line!

is much better presented as:

cd /some/random/folder
ls -l
# do not run this next line!

by wrapping it in [sourcecode] tags

I’ve known about the language=’xx’ attribute that you can use with the tag, but Ed’s posting prompted me to check on the syntax and it turns out there a few tweaks one can use. Some of them are illustrated below. The list is taken from WordPress’ Posting Source Code reference page.

[sourcecode] …. [/sourcecode]

#REF: http://en.support.wordpress.com/code/posting-source-code/
#
# This is some dummy source code to illustrate sourcecode posting on wordpress
# Line 2
# Line 3
cd /some/random/folder
ls -l
# do not run this next line!
rm -rf /some

[sourcecode language=bash] …. [/sourcecode]

#REF: http://en.support.wordpress.com/code/posting-source-code/
#
# This is some dummy source code to illustrate sourcecode posting on wordpress
# Line 2
# Line 3
cd /some/random/folder
ls -l
# do not run this next line!
rm -rf /some

[sourcecode gutter=false] …. [/sourcecode]

#REF: http://en.support.wordpress.com/code/posting-source-code/
#
# This is some dummy source code to illustrate sourcecode posting on wordpress
# Line 2
# Line 3
cd /some/random/folder
ls -l
# do not run this next line!
rm -rf /some

[sourcecode collapse=true] …. [/sourcecode]

#REF: http://en.support.wordpress.com/code/posting-source-code/
#
# This is some dummy source code to illustrate sourcecode posting on wordpress
# Line 2
# Line 3
cd /some/random/folder
ls -l
# do not run this next line!
rm -rf /some

[sourcecode highlight=3,5,6,8] …. [/sourcecode]

#REF: http://en.support.wordpress.com/code/posting-source-code/
#
# This is some dummy source code to illustrate sourcecode posting on wordpress
# Line 2
# Line 3
cd /some/random/folder
ls -l
# do not run this next line!
rm -rf /some

[sourcecode firstline=42] …. [/sourcecode]

#REF: http://en.support.wordpress.com/code/posting-source-code/
#
# This is some dummy source code to illustrate sourcecode posting on wordpress
# Line 2
# Line 3
cd /some/random/folder
ls -l
# do not run this next line!
rm -rf /some

[sourcecode padlinenumbers=3] …. [/sourcecode]

#REF: http://en.support.wordpress.com/code/posting-source-code/
#
# This is some dummy source code to illustrate sourcecode posting on wordpress
# Line 2
# Line 3
cd /some/random/folder
ls -l
# do not run this next line!
rm -rf /some

[sourcecode toolbar=false] …. [/sourcecode]

#REF: http://en.support.wordpress.com/code/posting-source-code/
#
# This is some dummy source code to illustrate sourcecode posting on wordpress
# Line 2
# Line 3
cd /some/random/folder
ls -l
# do not run this next line!
rm -rf /some

[sourcecode light=true language=’bash’] …. [/sourcecode]

#REF: http://en.support.wordpress.com/code/posting-source-code/
#
# This is some dummy source code to illustrate sourcecode posting on wordpress
# Line 2
# Line 3
cd /some/random/folder
ls -l
# do not run this next line!
rm -rf /some
About these ads

3 Comments

  1. I’m a big fan of light=”true”, which removes the toolbar and gutter in one.

    Comment by Martin Nash — September 26, 2011 @ 20:06

    • Thanks Martin, I’ve added this to the list.

      Comment by rnm1978 — September 26, 2011 @ 21:27

  2. Very nice….. ^^

    Comment by #NoteQu# — January 8, 2012 @ 03:05


RSS feed for comments on this post.

Sorry, the comment form is closed at this time.

The Silver is the New Black Theme. Create a free website or blog at WordPress.com.

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: