~jonas-drange/ubuntu-start-page/1252899-mobile-friendly

« back to all changes in this revision

Viewing changes to src/Mako-0.1.9/doc/build/templates/formatting.html

  • Committer: Matthew Nuzum
  • Date: 2008-04-18 01:58:53 UTC
  • Revision ID: matthew.nuzum@canonical.com-20080418015853-2b8rf979z2c2exxl
adding files

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
## formatting.myt - Provides section formatting elements, syntax-highlighted code blocks, and other special filters.
 
2
<%!
 
3
    import string, re, cgi
 
4
    from mako import filters
 
5
    
 
6
    def plainfilter(f):
 
7
        f = re.sub(r'\n[\s\t]*\n[\s\t]*', '</p>\n<p>', f)
 
8
        f = "<p>" + f + "</p>"
 
9
        return f
 
10
    
 
11
%>
 
12
 
 
13
<%namespace name="nav" file="nav.html"/>
 
14
 
 
15
<%def name="section(toc, path, paged, extension, description=None)">
 
16
    ## Main section formatting element.
 
17
    <%
 
18
        item = toc.get_by_path(path)
 
19
        subsection = item.depth > 1
 
20
    %>
 
21
    <A name="${item.path}"></a>
 
22
    
 
23
    <div class="${subsection and 'subsection' or 'section'}">
 
24
    <%
 
25
        content = capture(caller.body)
 
26
    %>
 
27
 
 
28
    <h3>${description or item.description}</h3>
 
29
    
 
30
    ${content}
 
31
 
 
32
    % if (subsection and item.next and item.next.depth >= item.depth) or not subsection:
 
33
        % if paged:
 
34
            <a href="#top">back to section top</a>
 
35
        % else:
 
36
            <a href="#${item.get_page_root().path}">back to section top</a>
 
37
        % endif
 
38
    % endif
 
39
    </div>
 
40
 
 
41
</%def>
 
42
 
 
43
 
 
44
<%def name="formatplain()" filter="plainfilter">
 
45
    ${ caller.body() | h}
 
46
</%def>
 
47
 
 
48
 
 
49
<%def name="codeline()" filter="trim,h">
 
50
    <span class="codeline">${ caller.body() }</span>
 
51
</%def>
 
52
 
 
53
<%def name="code(title=None, syntaxtype='mako', html_escape=False, use_sliders=False)">
 
54
    <%!
 
55
        import pygments
 
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(),
 
60
                  'ini':IniLexer()}
 
61
    %>
 
62
    <%
 
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))
 
66
        
 
67
        if lexer is not None:
 
68
            content = pygments.highlight(content, lexer, HtmlFormatter())
 
69
        else:
 
70
            content = "<pre>" + content + "</pre>"
 
71
    %>
 
72
 
 
73
    <div class="${ use_sliders and "sliding_code" or "code" }">
 
74
        % if title is not None:
 
75
            ${title}
 
76
        % endif
 
77
        ${ content }
 
78
    </div>
 
79
</%def>
 
80
 
 
81
 
 
82
 
 
83