alejandro5042
alejandro5042

Reputation: 861

Command-line tool to syntax highlight C# into HTML?

I'm looking for an easy way to syntax highlight C# code into HTML from the command line. Ideally this would be something like:

syntax-highlighter test.cs

... produces test.html.

Upvotes: 7

Views: 1448

Answers (3)

Matěj Zábský
Matěj Zábský

Reputation: 17272

Try GeSHi. It is an syntax highlighter for PHP, so you can write a very simple command-line PHP script that will take a name as argument and spit out the highlighted version.

Upvotes: 1

kikito
kikito

Reputation: 52698

A very good one is pygments.

The command is

pygmentize -f html /path/to/test.cs

Supports lots of languages, including C#. Requires python.

Upvotes: 4

dogbane
dogbane

Reputation: 274878

You can try SyntaxHighlighter. It doesn't literally translate C# to HTML source, but instead uses javascript. All you have to do it link to the JS files. For example:

<html>
  <head></head>
  <body>

    <pre class="brush: csharp;">
    //put all your code here
    public class Hello1
    {
       public static void Main()
       {
          System.Console.WriteLine("Hello, World!");
       }
    }
    </pre>

    <link type="text/css" rel="stylesheet" href="syntaxhighlighter/styles/shCore.css"></link>
    <link type="text/css" rel="stylesheet" href="syntaxhighlighter/styles/shThemeDefault.css"></link>
    <script type="text/javascript" src="syntaxhighlighter/scripts/shCore.js"></script>
    <script type="text/javascript" src="syntaxhighlighter/scripts/shBrushCSharp.js"></script>
    <script type="text/javascript">
        SyntaxHighlighter.all();
    </script>    
  </body>
</html>

The result is very good.

It would be really easy to write a script which uses the template above and simply cats out your source code in the right place.

Upvotes: 1

Related Questions