Code formatting


It would be nice if there were code formatting on blog posts.

file attachments


rclarkson wrote Aug 17, 2007 at 10:31 PM

I just added an extention that begins to address this. There are still a few tweaks to be made.

aschuc wrote Aug 18, 2007 at 2:23 PM

A few days ago I made such extension too.. but it has the same problems with TinyMCE ;)


rclarkson wrote Aug 20, 2007 at 5:26 PM

did you submit something to Mads? If so send me an email from the "People" page. I need to figure out what is going on. I just looked at your site. Bizarre. I wrote my extensions the same way you did. Anyway, get back with me if you would. I am finding that the tinyMCE is taking my code and formatting it on the paste event. It looks alright but isn't what I want. Look forward to the email.

iaresean wrote Aug 22, 2007 at 3:25 PM

Try implementing FckEditor as your editor. It waaaay better than TinyMCE. Full instructions are on the Blogengine.net wiki.

iaresean wrote Aug 22, 2007 at 3:54 PM

After the FckEditor thing add the following to your stylesheet:

code { margin: 5px 0; padding: 10px; text-align: left; display: block; overflow: auto; font: 500 1em/1.5em 'Lucida Console', 'courier new', monospace; / white-space: pre; / background: #111; }

Then place your code in between code tags like such: Your code here

aschuc wrote Aug 23, 2007 at 4:14 PM


I tried something with FCKeditor and got the code formatting stuff to work with it.

I have attached my modifications.

It replaces tinyMCE.. :)

I have tested the attached stuff on an test installation and it seems to work quite well, but feel free to test it.. =)

Installation and the made modifications are described inside the package. (readme.txt)

Known problems: I haven't changed the autosave code..

rclarkson wrote Aug 25, 2007 at 1:18 AM

I just uploaded a working extension that takes care of code formatting on the sever side. If you are using the tinyMCE editor (aka default editor) then you will need to copy your code and past it into a temporary .txt file. Paste it in there and copy again. Then paste it into the tinyMCE editor. It will add tags and maybe even
tags. Don't worry about it. The extension will take care of them. When you download the current source code there is a post that gives you all the information you need to get started. It includes all of the extension class that I created.

Have fun and keep us posted.

rclarkson wrote Aug 25, 2007 at 4:22 PM

I am adding another formatter from Wilco Bauwer called Wilco.SyntaxHighlighting so the two can be compared side by side. You will disable one and enable the other and vise versa. It was sent to me in a dll form. We cannot run third party assemblies. The BlogEngine.Net must be run all by itself with NO THIRD PARTY ASEMBLIES. So, I am bring the code to the App_Code directory, I am going to use aschuc's extension and give it a whirl.

rclarkson wrote Sep 12, 2007 at 11:41 PM

I added the extension to the source code. You can see it in action at http://www.romanclarkson.us/page/Syntax-Highligting-on-Server-Side-(aka-Code-Format-Rendering).aspx

I will update the page for learning purposes.

madskristensen wrote Sep 13, 2007 at 12:15 AM

I just updated the syntax highlighter. It is starting to look really really good. Still need some tweaks to the VB.NET highlighting, but the rest seem fine

rclarkson wrote Sep 13, 2007 at 1:04 AM

So am I. I wonder what the differences are?

rclarkson wrote Sep 13, 2007 at 2:22 AM

I added some other features mentioned in the Check-in notes. I don't know about the individual code formatting. It would be nice for anyone who uses these languages to give it a try. In 1.3 I plan on turning up the heat on this and adding some js, better tutorials, etc. If you jump the gun give me a heads up so I can see what we can add. Try to follow the [code:c#|vb|tsql|html|xml; ln=on|off; alt=on|off; title=My source code; js=on; collapsed=true|false]. Yada yada yada you get the point. Even if you do it your own way I can work it into the system. I plan on using aschuc's js for the expansion and titling feature. I may even do it right now ;)

madskristensen wrote Sep 15, 2007 at 12:26 PM

Finally, BlogEngine.NET has syntax highlighting of C#, VB.NET, HTML, XML and Javascript.

Example [code:c#]your code[/code]


[code:c#]your code[/code]

nesteruk wrote Nov 23, 2008 at 10:40 AM

It's not working for me! After I switch to HTML mode, line breaks disappear. Also, there is no syntax highlighting being applied :( nice editor, though