Code formatter online

I’ve finally got round to doing it… the code I use for posting code for articles etc has now been transformed into a small ASP.NET app. It’s based on a VB.NET article. I converted it from VB.NET to C# using Instant C# (which worked very well – just a few gotchas, far fewer than last time I tried it) and then refactored it into a more object-oriented and cleanly layered structure. There’s now a WinForms application, and a separate class library, which the ASP.NET app uses.


If you want to use the results yourself, you’ll need the stylesheet I use. Unfortunately, between this blog, my home page, and the home for the application, I’m starting to get far too many copies floating around – I may need to rationalise at some stage, as making a change is becoming painful. Anyway, just reference the stylesheet in your page header, cut and paste whatever the app provides for you (between the textbox and the sample output) and you’re away.


The site is hosted by AspSpider.NET – free ASP.NET hosting. I only signed up with them yesterday, and everything seems to work pretty seamlessly, so it seems reasonable to acknowledge them in this post :)


The code can still be made a lot prettier, but it’s getting there. I was pleased with the ASP.NET side of things – obviously (being me) I did it all in a plain text editor, and the resulting .aspx page is 29 lines, with the code-behind weighing in at 60 lines. Nice.


Future plans for it:


  • A drop down list of languages (easy) (done, 17th Nov 2005)
  • A radio-button for the format type (css, html – easy)
  • Adding Java to the list of languages (hopefully fairly easy) (done, 17th Nov 2005)
  • Giving the code back to the Darren Neimke

8 thoughts on “Code formatter online”

  1. Ooh, you’re right. Thanks for pointing it out. (It wouldn’t work with anything involving a comparison, either…) It’s easy to fix the validation part – and I’ve done it now. It doesn’t do anything special with the generics themselves though. I might try to fix that soon – I’ll see how urgent it ends up being :)

    Jon

  2. hi i found it very useful but it doesnt fix indentation?

    like:

    if(true) {
    do this;
    }

    to

    if(true) {
    do this;
    }

    thanks again :)

  3. No, it doesn’t fix indentation. It’s not meant to. In particular, it would be very annoying if it “fixed” indentation as far as it was concerned, in a way which wasn’t expected or desired.

    It’s really just a way of putting code into web pages. If you want it correctly indented, fix your code first! :)

    Jon

  4. Jon, the website is not working, the VB.NET article link is broken… and… is it open sourced?

    Thank you.

  5. Oh, and my modified C# version isn’t open sourced yet – I may make a version available for download at some point in the future, again when I’ve got more time.

    Jon

Comments are closed.