#166 closed enhancement (duplicate)
See colorized source files.
Reported by: | Owned by: | daniel | |
---|---|---|---|
Priority: | normal | Milestone: | |
Component: | version control/browser | Version: | 0.5.2 |
Severity: | normal | Keywords: | |
Cc: | tbrkic@… | Branch: | |
Release Notes: | |||
API Changes: | |||
Internal Changes: |
Description (last modified by )
Hi,
I wanted to be able to see colorized source files and thought of extending trac.
I reached the point where I have no idea why it doesnt show up in colors.
I downloaded and installed an python module called SilverCity and looked in the script source2html how they did.
I imported the changes into File.py in trac. And now when I klick on a file I get valid html. But it doesnt show up as html but I see all the markups aswell. If I view the source and save it to disk as html and the view it in a browser it looks exactly as I want it.
I only modified apply_template() in File.py below is the modified function. I think to see the source code with syntax highlighting would be really nice and I am quite close. So it would be nice if it could be fixe. What you need to do download and install SilverCity the default.css file in the SilverCity directory must be readable from Apache.
def apply_template (self): rev = dict_get_with_default(self.args, 'rev', None) path = dict_get_with_default(self.args, 'path', '/') if not rev: rev = fs.youngest_rev(self.fs_ptr, self.pool) else: rev = int(rev) root = fs.revision_root(self.fs_ptr, rev, self.pool) generator = None mime_type = self.get_mime_type (root, path) if mime_type == 'text/plain': #if text see if we can pretty print it try: import SilverCity from SilverCity import LanguageInfo import urllib import os generator = LanguageInfo.guess_language_for_file(path).get_default_html_generator()() except: pass size = fs.file_length(root, path, self.pool) date = fs.revision_prop(self.fs_ptr, rev, util.SVN_PROP_REVISION_DATE, self.pool) date_seconds = util.svn_time_from_cstring(date, self.pool) / 1000000 date = strftime("%a, %d %b %Y %H:%M:%S GMT", gmtime(date_seconds)) if generator: css = 'file:' + urllib.pathname2url(SilverCity.get_default_stylesheet_location()) xhtml_prefix = \ r""" <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>%(title)s</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <link rel="stylesheet" href="%(css)s" /> </head> <body> <span class="code_default"> """ sys.stdout.write(xhtml_prefix % {'title' : os.path.basename(path), 'css' : css}) else: sys.stdout.write('Last-Modified: %s\r\n' % date) sys.stdout.write('Content-Length: %d\r\n' % size) sys.stdout.write('Content-Type: %s\r\n\r\n' % mime_type) file = fs.file_contents(root, path, self.pool) while 1: data = util.svn_stream_read(file, self.CHUNK_SIZE) if not data: break if generator: suffix = \ """ </span> </body> </html> """ generator.generate_html(sys.stdout, data) sys.stdout.write(suffix) else: sys.stdout.write(data)
Attachments (0)
Change History (7)
comment:1 by , 21 years ago
Component: | changset view → browser |
---|---|
Milestone: | → 0.7 |
Owner: | changed from | to
Severity: | normal → enhancement |
Status: | new → assigned |
comment:2 by , 21 years ago
Resolution: | → duplicate |
---|---|
Status: | assigned → closed |
comment:3 by , 21 years ago
Partially implemented in [429]. The main framework is in place, and highlighting in WikiFormatting. File and Browser still needs update.. See #127.
comment:4 by , 20 years ago
Priority: | normal → low |
---|
comment:5 by , 20 years ago
Priority: | low → normal |
---|
comment:7 by , 9 years ago
Description: | modified (diff) |
---|
I'm marking this as a duplicate, because the same code is needed in #127.
See #127 for continued development.