# 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, paged=True)">
# Main section formatting element.
<%
item = toc.get_by_path(path)
subsection = item.depth > 1
%>
% if subsection:
% endif
<%
content = capture(caller.body)
re2 = re.compile(r"'''PYESC(.+?)PYESC'''", re.S)
content = re2.sub(lambda m: m.group(1), content)
%>
${description or item.description}
${content}
% if subsection:
% if (item.next and item.next.depth >= item.depth):
back to section top
% endif
% else:
% if paged:
${nav.pagenav(item=item, paged=paged)}
% endif
back to section top
% endif
%def>
<%def name="formatplain" filter="plainfilter">
${ caller.body() | h}
%def>
<%def name="codeline" filter="trim,h">
${ caller.body() }
%def>
<%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 }
%def>