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
22 marker = '<link rel="stylesheet" href="{{ stylesheet }}">'
23 custom_css = '<link rel="stylesheet" href="pycco_custom.css">'
24 patched_html = html_src.replace(marker, marker+custom_css, 1)
25 pycco.main.pycco_template = pycco.main.template(patched_html)