Pygments for Windows Live Writer

Pygments is an extremely versatile Python library that does syntax highlighting. It not only supports many input languages, but can also output in many common markup formats (for wikis and so on).

Windows Live Writer is a WYSIWYG Windows blogging tool by Microsoft. It allows you to write blog entries on your desktop (shock news - not everything needs to happen online), including adding images and videos. It integrates with blog services like Windows Live, Wordpress, Blogger, Live Journal, TypePad, and many more. I've never used it, but hear good things about it from developers I respect.

Devhawk (Harry Pierson the Microsoft IronPython PM) uses live writer, and has written a plugin that uses IronPython and Pygments with a Windows Forms multi-line textbox as the code editor window.
Pygments for WL Writer is a smart content source. In WL Writer’s terminology, that means when you click inserted text in the editor window, it is treated as an atomic entity which you can then edit by using the Edit Code button in the Pygments for WL Writer sidebar editor. I I often found that I would edit my code multiple times – usually to shorten lines so they’d fit on my blog without wrapping. CodeHTMLer for WL Writer is a standard content source, so it just spews the formatted code as HTML onto the page.

From an IronPython perspective, there’s some interesting stuff there. I decided to compile the pygments library into a DLL for easier distribution. If you look in the source, there’s a folder for the Pygments source as well as the parts of the standard Python library that Pygments depends on and my custom HTML formatter. Those all get compiled via a custom script which can be called by the build.bat file in the project root.
As usual this project is available for download from Harry's Skydrive. The source is up on Github. There are plenty of features he is thinking of adding, so if you use it don't forget to give him feedback.

In a separate post he notes an update he has made (download URL is unchanged).
The only change is that I now override OnSelectedContentChanged in the sidebar control. That way, if I have multiple blocks of pygmented code in a given post, the sidebar UI updates with the correct language and color scheme of the currently selected code block.
Quite a few of Harry's projects are up on GitHub. Harry has enabled issue tracking so that you can now submit issues, bugs and feature requests:
Speaking of GitHub; ipydbg and IronPython-URLs got a nice shoutout on the GitHub blog:

Comments

Popular posts from this blog

Extending Abobe Flash Player and AIR with Python and Ruby

IronPython Tools for Visual Studio CTP3

Further Adventures of the Debugger