X-Git-Url: https://git.ralfj.de/rust-101.git/blobdiff_plain/7df9cdaae2db9969c8b83c4c69ccc21eb0973eb4..5c86632a09410065f7ed67d8c965999edd4172a3:/pycco-rs?ds=sidebyside diff --git a/pycco-rs b/pycco-rs index d250b20..3e6b29d 100755 --- a/pycco-rs +++ b/pycco-rs @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # A little wrapper around pycco, to add Rust support. import pycco, pycco_resources from pygments import lexers, formatters @@ -11,16 +11,16 @@ def patch_html(source, marker, new_text): 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"]) @@ -32,13 +32,13 @@ def generate_documentation(*args, **kwargs): generate_documentation_called = True result = generate_documentation_orig(*args, **kwargs) # now patch it - result = patch_html(result, '', - '') - result = patch_html(result, '', 'Rust-101: ') + result = patch_html(result, b'<link rel="stylesheet" href="pycco.css">', + b'<link rel="stylesheet" href="pycco_custom.css"><meta name="viewport" content="width=device-width">') + result = patch_html(result, b'<title>', b'Rust-101: ') ## remove empty code blocks - result = re.sub('''<div class='code'> + result = re.sub(b'''<div class='code'> *<div class="highlight"><pre>(<span></span>)?</pre></div> - *</div>''', '<!-- empty code block -->', result) + *</div>''', b'<!-- empty code block -->', result) # done return result pycco.main.generate_documentation = generate_documentation