Ticket #636 (closed enhancement: wontfix)
Opened 8 years ago
Last modified 5 years ago
Trac support for a SilverCity module
| Reported by: | cheald45@… | Owned by: | cboos |
|---|---|---|---|
| Priority: | lowest | Milestone: | |
| Component: | wiki system | Version: | 0.7.1 |
| Severity: | normal | Keywords: | csharp silvercity syntax coloring |
| Cc: | aj@…,David_Chilton@…,junkmail.joe@…, rhind@… | ||
| Release Notes: | |||
| API 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
Change History
Changed 8 years ago by cheald45@…
comment:1 Changed 8 years ago by cheald45@…
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 Changed 8 years ago by jonas
- Milestone set to 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 Changed 7 years ago by jonas
- Milestone changed from 0.8 to 0.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 Changed 7 years ago by aj
- 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 Changed 7 years ago by justin@…
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 Changed 7 years ago by David_Chilton@…
- 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 Changed 7 years ago by David_Chilton@…
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 Changed 7 years ago by Andreas <Andreas.L@…>
Works fine for me!!!
comment:9 Changed 7 years ago by anonymous
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
| abstract | event | new | struct |
| as | explicit | null | switch |
| base | extern | object | this |
| bool | false | operator | throw |
| break | finally | out | true |
| byte | fixed | override | try |
| case | float | params | typeof |
| catch | for | private | uint |
| char | foreach | protected | ulong |
| checked | goto | public | unchecked |
| class | if | readonly | unsafe |
| const | implicit | ref | ushort |
| continue | in | return | using |
| decimal | int | sbyte | virtual |
| default | interface | sealed | volatile |
| delegate | internal | short | void |
| do | is | sizeof | while |
| double | lock | stackalloc | |
| else | long | static | |
| enum | namespace | string |
comment:11 Changed 6 years ago by anonymous
- 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 Changed 6 years ago by anonymous
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 Changed 6 years ago by Eric Moret
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 Changed 6 years ago by anonymous
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 Changed 6 years ago by cboos
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 Changed 6 years ago by Russell Hind <rhind@…>
- Cc rhind@… added
comment:17 Changed 6 years ago by cboos
- Owner changed from jonas to cboos
comment:18 Changed 6 years ago by cboos
#2874 is now fixed. I leave this open until
someone provides a good CSharp.py implementation.
comment:19 Changed 6 years ago by mgood
- Resolution set to wontfix
- Status changed from new to closed
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 Changed 5 years ago by anonymous
- Milestone set to 0.11
- Resolution wontfix deleted
- Status changed from closed to reopened
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 Changed 5 years ago by cboos
- Milestone 0.11 deleted
- Resolution set to wontfix
- Status changed from reopened to closed
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 Changed 5 years ago by brian@…
- Resolution wontfix deleted
- Status changed from closed to reopened
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 Changed 5 years ago by cboos
- Resolution set to wontfix
- Status changed from reopened to closed
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.



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