Edgewall Software
Modify

Opened 20 years ago

Closed 18 years ago

#636 closed enhancement (wontfix)

Trac support for a SilverCity module

Reported by: cheald45@… Owned by: Christian Boos
Priority: lowest Milestone:
Component: wiki system Version: 0.7.1
Severity: normal Keywords: csharp silvercity syntax coloring
Cc: aj@…, David_Chilton@…, junkmail.joe@…, rhind@… Branch:
Release Notes:
API Changes:
Internal Changes:

Description

I've put together the modifications necessary to highlight C# code with Trac using SilverCity. I figured I'd submit them, in case you all say fit to use it. :)

Anyhow, directions are as follows:

trac/Wiki.py needs an update on line 34 to include the hash symbol in the regex.

processor_re = re.compile('#\!([a-zA-Z#]+)')

MIME_MAP in trac/Mimeview.py gets two new entries:

'c#':'text/x-csharp', 'cs':'text/x-csharp',

trac/mimeviewers/silvercity.py has a few changes:

supported_types gets a new entry:

(1, 'text/x-csharp'),

as does type_lang:

'text/x-csharp':['CSharp'],

The site-packages/SilverCity directory gets a new file: CSharp.py. This file has been attached.

Finally, site-packages/SilverCity/Keywords.py gets a new entry:

csharp_keywords = \
    "bool break case catch char class const continue "\
    "default delete do double else enum explicit export extern false float for foreach "\
    "friend goto if inline in int interface long mutable namespace new operator private protected public "\
    "register return sealed short signed sizeof static string struct switch "\
    "this throw true try typedef typeid typename union unsigned using "\
    "virtual void volatile while"

And that should do it. Trac can now syntax-color .cs files, as well as code blocks marked with #!cs or #!c#

See it in action here (source file), or here (inline code block).

Attachments (1)

CSharp.py (1.6 KB ) - added by cheald45@… 20 years ago.
CSharp.py file for SilverCity syntax coloring of C# files.

Download all attachments as: .zip

Change History (24)

by cheald45@…, 20 years ago

Attachment: CSharp.py added

CSharp.py file for SilverCity syntax coloring of C# files.

comment:1 by cheald45@…, 20 years ago

Oops - and one more addition.

site-packages/SilverCity/LanguageInfo.py contains method do_registration() on line 114. This method needs a line added to it, as well:

import CSharp

comment:2 by Jonas Borgström, 20 years ago

Milestone: 0.8

Looks good, but I think we should use #!csharp instead of #!c#. One hash-symbol is enough, it's confusing at it is already.

comment:3 by Jonas Borgström, 20 years ago

Milestone: 0.80.9

Has CSharp.py been included into the upstream version of silvercity yet? I guess there is no point in modifying trac until that happens, right?

comment:4 by aj, 20 years ago

Cc: aj@… added

I would love to see C# syntax support by default in trac. I'm having trouble getting it to work by following the instructions (HACK) above.

It doesn't look like much is happening on silvercity so I'm worried that this will drop out of sight (already milestone 0.9). I'm not a python guy, but if I can do anything to make it happen, let me know.

comment:5 by justin@…, 20 years ago

I would also like to see C# syntax by default in 0.8, but since that version is just about ready for release, I will wait. I will try the hack above in the meantime.

comment:6 by David_Chilton@…, 20 years ago

Cc: David_Chilton@… added

I found that to get the inline code coloring to work in Trac 0.8 I had to make a few changes to WikiFormatter.py.

I added:

'cs':csharp_processor,
'csharp':csharp_processor,

to the list of builtin processors on line 323 and

def csharp_processor(hdf,text,env):
    return env.mimeview.display(text, 'text/x-csharp')
}}} some where before that, with the definitions of the processors

I also ignored the change to add the hash symbol to the regex string, following jonas' suggestion of useing csharp instead of c#

comment:7 by David_Chilton@…, 20 years ago

oops forgot to put a new line after the code block, Wiki doesn't like that

also add:

def csharp_processor(hdf,text,env):
    return env.mimeview.display(text, 'text/x-csharp')

with the definitions of the processors

I also ignored the change to add the hash symbol to the regex string, following jonas' suggestion of useing csharp instead of c#

comment:8 by Andreas <Andreas.L@…>, 20 years ago

Works fine for me!!!

comment:9 by anonymous, 20 years ago

Some of those keywords you supplied are not keywords in csharp. Also there is some keywords that are not included in your list.

C# Keywords

abstracteventnewstruct
asexplicitnullswitch
baseexternobjectthis
boolfalseoperatorthrow
breakfinallyouttrue
bytefixedoverridetry
casefloatparamstypeof
catchforprivateuint
charforeachprotectedulong
checkedgotopublicunchecked
classifreadonlyunsafe
constimplicitrefushort
continueinreturnusing
decimalintsbytevirtual
defaultinterfacesealedvolatile
delegateinternalshortvoid
doissizeofwhile
doublelockstackalloc
elselongstatic
enumnamespacestring

comment:10 by Christopher Lenz, 20 years ago

Milestone: 0.9

Later.

comment:11 by anonymous, 19 years ago

Cc: junkmail.joe@… added

This would be very nice. It seems that the changes suggested are a bit out-dated so I hope the Trac team could find time to do this one.

comment:12 by anonymous, 19 years ago

Spoke too soon! Ignorning the part about process_re and the regex and just doing everything else works. I guess I wonder why this doesn't become part of the Trac main code, but I can't complain since it isn't that hard … and .Net development isn't probably as popular.

comment:13 by Eric Moret, 19 years ago

I found out trac 0.9b1 only requires the following changes to support c# highlighting:

  • Add the following entry to types in ./mimeview/silvercity.py
        'text/x-csharp':['CSharp'],
    
  • Add the following entry to MIME_MAP in ./mimeview/api.py
        'c#':'text/x-csharp', 'cs':'text/x-csharp',
    
  • Changes to SilverCity site package described in above comments

comment:14 by anonymous, 19 years ago

I don't understand, why hasn't this made it to the main development tree? it's pretty trivial, at the very least a c++ lexer could be applied to c# source files, I'll put up a request at silvercity as well.

comment:15 by Christian Boos, 19 years ago

The changes Eric Moret described above could be done in the future by customizing the TracIni, like suggested in #2874.

Modifying the ./mimeview/silvercity.py and ./mimeview/api.py source files is probably a bad idea at this point, since this would imply that SilverCity supports C# out of the box, which is apparently not the case.

It would also help if someone prepares a new C# support patch for SilverCity (the attachment:CSharp.py seems to have a number of flaws, according to the comments above).

comment:16 by Russell Hind <rhind@…>, 19 years ago

Cc: rhind@… added

comment:17 by Christian Boos, 19 years ago

Owner: changed from Jonas Borgström to Christian Boos

#2723 was marked as a duplicate.

I'll soon resume my work on making MIME-type associations customizable (#2874).

comment:18 by Christian Boos, 18 years ago

#2874 is now fixed. I leave this open until someone provides a good CSharp.py implementation.

comment:19 by Matthew Good, 18 years ago

Resolution: wontfix
Status: newclosed

I've added a request for this on SilverCity's tracker, so if changes need to be made on SilverCity's side please add them here: http://sourceforge.net/tracker/index.php?func=detail&aid=1523628&group_id=45693&atid=443741

I'm closing this ticket since I don't see a reason to keep this open unless there's upstream support for the language. I've requested that the SilverCity devs reopen this ticket when C# support is added and at that time we can support it in Trac.

comment:20 by anonymous, 18 years ago

Milestone: 0.11
Resolution: wontfix
Status: closedreopened

I understand why the ticket was closed because SilverCity needs to implement csharp highlighting before Trac can use it.

But, it looks like SilverCity is being replaced by Genshi. So, my thinking is, we can reopen this ticket and mark it for milestone:0.11.

Does a ticket need to be opened on the Genshi project, instead? Or both?

comment:21 by Christian Boos, 18 years ago

Milestone: 0.11
Resolution: wontfix
Status: reopenedclosed

No, there's a misunderstanding here: Genshi has nothing to do with syntax highlighting.

If you're interested in progress related to TracSyntaxColoring, I'd suggest that you keep an eye on #366, as Colorer supports C# highlighting out of the box.

comment:22 by brian@…, 18 years ago

Resolution: wontfix
Status: closedreopened

I've added this patch to SilverCity svn. It will be available when SilverCity 0.98 is released.

Any testing would be appreciated: svn co https://svn.sourceforge.net/svnroot/silvercity silvercity

You have to move the trunk/scintilla directory into trunk/silvercity for setup.py to work

comment:23 by Christian Boos, 18 years ago

Resolution: wontfix
Status: reopenedclosed

If SilverCity 0.9.8 will support C#, all the better. However, this is not Trac's primary concern, as we focus now on Pygments as our default highlighting engine for 0.11, and Pygments has C# support. See TracSyntaxColoring.

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain Christian Boos.
The resolution will be deleted. Next status will be 'reopened'.
to The owner will be changed from Christian Boos 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.