| # 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, description=None)"> |
| FORMATTING SECTION ${path} |
| # Main section formatting element. |
| <% |
| import sys, traceback |
| try: |
| item = toc.get_by_path(path) |
| except: |
| context.write("EXCEPTION GETTING ITEM") |
| context.write(repr(sys.exc_info()[1].args)) |
| context.write(repr(traceback.extract_tb(sys.exc_info()[2]))) |
| %> |
| CHECK1 ITEM ${item} |
| <A name="${item.path}"></a> |
| |
| <div class="section" style="margin-left:${repr(item.depth * 10)}px;"> |
| <% |
| content = capture(caller.body) |
| re2 = re.compile(r"'''PYESC(.+?)PYESC'''", re.S) |
| content = re2.sub(lambda m: m.group(1), content) |
| %> |
| CHECK2 |
| % if item.depth > 1: |
| <h3>${description or item.description}</h3> |
| % endif |
| |
| CHECK3 |
| ${content} |
| |
| % if item.depth > 1: |
| % if (item.next and item.next.depth >= item.depth): |
| <a href="#${ item.get_page_root().path }">back to section top</a> |
| % endif |
| % else: |
| <a href="#${ item.get_page_root().path }">back to section top</a> |
| ${nav.pagenav(item=item)} |
| % endif |
| CHECK4 |
| </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> |
| |
| |
| |
| |