+################################################################################
+# probably xml.sax.saxutils would work as well
+
+def html_escape(s):
+ return re_html_escaping.sub(lambda x: html_escaping.get(x.group(0)), s)
+
+def escape_if_needed(s):
+ if use_html:
+ return re_html_escaping.sub(html_escaping.get, s)
+ else:
+ return s
+
+def headline(s, level=2, bodyelement=None):
+ if use_html:
+ if bodyelement:
+ print """<thead>
+ <tr><th colspan="2" class="title" onclick="toggle('%(bodyelement)s', 'table-row-group', 'table-row-group')">%(title)s</th></tr>
+ </thead>"""%{"bodyelement":bodyelement,"title":html_escape(s)}
+ else:
+ print "<h%d>%s</h%d>" % (level, html_escape(s), level)
+ else:
+ print "---- %s ----" % (s)
+
+# Colour definitions, 'end' isn't really for use
+
+ansi_colours = {
+ 'main': "\033[36m",
+ 'contrib': "\033[33m",
+ 'nonfree': "\033[31m",
+ 'arch': "\033[32m",
+ 'end': "\033[0m",
+ 'bold': "\033[1m",
+ 'maintainer': "\033[32m"}
+
+html_colours = {
+ 'main': ('<span style="color: aqua">',"</span>"),
+ 'contrib': ('<span style="color: yellow">',"</span>"),
+ 'nonfree': ('<span style="color: red">',"</span>"),
+ 'arch': ('<span style="color: green">',"</span>"),
+ 'bold': ('<span style="font-weight: bold">',"</span>"),
+ 'maintainer': ('<span style="color: green">',"</span>")}
+
+def colour_output(s, colour):
+ if use_html:
+ return ("%s%s%s" % (html_colours[colour][0], html_escape(s), html_colours[colour][1]))
+ else:
+ return ("%s%s%s" % (ansi_colours[colour], s, ansi_colours['end']))
+
+def print_escaped_text(s):
+ if use_html:
+ print "<pre>%s</pre>" % (s)
+ else:
+ print s
+
+def print_formatted_text(s):
+ if use_html:
+ print "<pre>%s</pre>" % (html_escape(s))
+ else:
+ print s
+