Friday, March 06, 2009

New version of the Code Formatter Plugin

Version 2.0 of the Code Formatter Plugin for Windows Live Writer is now available.

New in this version is the ability to use different formatting engines – in this version: ActiPro and SyntaxHighlighter 2.0

Also new is the ability to output either formatted code as text or as a bitmap.

A massive thank you to ActiPro for donating the ActiPro Syntax Editor component – the best code editor available!

If you’re reading this in an aggregator, the following code snippets may look unformatted (apart from the bitmap), but if you’re not, then it should be all nicely formatted.

Here’s some output from ActiPro as text:

public int TabWidth
{
  get
  {
      return _content.GetInt(@"TabWidth", 4);
  }
  set
  {
      _content.SetInt(@"TabWidth", value);
  }
}

Here it is again as a bitmap:

image

and here it is using SyntaxHighlighter 2.0

public int TabWidth
{
  get
  {
      return _content.GetInt(@"TabWidth", 4);
  }
  set
  {
      _content.SetInt(@"TabWidth", value);
  }
}

Please feel free to read more and download it.

18 comments:

sergeb said...

Steve,

Thanks for the great plugin!

I'm having problem with it. I copied it into WLW\Plugins and when I click either of the "Formatted code" / "Higlighted code" links I get error message about not being able to access ActiProConfiguration.xml or SyntaxHighlighter2xConfiguration.xml file (the path it shows is correct and file exists). Every other time I get WLW "stopped working" message.

Any advice?

Thanks!

Steve Dunn said...

Hi sergeb,
Can you tell me what version of WLW you're using? Could you also copy and past the contents of the error message you're seeing.

Cheers,

Steve

sergeb said...

I believe I use the latest version of WLW - build 14.0.8064.206

When I first click on Formatted code I get message box:
---------------------------
Error loading languages
---------------------------
There was an error initialising this plugin:

Could not find file 'C:\Program Files\Windows Live\Writer\Plugins\ActiProConfiguration.xml'.


---------------------------
Retry Cancel
---------------------------

Then I get:

System.NullReferenceException: Object reference not set to an instance of an object.
at DunnHQ.Wlw.CodeFormatter.ContentEditors.CodeAsTextContentEditor..ctor(IProvider provider)
at DunnHQ.Wlw.CodeFormatter.ContentSources.ActiProTextContentSource.Initialize(IProperties pluginOptions)
at WindowsLive.Writer.PostEditor.ContentSources.ContentSourceInfo.get_Instance()
at WindowsLive.Writer.PostEditor.ContentSources.ContentSourceManager.PerformInsertion(IContentSourceSite sourceSite, ContentSourceInfo contentSource)

Then I click Highlighted Code and the following pops up:

System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.IO.FileNotFoundException: Could not find file 'C:\Program Files\Windows Live\Writer\Plugins\SyntaxHighlighter2xConfiguration.xml'.
File name: 'C:\Program Files\Windows Live\Writer\Plugins\SyntaxHighlighter2xConfiguration.xml'
at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy)
at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share)
at System.IO.File.OpenRead(String path)
at DunnHQ.Wlw.CodeFormatter.SyntaxHighlighter2xConfiguration..ctor()
at DunnHQ.Wlw.CodeFormatter.SyntaxHighlighter2xProvider..ctor()
at DunnHQ.Wlw.CodeFormatter.ContentEditors.ProviderFactory.Build(ProviderIdentifier providerIdentifier)
at DunnHQ.Wlw.CodeFormatter.ContentSources.SyntaxHighighter2xTextContentSource..ctor()
--- End of inner exception stack trace ---
at System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandle& ctor, Boolean& bNeedSecurityCheck)
at System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean fillCache)
at System.RuntimeType.CreateInstanceImpl(Boolean publicOnly, Boolean skipVisibilityChecks, Boolean fillCache)
at System.Activator.CreateInstance(Type type, Boolean nonPublic)
at WindowsLive.Writer.PostEditor.ContentSources.ContentSourceInfo.get_Instance()
at WindowsLive.Writer.PostEditor.ContentSources.ContentSourceManager.PerformInsertion(IContentSourceSite sourceSite, ContentSourceInfo contentSource)

or

System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.IO.FileNotFoundException: Could not find file 'C:\Program Files\Windows Live\Writer\Plugins\SyntaxHighlighter2xConfiguration.xml'.
File name: 'C:\Program Files\Windows Live\Writer\Plugins\SyntaxHighlighter2xConfiguration.xml'
at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy)
at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share)
at System.IO.File.OpenRead(String path)
at DunnHQ.Wlw.CodeFormatter.SyntaxHighlighter2xConfiguration..ctor()
at DunnHQ.Wlw.CodeFormatter.SyntaxHighlighter2xProvider..ctor()
at DunnHQ.Wlw.CodeFormatter.ContentEditors.ProviderFactory.Build(ProviderIdentifier providerIdentifier)
at DunnHQ.Wlw.CodeFormatter.ContentSources.SyntaxHighighter2xTextContentSource..ctor()
--- End of inner exception stack trace ---
at System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandle& ctor, Boolean& bNeedSecurityCheck)
at System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean fillCache)
at System.RuntimeType.CreateInstanceImpl(Boolean publicOnly, Boolean skipVisibilityChecks, Boolean fillCache)
at System.Activator.CreateInstance(Type type, Boolean nonPublic)
at WindowsLive.Writer.PostEditor.ContentSources.ContentSourceInfo.get_Instance()
at WindowsLive.Writer.PostEditor.ContentSources.ContentSourceManager.PerformInsertion(IContentSourceSite sourceSite, ContentSourceInfo contentSource)

Steve Dunn said...

Hi sergeb,
Thanks very much for the detailed info. I take it you're using a 32 bit version if Windows? Vista or XP? When you press Start/run and then type C:\Program Files\Windows Live\Writer\Plugins\ActiProConfiguration.xml - does IE appear displaying an XML file?

Also, if you're on Vista, are you an admin or standard user?

One more also... Are you launching from the start menu, a shortcut, command line, or directly from Explorer? If a shortcut, what's the location of it?

Thanks again,

Steve

sergeb said...

Found it - my plugins were installed into "C:\Program Files\Windows Live Writer\Plugins" directory. I copied Code Formatter Plugin into "C:\Program Files\Windows Live\Writer\Plugins" and it works now. Sorry, I did not notice the "/" where I have space in the path name. Thanks for your help and great plugin!

JasonBunting said...

Steve,

I too have had problems with this awesome-looking plugin. I don't know if it is because of *how* I installed WLW, because it gives me the following error when I try to use it:

There was an error initialising this plugin:

Could not find a part of the path 'C:\Documents and Settings\Jason\Plugins\ActiProConfiguration.xml'.

Notice, it is looking for the file to be in a folder underneath my settings folder. I tried putting the file there on purpose, but then get another error message. Obviously, I shouldn't have to copy a file to get this working, so is there a possibility that you can get this fixed? I can't use this tool at the moment but would love to be able to. Apparently the code has some hard-coded expectations for where things should be. I have the latest version of WLW and followed your instructions to a T, even double-checked the install path, since I noticed that someone else here also had a similar problem.

I can appreciate that you don't get paid for this (I've done open-source and free software before) and don't want you to think I am making any demands, but it sure would rock to be able to use this!

Thanks.

JasonBunting said...

Also, I am using Windows XP.

JasonBunting said...

So, I found out the problem - in the source code file for the ActiProConfiguration class, you have code like this:

using (FileStream stream = File.OpenRead("./Plugins/ActiProConfiguration.xml"))

What it should look like is this:

using (FileStream stream = File.OpenRead(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @".\Plugins\ActiProConfiguration.xml")))

So, your code is making an assumption about the current path (since you are providing a relative path) that it shouldn't make, and that seems to be causing the problems I am having.

There is a similar file path in the Save() method in that same file, and it too should have the same fix applied to it.

I will email you as well, as I would love to have this fixed so I can use the plugin.

Thanks!

Carsten said...

Found out that you can use it with wlw but not with wlspaces. wlspaces ignores the sources to render the code when using highlight syntax.

Nice tool, but with wlspaces you´ll miss some functions...

Eric Stott said...

I hate your plug-in.
Actually I love it also. I have become addicted to your plug-in, but since I have installed the latest version (2.0.0.1) I get the following Windows Live Writer error:
Windows Live Writer has encountered a problem: Could not find a part of the path 'd:\My Pictures\Blog\Plugins\ActiProConfiguration.xml'..
I have been trying to create one blog now 5 times, each time, I end up having to recreate it.
I am running on 32 bit XP.

Steve Dunn said...

Thanks for the feedback. Download v 2.0.0.2 at http://stevedunns.googlepages.com/codeformatterforwindowslivewriter

It should fix the paths problem

bluec said...

Hi, I'm trying to usE 2.0.0.2, however, I met the following exception when I click code as bitmap:
System.IO.FileNotFoundException: Could not load file or assembly 'ActiproSoftware.SyntaxEditor.Net20, Version=4.0.280.0, Culture=neutral, PublicKeyToken=21a821480e210563' or one of its dependencies. The system cannot find the file specified.
File name: 'ActiproSoftware.SyntaxEditor.Net20, Version=4.0.280.0, Culture=neutral, PublicKeyToken=21a821480e210563'
at DunnHQ.Wlw.CodeFormatter.Controls.CodeEditorControl..ctor()
at DunnHQ.Wlw.CodeFormatter.EditCodeAsImageForm.InitializeComponent()
at DunnHQ.Wlw.CodeFormatter.EditCodeAsImageForm..ctor(IProvider provider, ISettings settings)
at DunnHQ.Wlw.CodeFormatter.ContentEditors.CodeAsImageContentEditor.ShowCodeEditor(ISmartContent content)
at DunnHQ.Wlw.CodeFormatter.ContentSources.ActiProBitmapContentSource.CreateContent(IWin32Window dialogOwner, ISmartContent newContent)
at WindowsLive.Writer.PostEditor.ContentSources.ContentSourceManager.PerformInsertion(IContentSourceSite sourceSite, ContentSourceInfo contentSource)

WRN: Assembly binding logging is turned OFF.
To enable assembly bind failure logging, set the registry value [HKLM\Software\Microsoft\Fusion!EnableLog] (DWORD) to 1.
Note: There is some performance penalty associated with assembly bind failure logging.
To turn this feature off, remove the registry value [HKLM\Software\Microsoft\Fusion!EnableLog].

Click the hightlighted code or formatted code got a simular error.

It all said that ActiproSoftware.SyntaxEditor.Net20 cannot be found

Steve Dunn said...

Thanks for the recent comments. I've added the missing files to the zip so everything should work properly. Sorry about that!
Cheers,

Steve

Stefano said...

Hi there,
I have downloaded 2.0.0.2 but still it seems to be looking for files under
'C:\Program Files\Windows Live\Writer\Plugins\' folder where in fact the correct path is 'C:\Program Files\Windows Live Writer\Plugins'.

I am on Windows XP and WLW version is 14.0.8604.206 en.

Complete stack trace below.

Too bad because it really looks like a great plugin ;)

Stefano

System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.IO.FileNotFoundException: Could not find file 'C:\Program Files\Windows Live\Writer\Plugins\ActiProConfiguration.xml'.
File name: 'C:\Program Files\Windows Live\Writer\Plugins\ActiProConfiguration.xml'
at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy)
at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share)
at System.IO.File.OpenRead(String path)
at DunnHQ.Wlw.CodeFormatter.ActiProConfiguration..ctor()
at DunnHQ.Wlw.CodeFormatter.ActiProProvider..ctor()
at DunnHQ.Wlw.CodeFormatter.ActiProBitmapProvider..ctor()
at DunnHQ.Wlw.CodeFormatter.ContentEditors.ProviderFactory.Build(ProviderIdentifier providerIdentifier)
at DunnHQ.Wlw.CodeFormatter.ContentSources.ActiProBitmapContentSource..ctor()
--- End of inner exception stack trace ---
at System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandle& ctor, Boolean& bNeedSecurityCheck)
at System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean fillCache)
at System.RuntimeType.CreateInstanceImpl(Boolean publicOnly, Boolean skipVisibilityChecks, Boolean fillCache)
at System.Activator.CreateInstance(Type type, Boolean nonPublic)
at WindowsLive.Writer.PostEditor.ContentSources.ContentSourceInfo.get_Instance()
at WindowsLive.Writer.PostEditor.ContentSources.ContentSourceManager.PerformInsertion(IContentSourceSite sourceSite, ContentSourceInfo contentSource)

Steve Dunn said...

Hi Stefano,
Thanks for the feedback. The office location that WLW installs to is \program files\windows live\writer (not window live writer).

Check that you don't have both directories and that you've got some files in one and some in the other.

Cheers,

Steve

Miles said...

Steve,

I've surveyed all the code formatting plugins I can find and yours wins without a doubt.

However, I think there's a wee bugette. Every time I click on a formatted block and get the options pane on the RHS, the scrollbars combo gets another set of "none, automatic, clip, both" entries and consequently grows and grows and grows.

Also, is it intended that the Language combo doesn't maintain its selection?

Neither of these is a trainsmash, obviously.

Thanks
Miles

Cahya Dewanta said...

Hi Steve. I'm using WLW and this plugin. Both are the newest versions. WLW displays my code correctly but it becomes one single line everytime I publish it. What might cause this?Thank you so very much.

Maverick said...

Nice post...
Found a eclipse plugin for eclipse IDE users, to directly copy the code as HTML.

http://java-sample-program.blogspot.com/2012/12/copy-as-html-eclipse-plugin.html