diff --git a/etc/multi-domain.patch b/etc/multi-domain.patch index 205f4275..404f9208 100644 --- a/etc/multi-domain.patch +++ b/etc/multi-domain.patch @@ -1,5 +1,5 @@ ---- env/lib/python2.7/site-packages/flaskext/babel.py 2013-07-13 00:00:00 +0000 -+++ env/lib/python2.7/site-packages/flaskext/babel.py 2013-07-13 00:00:00 +0000 +--- env/lib/python2.7/site-packages/flask_babel/__init__.py 2013-07-13 00:00:00 +0000 ++++ env/lib/python2.7/site-packages/flask_babel/__init__.py 2013-07-13 00:00:00 +0000 @@ -19,6 +19,7 @@ from datetime import datetime from flask import _request_ctx_stack diff --git a/etc/reqs.txt b/etc/reqs.txt index baa1939c..f56ac7f7 100644 --- a/etc/reqs.txt +++ b/etc/reqs.txt @@ -1,8 +1,9 @@ pytz>=2012 -Flask==0.9 -Flask-Babel==0.8 -Flask-Cache==0.10.1 -Jinja2==2.6 +Flask==0.10.1 +Flask-Babel==0.9 +Flask-Cache==0.12 +Jinja2==2.7.2 Pygments==1.6 -docutils==0.9.1 +python-ctags +docutils==0.11 gunicorn==0.17.2 diff --git a/i2p2www/extensions.py b/i2p2www/extensions.py index 4886aae6..a1ce6d37 100644 --- a/i2p2www/extensions.py +++ b/i2p2www/extensions.py @@ -9,6 +9,14 @@ from pygments.lexers import get_lexer_by_name, guess_lexer from pygments.formatters import HtmlFormatter from pygments.util import ClassNotFound +try: + import ctags +except ImportError: + ctags = None + +from flask import g + +from i2p2www.formatters import I2PHtmlFormatter from i2p2www.lexers import DataSpecLexer class HighlightExtension(Extension): @@ -76,7 +84,16 @@ class HighlightExtension(Extension): print(e) sys.exit(1) - formatter = HtmlFormatter(**parameters) + if ctags: + if 'tagsfile' not in parameters: + parameters['tagsfile'] = 'i2p2www/pages/site/spectags' + + if 'tagurlformat' not in parameters: + lang = 'en' + if hasattr(g, 'lang') and g.lang: + lang = g.lang + parameters['tagurlformat'] = '/' + lang + '/%(path)s%(fname)s' + + formatter = I2PHtmlFormatter(**parameters) code = highlight(Markup(body).unescape(), lexer, formatter) return code - diff --git a/i2p2www/formatters.py b/i2p2www/formatters.py new file mode 100644 index 00000000..598269f5 --- /dev/null +++ b/i2p2www/formatters.py @@ -0,0 +1,826 @@ +# -*- coding: utf-8 -*- +""" + pygments.formatters.html + ~~~~~~~~~~~~~~~~~~~~~~~~ + + Formatter for HTML output. + + :copyright: Copyright 2006-2013 by the Pygments team, see AUTHORS. + :license: BSD, see LICENSE for details. +""" + +import os +import sys +import os.path +import StringIO + +from pygments.formatter import Formatter +from pygments.token import Token, Text, STANDARD_TYPES +from pygments.util import get_bool_opt, get_int_opt, get_list_opt, bytes + +try: + import ctags +except ImportError: + ctags = None + +__all__ = ['I2PHtmlFormatter'] + + +_escape_html_table = { + ord('&'): u'&', + ord('<'): u'<', + ord('>'): u'>', + ord('"'): u'"', + ord("'"): u''', +} + +kinds = { + 't': 'type', + 's': 'struct', + } + +def escape_html(text, table=_escape_html_table): + """Escape &, <, > as well as single and double quotes for HTML.""" + return text.translate(table) + +def get_random_id(): + """Return a random id for javascript fields.""" + from random import random + from time import time + try: + from hashlib import sha1 as sha + except ImportError: + import sha + sha = sha.new + return sha('%s|%s' % (random(), time())).hexdigest() + + +def _get_ttype_class(ttype): + fname = STANDARD_TYPES.get(ttype) + if fname: + return fname + aname = '' + while fname is None: + aname = '-' + ttype[-1] + aname + ttype = ttype.parent + fname = STANDARD_TYPES.get(ttype) + return fname + aname + + +CSSFILE_TEMPLATE = '''\ +td.linenos { background-color: #f0f0f0; padding-right: 10px; } +span.lineno { background-color: #f0f0f0; padding: 0 5px 0 5px; } +pre { line-height: 125%%; } +%(styledefs)s +''' + +DOC_HEADER = '''\ + + + + + %(title)s + + + + +

%(title)s

+ +''' + +DOC_HEADER_EXTERNALCSS = '''\ + + + + + %(title)s + + + + +

%(title)s

+ +''' + +DOC_FOOTER = '''\ + + +''' + + +class I2PHtmlFormatter(Formatter): + r""" + Format tokens as HTML 4 ```` tags within a ``
`` tag, wrapped
+    in a ``
`` tag. The ``
``'s CSS class can be set by the `cssclass` + option. + + If the `linenos` option is set to ``"table"``, the ``
`` is
+    additionally wrapped inside a ```` which has one row and two
+    cells: one containing the line numbers and one containing the code.
+    Example:
+
+    .. sourcecode:: html
+
+        
+
+ + +
+
1
+            2
+
+
def foo(bar):
+              pass
+            
+
+ + (whitespace added to improve clarity). + + Wrapping can be disabled using the `nowrap` option. + + A list of lines can be specified using the `hl_lines` option to make these + lines highlighted (as of Pygments 0.11). + + With the `full` option, a complete HTML 4 document is output, including + the style definitions inside a ``