From: khamidou Date: Wed, 1 Sep 2010 13:27:05 +0000 (+0200) Subject: added support for cross-references X-Git-Url: http://git.khamidou.com/?a=commitdiff_plain;h=363832ecde925e1a75aa7652aad5fc06c7f3dab9;p=pycco.git added support for cross-references --- diff --git a/pycco b/pycco index e9a4866..cb0cf73 100755 --- a/pycco +++ b/pycco @@ -70,6 +70,15 @@ def parse(source, code): save(docs_text, code_text) return sections +def preprocess(comment): +# Add cross-references before having the text processed by markdown. +# It's possible to reference another file, like this : [[file]] or a specific function of +# another file, like this: [[file#func]] + def repl(match): + return "[%s](%s)" % (match.group(1), destination(match.group(1))) + + return re.sub('\[\[(.+)\]\]', repl, comment) + # Highlights a single chunk of code using the **Pygments** module, and runs the # text of its corresponding comment through **Markdown**. # @@ -87,7 +96,7 @@ def highlight(source, sections): fragments = re.split(language["divider_html"], output) for i, section in enumerate(sections): section["code_html"] = highlight_start + shift(fragments, "") + highlight_end - section["docs_html"] = markdown(section["docs_text"]) + section["docs_html"] = markdown(preprocess(section["docs_text"])) section["num"] = i # Once all of the code is finished highlighting, we can generate the HTML file