Sunday, August 20, 2006

Code Formatter Plugin for Windows Live Writer

I'm quite new to blogging and have recently discovered Windows Live Writer. I've downloaded various plugins for code formatting but none provided me with what I wanted:

  • The ability to format the code 'live'
  • The ability to wrap lines
  • The ability to change the background color
  • The ability to just quickly paste what's in the clipboard as code

The plugin I implemented formats and highlights code and also does all the above. Here's a screen shot of it in use:



Here you can see that the content editor on the right can change the tab width, background color, language, and line numbers.

Below are some sample of code used with the plugin.

Here's some C# code:

public int TabWidth

{

get

{

return _content.Properties.GetInt( @"TabWidth", 4 );

}

set

{

_content.Properties.SetInt(
@"TabWidth", value );

}

}






and some XML markup...


<Triggers>

<KeyPressTrigger Key="PropertyListTrigger" Character=" ">

<KeyPressTriggerValidStates>

<KeyPressTriggerValidState State="PropertyState" />

</KeyPressTriggerValidStates>

</KeyPressTrigger>

<KeyPressTrigger Key="ValueListTrigger" Character=" ">

<KeyPressTriggerValidStates>

<KeyPressTriggerValidState State="ValueState" />

</KeyPressTriggerValidStates>

</KeyPressTrigger>

</Triggers>






I've made available the source and the binaries for this plugin.



To use it, extract the binaries to \Windows Live Writer\Plugins and run WLW. The source is in C# 2.0 and comes with a Visual Studio 2005 solution.



Note that the .NET 2.0 Framework must be installed before this plugin will work.



Going forward



I plan to put this plugin onto CodePlex (if they let me!). I also plan on making a few additions to the defaults via the Options screen. New languages can easily be added too thanks to the great ActiPro Code Highlighter. I'd also like to thank Christophe De Baene for his syntax highlighting tool. It's a great plugin and also helped me understand how to use the ActiPro control.



Please let me know if you'd like to contribute on CodePlex or if there are any features you'd like to see at steve at dunnhq d.o.t. com

97 comments:

Anonymous said...

Steve,

I added your plugin to my Windows Live Writer plugin list:

http://jeftek.spaces.live.com/blog/cns!F2042DC08607EF2!610.entry

JTB World said...

Great! I just found some minor issues.

http://jtbworld.blogspot.com

"One problem I run into is that I'm not able to use the word wrapping. It looked OK in the Normal Layout but in the Web Layout it was not nice. The width was just a hand full characters and could not be resized. Another thing is if editing the code use CTRL+Enter to add a row since Enter will trigger the OK button."

JTB World said...

I added an image showing the problem to the post on my site. If you don't see this effect could it be something with my blogger template?

Anonymous said...

Hey,
We have a WorkSpace for WLW plugins on CodePlex and will be glad to see ya there:
http://www.codeplex.com/Wiki/View.aspx?ProjectName=WLWPlugins

sagey said...

This guy has already done the same thing without the use of third party software

http://www.wilcob.com/Wilco/Toolbox/SyntaxHighlighter.aspx

might be worth getting him involved.

Anonymous said...

Hey
Absolutely cool tool. Already using it heavily in my blog.
But just figured out one issue with Wordpress. If I have word wrap enabled and then I edit it in Wordpress the whole structure kinda falls appart. I put an example into my blog:
http://remy.supertext.ch/?p=7

jv said...

Here is an example of the formatter with a couple of painful edits to the HTML. It shows how to turn on the scrollbars and the sizing of the control. This is necessary to prevent the lines from wrapping which will disrupt copy/paste of code in many weird ways.

It would be nice to have a copy button inserted that would force the clipboard copy to done as text and not HTML. This is what most code sites do with code snipettes. Yor control would make all of this very simple and straight-forward.

Thanks

http://tech-comments.blogspot.com/2006/10/live-writer-steve-dunns-code-formatter_03.html#links

Anonymous said...

Excellent work man, I would like to help you with it, upload it in someplace like codeplex and let me help. BTW, I found some troubles with special characters as \ or " with PHP code in wordpress.

Anonymous said...

Hey, I can't seem to be able to change the font of the code. Anyone knows how to do that, maybe?

Anonymous said...

Nice design of blog.

Anonymous said...

Great to see this! Thanks!

Anonymous said...

1

Anonymous said...

Thanks for article!

Anonymous said...

I like articles like this. Thanks!

Anonymous said...

Thanks for article! Very interesting.

Anonymous said...

Do you can write anything else about it? Great article!

Anonymous said...

like articles like this. Thanks
viagra Online store

Anonymous said...

Viagra
Generic Viagra
Google
Cialis
-------------------------------------------------------
Levitra
Propecia
Meridia
Yahoo!
-------------------------------------------------------
Zocor
Soma
Prozac

Anonymous said...

Indulge yourself and find partners for hot Sexual Encounters and Adult Dating at Adult friend finder free dating site!
If you are looking for a one night stand or a casual encounter, then the Adult Swingers Club is where the game is played.
If you practice a different range of sexual and sensual activities then adult personals has the Club for you.
Download over 2000 adult dvd movies, available formats: windows, mpeg, psp and ipod!
Shop for Adult Toys, DVDs and Lingerie and other Erotic Adult Products at adult sex toys shop.

Anonymous said...

bNadZ4 You have a talant! Write more!

Anonymous said...

QBlGyl Thanks to author.

Anonymous said...

4CDoAM The best blog you have!

Anonymous said...

pHe6Sk Good job!

Anonymous said...

Please write anything else!

Anonymous said...

Please write anything else!

Anonymous said...

Wonderful blog.

Anonymous said...

Magnific!

Anonymous said...

Wonderful blog.

Anonymous said...

Hello all!

Anonymous said...

Thanks to author.

Anonymous said...

Good job!

Anonymous said...

Nice Article.

Anonymous said...

zhq7tj write more, thanks.

Anonymous said...

Nice Article.

Anonymous said...

Please write anything else!

Anonymous said...

Hello all!

Anonymous said...

actually, that's brilliant. Thank you. I'm going to pass that on to a couple of people.

Anonymous said...

Hello all!

Anonymous said...

Wonderful blog.

Anonymous said...

Good job!

Anonymous said...

Please write anything else!

Anonymous said...

Please write anything else!

Anonymous said...

Wonderful blog.

Anonymous said...

Good job!

Anonymous said...

Wonderful blog.

Anonymous said...

actually, that's brilliant. Thank you. I'm going to pass that on to a couple of people.

Anonymous said...

I'm not a complete idiot, some parts are missing!

Anonymous said...

Beam me aboard, Scotty..... Sure. Will a 2x10 do?

Anonymous said...

Friends help you move. Real friends help you move bodies

Anonymous said...

A lot of people mistake a short memory for a clear conscience.

Anonymous said...

What is a free gift ? Aren't all gifts free?

Anonymous said...

Build a watch in 179 easy steps - by C. Forsberg.

Anonymous said...

Give me ambiguity or give me something else.

Anonymous said...

actually, that's brilliant. Thank you. I'm going to pass that on to a couple of people.

Anonymous said...

All generalizations are false, including this one.

Anonymous said...

I'm not a complete idiot, some parts are missing!

Anonymous said...

Oops. My brain just hit a bad sector.

Anonymous said...

Lottery: A tax on people who are bad at math.

Anonymous said...

A lot of people mistake a short memory for a clear conscience.

Anonymous said...

Energizer Bunny Arrested! Charged with battery.

Anonymous said...

Please write anything else!

Anonymous said...

A flashlight is a case for holding dead batteries.

Anonymous said...

What is a free gift ? Aren't all gifts free?

Anonymous said...

Calvin, we will not have an anatomically correct snowman!

Anonymous said...

Oops. My brain just hit a bad sector.

Anonymous said...

All generalizations are false, including this one.

Anonymous said...

I don't suffer from insanity. I enjoy every minute of it.

Anonymous said...

Ever notice how fast Windows runs? Neither did I.

Anonymous said...

What is a free gift ? Aren't all gifts free?

Anonymous said...

Oops. My brain just hit a bad sector.

Anonymous said...

The gene pool could use a little chlorine.

Anonymous said...

Friends help you move. Real friends help you move bodies.

Anonymous said...

Thanks to author.

Anonymous said...

Change is inevitable, except from a vending machine.

Anonymous said...

640K ought to be enough for anybody. - Bill Gates 81

Anonymous said...

Thanks to author.

Anonymous said...

If ignorance is bliss, you must be orgasmic.

Anonymous said...

A flashlight is a case for holding dead batteries.

Anonymous said...

I'm not a complete idiot, some parts are missing!

Anonymous said...

Clap on! , Clap off! clap@#&$NO CARRIER

Anonymous said...

If ignorance is bliss, you must be orgasmic.

Anonymous said...

The gene pool could use a little chlorine.

Anonymous said...

Wonderful blog.

Anonymous said...

I don't suffer from insanity. I enjoy every minute of it.

Anonymous said...

actually, that's brilliant. Thank you. I'm going to pass that on to a couple of people.

Anonymous said...

Save the whales, collect the whole set

Anonymous said...

Good job!

Anonymous said...

Beam me aboard, Scotty..... Sure. Will a 2x10 do?

Anonymous said...

The gene pool could use a little chlorine.

Anonymous said...

What is a free gift ? Aren't all gifts free?

Anonymous said...

Save the whales, collect the whole set

Anonymous said...

640K ought to be enough for anybody. - Bill Gates 81

Anonymous said...

I'm not a complete idiot, some parts are missing!

Anonymous said...

All generalizations are false, including this one.

Anonymous said...

What is a free gift ? Aren't all gifts free?

Anonymous said...

You've got a great picture to illustrate your text, and you know exactly

where you want it to be positioned. When you insert the picture, however,

it can not be moved or floats off the page or seems to be cut off, which

is not what you had in mind.When a picture is inserted into your Word document,

its default placement is In Line With Text. That is, Word inserts the picture

where your cursor is, even though it may not be aligned properly with the text

around it. Many times, however, you will want to change the way that text wraps

around your image.

If you want to reposition your picture choose from these options:learn more

boys not ready for college

Anonymous said...

You've got a great picture to illustrate your text, and you know exactly

where you want it to be positioned. When you insert the picture, however,

it can not be moved or floats off the page or seems to be cut off, which

is not what you had in mind.When a picture is inserted into your Word document,

its default placement is In Line With Text. That is, Word inserts the picture

where your cursor is, even though it may not be aligned properly with the text

around it. Many times, however, you will want to change the way that text wraps

around your image.

If you want to reposition your picture choose from these options:
learn more