]> khamidou — GitHub mirrors - pycco.git/commitdiff
added cross-referencing to pycco
authorkhamidou <khamidou@gmail.com>
Wed, 1 Sep 2010 17:16:21 +0000 (19:16 +0200)
committerkhamidou <khamidou@gmail.com>
Wed, 1 Sep 2010 17:16:21 +0000 (19:16 +0200)
pycco

diff --git a/pycco b/pycco
index cb0cf73983e570778ee45b20079ac75583455301..21dcdbd687aa8bac342feec2485c8c39c08d9d3b 100755 (executable)
--- 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": "#" },