Edgewall Software
Modify

Opened 21 years ago

Closed 21 years ago

Last modified 9 years ago

#166 closed enhancement (duplicate)

See colorized source files.

Reported by: tbrkic@… 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 Christian Boos)

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 daniel, 21 years ago

Component: changset viewbrowser
Milestone: 0.7
Owner: changed from Jonas Borgström to daniel
Severity: normalenhancement
Status: newassigned

comment:2 by daniel, 21 years ago

Resolution: duplicate
Status: assignedclosed

I'm marking this as a duplicate, because the same code is needed in #127.

See #127 for continued development.

comment:3 by daniel, 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 anonymous, 20 years ago

Priority: normallow

comment:5 by anonymous, 20 years ago

Priority: lownormal

comment:6 by Christian Boos, 12 years ago

Milestone: 0.7

(clearing report:35)

comment:7 by Christian Boos, 9 years ago

Description: modified (diff)

Modify Ticket

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