Syntax Highlighting. Converting C# (et al) to HTML.

0 comments suggest edit

I’ve probably read a hundred or so posts of people looking for a way to syntax highlight source code listings in HTML. Maybe I’m the last to discover this site, but http://www.manoli.net/csharpformat/ is the answer for me so far. Just cut and paste some C#, VB, html/xml/aspx code int the text box and click “format my code” and voila! You get some clean HTML displaying nicely formatted code.

The tool allows you to optionally format the code with alternating line colors and line numbers if you so desire.

public class ThisIsSoCool
{
  ///      /// This is seriously neat.      ///      
  public void YouShouldTryThis()
  {}
}

Let’s try it with line numbers.

``

   1:  public class ThisIsAlsoCool

   2:  {

   3:    /// 

   4:    /// Look at me ma! I’m using line numbers

   5:    /// 

   6:    public void YouShouldTryThis()

   7:    {}

   8:  }
Found a typo or error? Suggest an edit! If accepted, your contribution is listed automatically here.

Comments

avatar

10 responses

  1. Avatar for Daniel Turini
    Daniel Turini June 16th, 2004

    I've been using on my blog the SnippetCompiler (http://www.sliver.com/dotnet/SnippetCompiler/), which have a cool feature "Export HTML to Clipboard". :)

  2. Avatar for pblah
    pblah March 10th, 2005

    dim obj as object



    with obj

    .first = "xx"

    .last = "yy"

    .id =2

    end with



    obj = nothing

  3. Avatar for you've been HAACKED
    you've been HAACKED April 27th, 2007

    Insert Code for Windows Live Writer

  4. Avatar for Community Blogs
    Community Blogs April 27th, 2007

    Several pople have asked me recently about the nice code syntax highlighting in my blog. For example:

  5. Avatar for me
    me August 18th, 2008

    Thanks for the link! I've been looking for something like this as well, and i love how it does SQL too!

  6. Avatar for HSH
    HSH November 8th, 2008

    is there format for CSS code? it's a lack

  7. Avatar for os
    os December 6th, 2008

    There is also a simple one that converts code to HTML that is directly pasted from Visual studio (www.dreamsys.gr/.../Code-Formatter-for-HTML.aspx)

  8. Avatar for Erik Rydeman
    Erik Rydeman January 31st, 2009

    That's excellent! Just started a blog and was looking for something like that. :)
    Cheers!

  9. Avatar for Pavel Vladov
    Pavel Vladov October 1st, 2012

    Nice article! Thanks for sharing. If you need a free online C# syntax highlighting service that colorizes C# code like Visual Studio and produces HTML ready to be inserted in a website or blog take a look at:
    Online C# Code Colorizer

  10. Avatar for Madhukar Moogala
    Madhukar Moogala May 26th, 2017

    Thanks to know this, I used https://tohtml.com/csharp/ which does pretty neat job, it has various themes too.