2 # A little wrapper around pycco, to add Rust support.
3 import pycco, pycco_resources
4 from pygments import lexers, formatters
7 # now, monkey-patch pycco for Rust support
8 pycco.main.languages[".rs"] = { "name": "rust", "symbol": "//"}
9 for ext, l in pycco.main.languages.items():
10 # Does the line begin with a comment?
11 l["comment_matcher"] = re.compile(r"^\s*" + l["symbol"] + "\s?")
12 # The dividing token we feed into Pygments, to delimit the boundaries between
14 l["divider_text"] = "\n" + l["symbol"] + "DIVIDER\n"
15 # The mirror of `divider_text` that we expect Pygments to return. We can split
16 # on this to recover the original sections.
17 l["divider_html"] = re.compile(r'\n*<span class="c[1]?">' + l["symbol"] + 'DIVIDER</span>\n*')
18 # Get the Pygments Lexer for this language.
19 l["lexer"] = lexers.get_lexer_by_name(l["name"])
20 # and monkey-patch for a custom CSS file
21 html_src = pycco_resources.html
23 css_marker = '<link rel="stylesheet" href="{{ stylesheet }}">'
24 custom_css = '<link rel="stylesheet" href="pycco_custom.css"><meta name="viewport" content="width=device-width">'
25 assert html_src.count(css_marker) == 1
26 html_src = html_src.replace(css_marker, css_marker+custom_css, 1)
28 title_marker = '<title>'
29 assert html_src.count(title_marker) == 1
30 html_src = html_src.replace(title_marker, title_marker + 'Rust-101: ', 1)
32 pycco_resources.html = html_src
33 pycco.main.pycco_template = pycco_resources.pycco_template = pycco_resources.template(pycco_resources.html)