X-Git-Url: https://git.ralfj.de/rust-101.git/blobdiff_plain/a52087dc8f244861d144229b04e64f934ed1d03f..cfb905da7555e4ec4a8f1acd09bd7813607aa653:/pycco-rs?ds=sidebyside diff --git a/pycco-rs b/pycco-rs index 2e10184..c884311 100755 --- a/pycco-rs +++ b/pycco-rs @@ -2,31 +2,48 @@ # A little wrapper around pycco, to add Rust support. import pycco, pycco_resources from pygments import lexers, formatters -import re +import sys, re + +# helper functions +def patch_html(source, marker, new_text): + '''Find the [marker] in [source], and insert [new_text] after it.''' + assert source.count(marker) == 1 + return source.replace(marker, marker + new_text, 1) # now, monkey-patch pycco for Rust support -pycco.main.languages[".rs"] = { "name": "rust", "symbol": "//"} -for ext, l in pycco.main.languages.items(): +pycco.main.supported_languages[".rs"] = { "name": "rust", "comment_symbol": "//"} +for ext, l in pycco.main.supported_languages.items(): # Does the line begin with a comment? - l["comment_matcher"] = re.compile(r"^\s*" + l["symbol"] + "\s?") + l["comment_matcher"] = re.compile(r"^\s*" + l["comment_symbol"] + "\s?") # The dividing token we feed into Pygments, to delimit the boundaries between # sections. - l["divider_text"] = "\n" + l["symbol"] + "DIVIDER\n" + l["divider_text"] = "\n" + l["comment_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*' + l["symbol"] + 'DIVIDER\n*') + l["divider_html"] = re.compile(r'\n*' + l["comment_symbol"] + 'DIVIDER\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 - -css_marker = '' -custom_css = '' -html_src = html_src.replace(css_marker, css_marker+custom_css, 1) - -title_marker = '
()?