Edgewall Software
Modify

Opened 18 years ago

Closed 18 years ago

#2723 closed enhancement (duplicate)

C# syntax highlighting

Reported by: mdk@… Owned by: Jonas Borgström
Priority: normal Milestone:
Component: version control/browser Version: 0.9.3
Severity: normal Keywords:
Cc: Branch:
Release Notes:
API Changes:
Internal Changes:

Description

Would be good if Trac supported C# source highlighting. I guess that's the only major format missing.

Attachments (1)

silvercity_cs.patch (12.8 KB ) - added by mdk@… 18 years ago.
SilverCity 0.9.6 patch to add support for C# syntax highlighting

Download all attachments as: .zip

Change History (6)

comment:1 by simon-code@…, 18 years ago

We are using SilverCity for highlighting, and after some research on the matter it seems that the highlighter actually supports C# - or rather the C/C++ formatter also supports C# syntax.

The .cs ending is also used for the Trac templating system (ClearSilver) that currently it not in the map. It will change from no formatting to C# formatting, and it actually picks up on some keywords and string formatting that makes it OK (but by no means complete…)

For us C# is more important as well, so a solution is to make changes in trunk/trac/mimeview/api.py as follows:

CODE_MIME_ADDITIONS = {
    'cs': 'text/x-c++src',
    'aspx': 'text/x-asp',
    'resx': 'text/xml',
    'ascx': 'text/x-asp',
    'master': 'text/x-asp',
    'config': 'text/xml',
    'sitemap': 'text/xml',
}
MIME_MAP.update(CODE_MIME_ADDITIONS)

Either you can put the dictionary items right into the MIME_MAP, or put the code above into the file after the definition of MIME_MAP, or (as I have done to leave the Trac code intact) in something that executes as part of a custom plugin or similar in __init__.py or a file that it imports (need from trac.mimeview.api import MIME_MAP before the code above if you do this).

As you can see we have also added some other common ASP.Net endings that all get rendered relatively OK through default SilverCity install.

comment:2 by mdk@…, 18 years ago

Thanks, I got it working fairly easy on my testing/experimental Track installation (sample). It obviously lacks some C#-specific keywords (set, get, internal, delegate) but I guess the keywords can be fairly easily added to SilverCity.

I'm going to play with this a bit since I want to get some GLib-specific keywords (gint32, gint64, gfloat) in C-syntax as well. Hopefully we can push it upstream.

comment:3 by mdk@…, 18 years ago

I'm attaching a patch against SilverCity-0.9.6 that adds support for full C# highlighting without altering the C++/C module/keywords. I duplicated the lexer/keywords table of the CPP module and tweaked it reflect the C# specifics.

by mdk@…, 18 years ago

Attachment: silvercity_cs.patch added

SilverCity 0.9.6 patch to add support for C# syntax highlighting

comment:4 by mdk@…, 18 years ago

Ah, forgot to add - the new module is called CS. It needs to be enabled in trunk/trac/mimeview/silvercity.py with something like:

types = {
    ...
    ...
    'text/x-c#src':['CS'],
    ...
    ...
}

comment:5 by Christian Boos, 18 years ago

Resolution: duplicate
Status: newclosed

See #2874 for a suggested way to customize the MIME type associations to preview renderers.

As for the C# topic, this is a duplicate of #636.

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain Jonas Borgström.
The resolution will be deleted. Next status will be 'reopened'.
to The owner will be changed from Jonas Borgström to the specified user.

Add Comment


E-mail address and name can be saved in the Preferences .
 
Note: See TracTickets for help on using tickets.