• R/O
  • HTTP
  • SSH
  • HTTPS

提交

标签
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

allura


Commit MetaInfo

修订版252cf5408438e1b4d53b63e88c832309595b2260 (tree)
时间2012-05-11 04:33:32
作者bolkimen <bolkimen@yaho...>
CommiterYaroslav Luzin

Log Message

[#4115] ticket:21 add code line link and highlight

更改概述

差异

--- a/Allura/allura/lib/app_globals.py
+++ b/Allura/allura/lib/app_globals.py
@@ -75,7 +75,7 @@ class Globals(object):
7575 self.oid_store = M.OpenIdStore()
7676
7777 # Setup pygments
78- self.pygments_formatter = pygments.formatters.HtmlFormatter(
78+ self.pygments_formatter = utils.LineAnchorCodeHtmlFormatter(
7979 cssclass='codehilite',
8080 linenos='inline')
8181
--- a/Allura/allura/lib/utils.py
+++ b/Allura/allura/lib/utils.py
@@ -20,6 +20,7 @@ from pylons import tmpl_context as c
2020 from paste.httpheaders import CACHE_CONTROL, EXPIRES
2121 from webhelpers.html import literal
2222 from webob import exc
23+from pygments.formatters import HtmlFormatter
2324
2425 from ew import jinja2_ew as ew
2526 from ming.utils import LazyProperty
@@ -393,3 +394,20 @@ def postmortem_hook(etype, value, tb): # pragma no cover
393394 sys.stderr.write('Entering post-mortem PDB shell\n')
394395 traceback.print_exception(etype, value, tb)
395396 pdb.post_mortem(tb)
397+
398+class LineAnchorCodeHtmlFormatter(HtmlFormatter):
399+ def _wrap_pre(self, inner):
400+ style = []
401+ if self.prestyles:
402+ style.append(self.prestyles)
403+ if self.noclasses:
404+ style.append('line-height: 125%')
405+ style = '; '.join(style)
406+
407+ num = self.linenostart
408+ yield 0, ('<pre' + (style and ' style="%s"' % style) + '>')
409+ for tup in inner:
410+ yield (tup[0], '<a class="linelink" href="#codeline_%s">'\
411+ '<div id="codeline_%s" class="code_block">%s</div></a>' % (num, num, tup[1]))
412+ num += 1
413+ yield 0, '</pre>'
--- a/Allura/allura/public/nf/css/forge/hilite.css
+++ b/Allura/allura/public/nf/css/forge/hilite.css
@@ -63,4 +63,8 @@
6363 .codehilite .il { color: #666666 } /* Literal.Number.Integer.Long */
6464
6565 .codehilite pre { margin:0; }
66+.codehilite div { margin:0; padding: 0; }
67+.codehilite a.linelink { text-decoration: none; }
68+.codehilite a.linelink .code_block { width:100%; }
69+.codehilite a.linelink .code_block:hover { background-color: #ffff99; }
6670 .codehilite .lineno { background-color: #ebebeb; display:inline-block; padding:0 .5em; border-width: 0 1px 0 0; border-style: solid; border-color: #ddd; }
--- a/Allura/allura/templates/repo/file.html
+++ b/Allura/allura/templates/repo/file.html
@@ -18,6 +18,27 @@
1818 </a>
1919 {% endblock %}
2020
21+{% block extra_js %}
22+{{ super() }}
23+<script type="text/javascript">(function() {
24+ var hash = window.location.hash.substring(1);
25+ if (hash != '' && hash.substring(0, 9) == 'codeline_') {
26+ $('#' + hash).css('background-color', '#ffff99');
27+ }
28+
29+ $('.code_block').each(function(index, element) {
30+ $(element).bind('click', function() {
31+ var hash = window.location.hash.substring(1);
32+ if (hash != '' && hash.substring(0, 9) == 'codeline_') {
33+ $('#' + hash).css('background-color', 'transparent');
34+ }
35+ $(element).css('background-color', '#ffff99');
36+ });
37+ });
38+}());
39+</script>
40+{% endblock %}
41+
2142 {% block content %}
2243 {{ clone_info(c.app.repo) }}
2344 {% if prev %}