## formatting.myt - Provides section formatting elements, syntax-highlighted code blocks, and other special filters. <%! import string, re, cgi from mako import filters import highlight def plainfilter(f): f = re.sub(r'\n[\s\t]*\n[\s\t]*', '
\n', f) f = "
" + f + "
" return f %> <%namespace name="nav" file="nav.html"/> <%def name="section(toc, path, paged, extension, description=None)"> ## Main section formatting element. <% content = capture(caller.body) re2 = re.compile(r"'''PYESC(.+?)PYESC'''", re.S) content = re2.sub(lambda m: m.group(1), content) item = toc.get_by_path(path) subsection = item.depth > 1 level = min(item.depth, 4) %>(.*?)', re.S) def hlight(match): return "
" + highlight.highlight(fix_indent(match.group(1)), html_escape = html_escape, syntaxtype = syntaxtype) + "" content = p.sub(hlight, "
" + capture(caller.body) + "") %> %def> <%def name="popboxlink(name=None, show='show', hide='hide')" filter="trim"> <% if name is None: name = attributes.setdefault('popbox_name', 0) name += 1 attributes['popbox_name'] = name name = "popbox_" + repr(name) %> javascript:togglePopbox('${name}', '${show}', '${hide}') %def> <%def name="popbox(name=None, class_=None)" filter="trim"> <% if name is None: name = 'popbox_' + repr(attributes['popbox_name']) %> %def> <%def name="poplink(link='sql')" filter="trim"> <% href = capture(popboxlink) %> '''PYESC${nav.link(href=href, text=link, class_="codepoplink")}PYESC''' %def> <%def name="codepopper()" filter="trim"> <% c = capture(caller.body) c = re.sub(r'\n', '
%def> <%def name="poppedcode()" filter="trim"> <% c = capture(caller.body) c = re.sub(r'\n', '
\n', c.strip()) %>
%def>