diff options
Diffstat (limited to 'pastepy.py')
-rw-r--r-- | pastepy.py | 13 |
1 files changed, 11 insertions, 2 deletions
@@ -5,6 +5,15 @@ from pygments.formatters import HtmlFormatter base62_alphabet = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ' +class CustomHtmlFormatter(HtmlFormatter): + def wrap(self, source, outfile): + yield 0, '<pre>' + line = 1 + for i, t in source: + yield i, '<span id="codeline-%d">%s</span>' % (line, t) + line += 1 + yield 0, '<pre>' + class Paste(object): def __init__(self): lexers = dict([(x[0], x[1][0]) for x in get_all_lexers()]) @@ -20,7 +29,7 @@ class Paste(object): except KeyError: pass self.lexers.append(('Others' if settings.categories else 'Syntax', sorted(lexers.items(), cmp = lambda a, b: cmp(a[0], b[0])))) - self.formatter = HtmlFormatter(linenos = 'table', lineanchors = 'line', anchorlinenos = True) + self.formatter = CustomHtmlFormatter(linenos = 'table', lineanchors = 'line', anchorlinenos = True) def message(self, msg, title = 'Message'): self.start_response('200 OK', [('Content-Type', 'text/html')]) @@ -153,7 +162,7 @@ class Paste(object): def static(self): filename = settings.static_root + os.path.sep + self.path[1] - if not self.path[1] in ('paste.css', 'edit.js') or not os.path.exists(filename): + if not self.path[1] in ('paste.css', 'edit.js', 'view.js') or not os.path.exists(filename): self.start_response('404 Not Found', [('Content-Type', 'text/html'), ('Location', '/')]) return ['<a href="/">asdf</a>'] self.start_response('200 OK', [('Content-Type', mimetypes.guess_type(filename)[0] or 'text/plain')]) |