more https
[rust-101.git] / pycco-rs
1 #!/usr/bin/env python
2 # A little wrapper around pycco, to add Rust support.
3 import pycco, pycco_resources
4 from pygments import lexers, formatters
5 import re
6
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
13     # sections.
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
23 css_marker = '<link rel="stylesheet" href="{{ stylesheet }}">'
24 custom_css = '<link rel="stylesheet" href="pycco_custom.css">'
25 html_src = html_src.replace(css_marker, css_marker+custom_css, 1)
26
27 title_marker = '<title>'
28 html_src = html_src.replace(title_marker, title_marker + 'Rust-101: ', 1)
29
30 pycco.main.pycco_template = pycco.main.template(html_src)
31
32 pycco.main.main()