X-Git-Url: https://git.ralfj.de/rust-101.git/blobdiff_plain/f34c221547f429f23feedf3dc58344a9292c0e18..940a573f598530dda50c88dabf84e73ff7c73dc5:/pycco-rs diff --git a/pycco-rs b/pycco-rs index 7ac0b89..d250b20 100755 --- a/pycco-rs +++ b/pycco-rs @@ -2,7 +2,13 @@ # 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": "//"} @@ -17,11 +23,27 @@ for ext, l in pycco.main.languages.items(): l["divider_html"] = re.compile(r'\n*' + l["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 -marker = '' -custom_css = '' -patched_html = html_src.replace(marker, marker+custom_css, 1) -pycco.main.pycco_template = pycco.main.template(patched_html) +# and monkey-patch the function generating the output to do some post-processing +generate_documentation_orig = pycco.main.generate_documentation +generate_documentation_called = False +def generate_documentation(*args, **kwargs): + global generate_documentation_called + generate_documentation_called = True + result = generate_documentation_orig(*args, **kwargs) + # now patch it + result = patch_html(result, '', + '') + result = patch_html(result, '
()?