Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fix for google-code-prettify w/ c#

Tags:

javascript

c#

Prettify gives types and methods the same class when tokenizing c# so they are colored the same. This is because methods are pascal case in c# instead of camel case like in java. This affects my blog and all stackoverflow c# code since they use prettify too.

Does anyone have a fix for this?

If not, you can at least star/vote the official bug that was reported in Mar/2009 so the authors take another look.

like image 940
Mike Valenty Avatar asked Dec 05 '09 00:12

Mike Valenty


People also ask

What is Google code prettify?

A Javascript module and CSS file that allows syntax highlighting of source code snippets in an html page.

How do you use prettify?

How to use. Apply class="wb-prettify" to an element on the page to load the component (once per page). Apply class="prettyprint" to a pre or code element to apply syntax highlighting. Alternatively use class="wb-prettify all-pre" to apply syntax highlighting to all pre elements on the page.


2 Answers

It is possible for identical syntax to have different meanings. There just isn't enough information to properly syntax highlight everything.

Take a look at this example:

static class Program
{
    class Foo { public class Bar { public static void Func() { } } }
    class Foo2 { public static Baz Bar2 { get; set; } }
    class Baz { public void Func2() { } }

    static void Main()
    {
        Foo.Bar.Func();
        Foo2.Bar2.Func2();
    }
}

In the first line, Bar is an inner class, and should be highlighted green. In the second line, Bar2 is a property of type Foo2, and should be highlighted black. Both Func and Func2 are functions, and should be highlighted black.

Here's how Visual Studio highlights that code.

alt text

like image 184
David Yaw Avatar answered Oct 11 '22 07:10

David Yaw


I actually wrote my own syntax highlighting library to solve problems like this. It's pretty similar to prettify but you have to specify the language explicitly.

  • Website
  • Demo
like image 35
tmont Avatar answered Oct 11 '22 08:10

tmont