<%doc>formatting.myt - Provides section formatting elements, syntax-highlighted code blocks, and other special filters. <%global> import string, re import highlight <%method section> <%doc>Main section formatting element. <%args> toc path description=None onepage=False <%init> item = toc.get_by_path(path) if item is None: raise "path: " + path
<%python> content = m.content() 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 %>

%
<% content %>
% if onepage or item.depth > 1: % if (item.next and item.next.depth >= item.depth): back to section top % % else: back to section top <& nav.myt:pagenav, item=item, onepage=onepage &> %
<%method formatplain> <%filter> import re f = re.sub(r'\n[\s\t]*\n[\s\t]*', '

\n

', f) f = "

" + f + "

" return f <% m.content() | h%> <%method codeline trim="both"> <% m.content() %> <%method code autoflush=False> <%args> title = None syntaxtype = 'python' html_escape = False use_sliders = False <%init> def fix_indent(f): f =string.expandtabs(f, 4) g = '' lines = string.split(f, "\n") whitespace = None for line in lines: if whitespace is None: match = re.match(r"^([ ]*).+", line) if match is not None: whitespace = match.group(1) if whitespace is not None: line = re.sub(r"^%s" % whitespace, "", line) if whitespace is not None or re.search(r"\w", line) is not None: g += (line + "\n") return g.rstrip() p = re.compile(r'
(.*?)
', re.S) def hlight(match): return "
" + highlight.highlight(fix_indent(match.group(1)), html_escape = html_escape, syntaxtype = syntaxtype) + "
" content = p.sub(hlight, "
" + m.content() + "
")
"> % if title is not None:
<% title %>
% <% content %>
<%method popboxlink trim="both"> <%args> name=None show='show' hide='hide' <%init> if name is None: name = m.attributes.setdefault('popbox_name', 0) name += 1 m.attributes['popbox_name'] = name name = "popbox_" + repr(name) javascript:togglePopbox('<% name %>', '<% show %>', '<% hide %>') <%method popbox trim="both"> <%args> name = None class_ = None <%init> if name is None: name = 'popbox_' + repr(m.attributes['popbox_name']) <%method poplink trim="both"> <%args> link='sql' <%init> href = m.scomp('SELF:popboxlink') '''PYESC<& nav.myt:link, href=href, text=link, class_="codepoplink" &>PYESC''' <%method codepopper trim="both"> <%init> c = m.content() c = re.sub(r'\n', '
\n', c.strip()) <&|SELF:popbox, class_="codepop" &><% c %>


<%method poppedcode trim="both">
	<%init>
		c = m.content()
		c = re.sub(r'\n', '
\n', c.strip())
<% c %>