From 708125327434ec851100f2df1dbbaca241317b7f Mon Sep 17 00:00:00 2001 From: Jon Bergli Heier Date: Thu, 28 Jan 2010 00:36:38 +0100 Subject: Implemented dynamic highlighting of lines. This currently only works when opening URLs with an anchor. --- pastepy.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'pastepy.py') diff --git a/pastepy.py b/pastepy.py index cc5514d..67c2f44 100644 --- a/pastepy.py +++ b/pastepy.py @@ -5,6 +5,15 @@ from pygments.formatters import HtmlFormatter base62_alphabet = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ' +class CustomHtmlFormatter(HtmlFormatter): + def wrap(self, source, outfile): + yield 0, '
'
+		line = 1
+		for i, t in source:
+			yield i, '%s' % (line, t)
+			line += 1
+		yield 0, '
'
+
 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 ['asdf']
 		self.start_response('200 OK', [('Content-Type', mimetypes.guess_type(filename)[0] or 'text/plain')])
-- 
cgit v1.2.3