# formatting.myt - Provides section formatting elements, syntax-highlighted code blocks, and other special filters. <%! import string, re #import highlight from mako import filters 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, description=None)"> # Main section formatting element. <% item = toc.get_by_path(path) if item is None: raise "path: " + path %>
<% content = capture(caller.body) re2 = re.compile(r"'''PYESC(.+?)PYESC'''", re.S) content = re2.sub(lambda m: m.group(1), content) %> % if item.depth > 1:

${description or item.description}

% endif ${content} % if item.depth > 1: % if (item.next and item.next.depth >= item.depth): back to section top % endif % else: back to section top ${nav.pagenav(item=item)} % endif
<%def name="formatplain" filter="plainfilter"> ${ caller.body() | h} <%def name="codeline" filter="trim,h"> ${ caller.body() } <%def name="code(title=None, syntaxtype='python', html_escape=False, use_sliders=False)"> <% content = "
" + capture(caller.body) + "
" %>
% if title is not None: ${title} % endif ${ content }