%doc>formatting.myt - Provides section formatting elements, syntax-highlighted code blocks, and other special filters.%doc> <%global> import string, re import highlight %global> <%method section> <%doc>Main section formatting element.%doc> <%args> toc path description=None onepage=False %args> <%init> item = toc.get_by_path(path) if item is None: raise "path: " + path %init>
', f) f = "
" + f + "
" return f %filter> <% m.content() | h%> %method> <%method codeline trim="both"> <% m.content() %> %method> <%method code autoflush=False> <%args> title = None syntaxtype = 'python' html_escape = False use_sliders = False %args> <%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() + "") %init> %method> <%method popboxlink trim="both"> <%args> name=None show='show' hide='hide' %args> <%init> if name is None: name = m.attributes.setdefault('popbox_name', 0) name += 1 m.attributes['popbox_name'] = name name = "popbox_" + repr(name) %init> javascript:togglePopbox('<% name %>', '<% show %>', '<% hide %>') %method> <%method popbox trim="both"> <%args> name = None class_ = None %args> <%init> if name is None: name = 'popbox_' + repr(m.attributes['popbox_name']) %init> %method> <%method poplink trim="both"> <%args> link='sql' %args> <%init> href = m.scomp('SELF:popboxlink') %init> '''PYESC<& nav.myt:link, href=href, text=link, class_="codepoplink" &>PYESC''' %method> <%method codepopper trim="both"> <%init> c = m.content() c = re.sub(r'\n', '
%method> <%method poppedcode trim="both"> <%init> c = m.content() c = re.sub(r'\n', '
\n', c.strip()) %init>
%method>