This project is read-only.

Code syntax formatting

Oct 9, 2007 at 1:46 PM
Edited Oct 9, 2007 at 2:15 PM
I can't get the code syntax highlighting to work on my posts. When I try the [code:c#]my code[/code] it seems to do a little formatting, but it still shows the [code:c#] and [/code] in the posts. I'm running 1.2 with the fckeditor. Any ideas?
Oct 9, 2007 at 6:28 PM
I have the same problem, but still running the tinymce editor.
Oct 12, 2007 at 7:50 AM
Exactly the same problem here too. I'm also using the tinymce editor, but everything i've tried to do in the formatting has failed so far. Hopefully Mads will point us in the right direction
Oct 12, 2007 at 12:06 PM
Edited Oct 12, 2007 at 12:07 PM
i managed to make it work by editing HTML source of the post to look like this:

your source code


i think that <pre> tags are not needed, because regex expression looks for <p>[code:*]</p>, but i can't check it now because i don't have an engine installation here. Anyway, try to play with this and it should work.
Oct 12, 2007 at 1:29 PM
Edited Oct 12, 2007 at 1:30 PM
Top job zdeslav. That worked first time and I think you're also correct about the <pre> tags not being needed
Oct 17, 2007 at 4:43 PM
Still doesn't work for me. The "[code:c#]" goes away and the code is formatted, but I still get the "[/code]" at the end of the code section. Again, I'm using fckeditor.
Oct 24, 2007 at 1:58 AM
Anyone get this to work right? I tried what zdeslav suggested, and it at least applied the styles to the code. But the code:c and /code items still appear in the page. The rendered html still has them (obviously), and they're inside a <div class="code"> section. Not sure how to correct this.

Note I'm just doing this with the built-in TinyMCE editor.


Oct 24, 2007 at 3:54 PM
Try to copy code to notepad so it strips all the formatting and then copy/paste from notepad to TinyMCE. That is the only way it works for me…
Nov 27, 2007 at 6:25 PM
syntax highlighting has never worked for me :( even with these tips.
Nov 27, 2007 at 6:59 PM
I've gotten to the point where I just do screenshots of the code it got way to complicated to do the syntax highlighting effectively.
Nov 27, 2007 at 10:14 PM
I understand that this is something that would be ideally fixed in the built-in editor. But in the mean time, have you considered using Windows Live Writer with the Code Snippet plugin for Windows Live Writer (shameless plug)? You can get the binaries directly from the Windows Live Gallery. Or, you can get the source code for it from CodePlex from the Plugin Collection for Windows Live Writer project.

I am using this combination for my own blog (granted, I'm currently using Blogger) and as part of my evaluation of BlogEngine.NET. It seems to work well. Just a thought.
Nov 28, 2007 at 9:42 PM
Would someone please explain to me how to use the Syntax Highlighter from scratch with a default install of 1.2 please! I've wasted 2 hours on Google and experimenting. PS - Where is the wiki on this?
Nov 28, 2007 at 10:41 PM
I did a post on syntax highlighting while back if anybody are interested:
Nov 29, 2007 at 3:45 PM
Great blog rtur. Thanks.
Nov 29, 2007 at 4:06 PM
Ok that's it... The built in Syntax highlighter is utterly terrible. It shouldn't be included in the release at at. Blog Engine is a quality app, granted, but this highlighter is ridiculous. I'm sorry guys for complaining, but this should be easy to use feature. We all know what a good syntax highlighter should do and this is not it.

--- Ignores line breaks. <--- this is the worst.
Jan 25, 2008 at 8:10 PM
bump bump bump!!!
Apr 13, 2008 at 1:55 PM
Because of the complains about the built in syntax highlighter I'm improving it and I'm blogging about it here:
May 7, 2008 at 12:13 PM
A new version of the syntax highlighter with better recognition of code tags as well as coloring of types in C# is available here:

May 7, 2008 at 5:21 PM
You might also want to have a look at for an alternative...
Nov 8, 2008 at 12:26 PM
How can i add line numbers?