blob: e3627fd0ef15e66e5d4f56d52117e953193ceab6 [file]
# 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]*', '</p>\n<p>', f)
f = "<p>" + f + "</p>"
return f
%>
<%namespace name="nav" file="nav.html"/>
<%def name="section(toc, path, paged, extension, description=None)">
# Main section formatting element.
<%
item = toc.get_by_path(path)
subsection = item.depth > 1
%>
<A name="${item.path}"></a>
<div class="${subsection and 'subsection' or 'section'}">
<%
content = capture(caller.body)
re2 = re.compile(r"'''PYESC(.+?)PYESC'''", re.S)
content = re2.sub(lambda m: m.group(1), content)
%>
<h3>${description or item.description}</h3>
${content}
% if (subsection and item.next and item.next.depth >= item.depth) or not subsection:
% if paged:
<a href="#top">back to section top</a>
% else:
<a href="#${item.get_page_root().path}">back to section top</a>
% endif
% endif
</div>
</%def>
<%def name="formatplain()" filter="plainfilter">
${ caller.body() | h}
</%def>
<%def name="codeline()" filter="trim,h">
<span class="codeline">${ caller.body() }</span>
</%def>
<%def name="code(title=None, syntaxtype='python', html_escape=False, use_sliders=False)">
<%
content = "<pre>" + capture(caller.body) + "</pre>"
%>
<div class="${ use_sliders and "sliding_code" or "code" }">
% if title is not None:
${title}
% endif
${ content }
</div>
</%def>