1
## formatting.myt - Provides section formatting elements, syntax-highlighted code blocks, and other special filters.
4
from mako import filters
7
f = re.sub(r'\n[\s\t]*\n[\s\t]*', '</p>\n<p>', f)
13
<%namespace name="nav" file="nav.html"/>
15
<%def name="section(toc, path, paged, extension, description=None)">
16
## Main section formatting element.
18
item = toc.get_by_path(path)
19
subsection = item.depth > 1
21
<A name="${item.path}"></a>
23
<div class="${subsection and 'subsection' or 'section'}">
25
content = capture(caller.body)
28
<h3>${description or item.description}</h3>
32
% if (subsection and item.next and item.next.depth >= item.depth) or not subsection:
34
<a href="#top">back to section top</a>
36
<a href="#${item.get_page_root().path}">back to section top</a>
44
<%def name="formatplain()" filter="plainfilter">
49
<%def name="codeline()" filter="trim,h">
50
<span class="codeline">${ caller.body() }</span>
53
<%def name="code(title=None, syntaxtype='mako', html_escape=False, use_sliders=False)">
56
from pygments.formatters import HtmlFormatter
57
from pygments.lexers import PythonLexer, HtmlLexer, IniLexer
58
from mako.ext.pygmentplugin import MakoHtmlLexer
59
lexers = {'mako':MakoHtmlLexer(), 'python':PythonLexer(), 'html':HtmlLexer(),
63
lexer = lexers.get(syntaxtype, None)
64
# dumb hack to print a </%text> tag inside of a <%text> section
65
content = re.sub(r'%CLOSETEXT', '</%text>', capture(caller.body))
68
content = pygments.highlight(content, lexer, HtmlFormatter())
70
content = "<pre>" + content + "</pre>"
73
<div class="${ use_sliders and "sliding_code" or "code" }">
74
% if title is not None: