Edgewall Software

Opened 20 years ago

Last modified 8 years ago

#166 closed enhancement

See colorized source files. — at Initial Version

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

Description

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 "-W3CDTD XHTML 1.0 TransitionalEN"

"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)


Change History (0)

Note: See TracTickets for help on using tickets.