Home > Uncategorized > Using WordPress [sourcecode]

Using WordPress [sourcecode]

I wanted to use an offline editor for my blog along with the [-sourcecode] feature of WordPress for syntax highlighting using Syntaxhighlighter.

I started with Word 2010. At first it seemed perfect, I could save my blogs locally under version control (git) and had a familiar environment. Unfortunately the [-sourcecode] attribute does not properly work, when posed to WordPress each line of the source begins with a phantom html paragraph tag. There is no way to manually edit the HTML from within Word.

I moved on the Live Writer. Two issues showed up. I could save the blog files locally but not specify their location (annoying). The second issue is that [-sourcecode] did not work at all. Live Writer does have the ability to manually edit the HTML and that will work if immediately posted to WordPress. The problem is that if you ever switch from HTML back to WYSIWYG, Live Writer mangles the [-sourcecode] attribute to the point it no longer works once posted.

I played around with BlogJet, essentially the same issue as Live Writer. Works only in HTML, switching mangles the [-sourcecode]. One issue I did not like about BlogJet is that you can not use the tab or shift-tab keys to increment/decrement the tab, a common thing with formatting source code.

It seems that nearly all the offline WYSIWYG editors will have this issue.

I toyed with manually adding Syntaxhighlighter to the site and eliminating the use of [-sourcecode]. During this process I realized that if I replace [-sourcecode] with the actual HTML that WordPress uses:

<pre class=”brush: csharp;”>

That it works! The WYSIWYG editors leave this alone, so I can switch back and forth between visual and html editing.

So I started posting some code and noticed that my C# generics which contain the <> characters were incorrectly formatted. A bit of Syntaxhighlighter research and I discovered that these characters must be manually replaced unless instead of using the <tag> you use the <textarea> tag.

I attempted this on WordPress, however the installation of Syntaxhighlighter at WordPress.com is not configured to recognize the <textarea> tag.

I’ve settled on using the online WordPress editor, it properly recognized [-sourcecode], but it is, well, an online editor (yuck). I also don’t have my blog entries under version control.

A few references:

http://en.support.wordpress.com/code/posting-source-code/

http://en.blog.wordpress.com/2009/12/02/better-source-code-posting/

http://code.google.com/p/syntaxhighlighter/wiki/Usage

Advertisements
Categories: Uncategorized
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: