Vadim's Weblog

Never stop learning.

Syntax highlighting in WordPress using Windows Live Writer

Posted by Vadim on February 24, 2009

We always strive to make our code as readable as possible in our posts.  I’ve been searching for the perfect source code plug-in since I started blogging.  I finally found the style I like to present my code.  It looks like this:

        public void Foo()
        {
            Console.WriteLine("Where's my code plug-in?");
        }

You’ve probably seen this style many times before.  Until today I had no clue how I can present my code similar to this.  It just took a little bit of googling to find out that WordPress allows us to format our code like shown above.

Here’s the syntax we need to use:

[sourcecode language='csharp']

your code here

[/sourcecode]

However, it doesn’t solves my problem completely.  I usually create my posts using Windows Live Writer (WLW) and if you try to type the code as above it is not going to look pretty.

So far I found this solution:

1. When pasting code into WLW change to Source view (Shift-F11).

2. Type following:

<pre>[sourcecode language='csharp']

-- You code goes here.

[/sourcecode]</pre>

3. Switch back to Edit view (F11).

Don’t be alarm that your code doesn’t look as expected in Windows Live Writer.  It’s going to look right in your WordPress blog.

kick it on DotNetKicks.com

About these ads

6 Responses to “Syntax highlighting in WordPress using Windows Live Writer”

  1. Check out this live writer addon. http://www.codeplex.com/wlwSyntaxHighlighter no need to go into source view and it works with the syntax highlighter you are using on here.

  2. […] that shows how to stop LiveWriter from formatting special characters.  Next, I used this technique, in which you simple wrap your “sourcecode” tag in a <pre> and then all is […]

  3. […] by Vadim on February 8, 2010 About a year ago I wrote a small article how to use syntax highlighting in WordPress using Windows Live Writer.  Few months ago I discovered  Rich Hewlett’s plug-in for Windows Live Writer that […]

  4. […] of them looked pretty terrible in WordPress. After a little more Bing searching, I discovered: http://vkreynin.wordpress.com/2009/02/24/syntax-highlighting-in-wordpress-using-windows-live-writer/. This allowed me to paste my code in directly as […]

  5. lmaran said

    You can avoid switching between “Edit” and “Source” and eliminate the “pre” tags using the PreCode plugin for WLW (http://precode.codeplex.com/). I used it with the folowing setings:
    – Surround With: PRE
    – Highlighter Class: None
    – All others checkbox: false
    …and the code, between [language] attribute.

  6. […] Source : Syntax-highlighting-in-wordpress […]

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s

 
Follow

Get every new post delivered to your Inbox.

%d bloggers like this: