From: khamidou Date: Wed, 1 Sep 2010 17:16:21 +0000 (+0200) Subject: added cross-referencing to pycco X-Git-Url: http://git.khamidou.com/?a=commitdiff_plain;h=ea229de6d6d4bc2d670a8bddf6810f13d3442df1;p=pycco.git added cross-referencing to pycco --- diff --git a/pycco b/pycco index cb0cf73..21dcdbd 100755 --- a/pycco +++ b/pycco @@ -70,12 +70,16 @@ def parse(source, code): save(docs_text, code_text) return sections -def preprocess(comment): +def preprocess(comment, section_nr): # 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 +# It's possible to reference another file, like this : [[pycco.py]] 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 "[%s](%s)" % (match.group(1), path.basename(destination(match.group(1)))) + + def repl2(match): + return "[%s](%s)" % (match.group(1), destination(match.group(1)) + "#section-" + str(section_nr)) + return re.sub('\[\[(.+)\]\]', repl, comment) @@ -96,7 +100,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(preprocess(section["docs_text"])) + section["docs_html"] = markdown(preprocess(section["docs_text"], i)) section["num"] = i # Once all of the code is finished highlighting, we can generate the HTML file @@ -136,7 +140,7 @@ from subprocess import Popen, PIPE # the name of the Pygments lexer and the symbol that indicates a comment. To # add another language to Pycco's repertoire, add it here. languages = { - ".coffee": { "name": "coffee-script", "symbol": "#" }, +# ".coffee": { "name": "coffee-script", "symbol": "#" }, ".js": { "name": "javascript", "symbol": "//" }, ".rb": { "name": "ruby", "symbol": "#" }, ".py": { "name": "python", "symbol": "#" },