summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJon Bergli Heier <snakebite@jvnv.net>2010-01-28 00:36:38 +0100
committerJon Bergli Heier <snakebite@jvnv.net>2010-01-28 00:36:38 +0100
commit708125327434ec851100f2df1dbbaca241317b7f (patch)
treebd76e66b3a11b8c9fb83b9adbca7032c660377f4
parent990a5db0a543c4d69a58ee8a0046adee1c9efbc5 (diff)
Implemented dynamic highlighting of lines.
This currently only works when opening URLs with an anchor.
-rw-r--r--pastepy.py13
-rw-r--r--static/paste.css1
-rw-r--r--static/view.js5
-rw-r--r--templates/view.tmpl1
4 files changed, 18 insertions, 2 deletions
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, '<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')])
diff --git a/static/paste.css b/static/paste.css
index 11e15a0..e2139be 100644
--- a/static/paste.css
+++ b/static/paste.css
@@ -16,3 +16,4 @@ div#alt-links a { color: #44f; }
.highlighttable pre { margin: 0; padding: 0; }
.highlighttable .linenos { text-align: right; padding-left: .5em; padding-right: .5em; }
.highlighttable .linenos a { color: #888; }
+.highlighttable .selected { display: block; background-color: #cfc; }
diff --git a/static/view.js b/static/view.js
new file mode 100644
index 0000000..c855609
--- /dev/null
+++ b/static/view.js
@@ -0,0 +1,5 @@
+window.onload = function() {
+ var line = 'code' + document.location.hash.substr(1);
+ var codeline = document.getElementById(line);
+ codeline.className = 'selected';
+}
diff --git a/templates/view.tmpl b/templates/view.tmpl
index 898a08e..267e87f 100644
--- a/templates/view.tmpl
+++ b/templates/view.tmpl
@@ -1,6 +1,7 @@
#extends templates.base
#def head
<link rel="StyleSheet" href="/highlight_stylesheet" type="text/css" />
+ <script type="text/javascript" src="/static/view.js"></script>
#end def
#def content
<p><a href="/">New paste</a></p>