save(docs_text, code_text)
return sections
-def preprocess(comment, section_nr):
+# === Preprocessing the comments ===
+#
# Add cross-references before having the text processed by markdown.
-# 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), path.basename(destination(match.group(1))))
+# It's possible to reference another file, like this : [[pycco.py]] or a specific section of
+# another file, like this: [[pycco.py#Highlighting]]. Of course, sections have to be manually declared before,
+# A section name is written on a single line, and surrounded by equals signs, === like this ===
+def preprocess(comment, section_nr):
+ def sanitize_section_name(name):
+ return name.strip().split(" ")[0]
- def repl2(match):
- return "[%s](%s)" % (match.group(1), destination(match.group(1)) + "#section-" + str(section_nr))
+ def replace_crossref(match):
+ # Check if the match contains an anchor
+ if '#' in match.group(1):
+ name, anchor = match.group(1).split('#')
+ return "[%s](%s#%s)" % (name, path.basename(destination(name)), anchor)
+ else:
+ return "[%s](%s)" % (match.group(1), path.basename(destination(match.group(1))))
- return re.sub('\[\[(.+)\]\]', repl, comment)
+ def replace_section_name(match):
+ return '<a name="%s">*%s*</a>' % (sanitize_section_name(match.group(1)), match.group(1))
+ comment = re.sub('===(.+)===\\n', replace_section_name, comment)
+ comment = re.sub('\[\[(.+)\]\]', replace_crossref, comment)
+
+ return comment
+
+# === Highlighting the source code ===
+#
# Highlights a single chunk of code using the **Pygments** module, and runs the
# text of its corresponding comment through **Markdown**.
#
section["docs_html"] = markdown(preprocess(section["docs_text"], i))
section["num"] = i
+# === HTML Code generation ===
# Once all of the code is finished highlighting, we can generate the HTML file
# and write out the documentation. Pass the completed sections into the template
# found in `resources/pycco.html`