*sigh* go back to pycco... for now...
[rust-101.git] / pycco-rs
diff --git a/pycco-rs b/pycco-rs
new file mode 100755 (executable)
index 0000000..bfb731c
--- /dev/null
+++ b/pycco-rs
@@ -0,0 +1,27 @@
+#!/usr/bin/python
+# A little wrapper around pycco, to add Rust support.
+import pycco, pycco_resources
+from pygments import lexers, formatters
+import re
+
+# now, monkey-patch pycco for Rust support
+pycco.main.languages[".rs"] = { "name": "rust", "symbol": "//"}
+for ext, l in pycco.main.languages.items():
+    # Does the line begin with a comment?
+    l["comment_matcher"] = re.compile(r"^\s*" + l["symbol"] + "\s?")
+    # The dividing token we feed into Pygments, to delimit the boundaries between
+    # sections.
+    l["divider_text"] = "\n" + l["symbol"] + "DIVIDER\n"
+    # The mirror of `divider_text` that we expect Pygments to return. We can split
+    # on this to recover the original sections.
+    l["divider_html"] = re.compile(r'\n*<span class="c[1]?">' + l["symbol"] + 'DIVIDER</span>\n*')
+    # Get the Pygments Lexer for this language.
+    l["lexer"] = lexers.get_lexer_by_name(l["name"])
+# and monkey-patch for a custom CSS file
+html_src = pycco_resources.html
+marker = '<link rel="stylesheet" href="{{ stylesheet }}">'
+custom_css = '<link rel="stylesheet" href="pycco_custom.css">'
+patched_html = html_src.replace(marker, marker+custom_css, 1)
+pycco.main.pycco_template = pycco.main.template(patched_html)
+
+pycco.main.main()