From 50009e1546e4880dfd23eb7f5120e599848d4ead Mon Sep 17 00:00:00 2001 From: Andrey Kamaev Date: Sat, 28 Apr 2012 12:31:53 +0000 Subject: [PATCH] Improved javadoc generation scripts --- modules/java/gen_javadoc.py | 59 ++++++++++++++++++++++++++++++++----- modules/java/rst_parser.py | 6 ++-- 2 files changed, 55 insertions(+), 10 deletions(-) diff --git a/modules/java/gen_javadoc.py b/modules/java/gen_javadoc.py index 330dd7a59c..92dd0e2c69 100644 --- a/modules/java/gen_javadoc.py +++ b/modules/java/gen_javadoc.py @@ -1,5 +1,5 @@ import os, sys, re, string, glob -allmodules = ["core", "flann", "imgproc", "ml", "highgui", "video", "features2d", "calib3d", "objdetect", "legacy", "contrib", "gpu", "androidcamera", "haartraining", "java", "python", "stitching", "traincascade", "ts", "photo"] +allmodules = ["core", "flann", "imgproc", "ml", "highgui", "video", "features2d", "calib3d", "objdetect", "legacy", "contrib", "gpu", "androidcamera", "haartraining", "java", "python", "stitching", "traincascade", "ts", "photo", "videostab"] verbose = False show_warnings = True show_errors = True @@ -67,14 +67,47 @@ class JavadocGenerator(object): inf.close() outf.close() + def FinishParagraph(self, text): + return text[:-1] + "

\n" + def ReformatForJavadoc(self, s): out = "" + in_paragraph = False + in_list = False for term in s.split("\n"): - if term.startswith("*") or term.startswith("#."): - term = " " + term + in_list_item = False + if term.startswith("*"): + in_list_item = True + if in_paragraph: + out = self.FinishParagraph(out) + in_paragraph = False + if not in_list: + out += " * \n" pos_start = 0 pos_end = min(77, len(term)-1) while pos_start < pos_end: @@ -91,12 +124,22 @@ class JavadocGenerator(object): pos_end += 1 else: break - out += " * " + term[pos_start:pos_end+1].rstrip() + "\n" + if in_paragraph or term.startswith("@") or in_list_item: + out += " * " + else: + in_paragraph = True + out += " *

" + out += term[pos_start:pos_end+1].rstrip() + "\n" pos_start = pos_end + 1 pos_end = min(pos_start + 77, len(term)-1) + + if in_paragraph: + out = self.FinishParagraph(out) + if in_list: + out += " * \n" return out - def getJavaName(self, decl): + def getJavaName(self, decl, methodSeparator = "."): name = "org.opencv." name += decl["module"] if "class" in decl: @@ -104,11 +147,11 @@ class JavadocGenerator(object): else: name += "." + decl["module"].capitalize() if "method" in decl: - name += "." + decl["method"] + name += methodSeparator + decl["method"] return name def getDocURL(self, decl): - url = "http://opencv.itseez.com/modules/" + url = "http://docs.opencv.org/modules/" url += decl["module"] url += "/doc/" url += os.path.basename(decl["file"]).replace(".rst",".html") @@ -168,7 +211,7 @@ class JavadocGenerator(object): for see in decl["seealso"]: seedecl = self.definitions.get(see,None) if seedecl: - doc += prefix + " * @see " + self.getJavaName(seedecl) + "\n" + doc += prefix + " * @see " + self.getJavaName(seedecl, "#") + "\n" else: doc += prefix + " * @see " + see.replace("::",".") + "\n" prefix = " *\n" diff --git a/modules/java/rst_parser.py b/modules/java/rst_parser.py index 31d3827298..ebd1e1d157 100644 --- a/modules/java/rst_parser.py +++ b/modules/java/rst_parser.py @@ -499,7 +499,8 @@ class RstParser(object): def normalizeText(self, s): if s is None: return s - s = re.sub(r"\.\. math::[ ]*\n+(.*?)(\n[ ]*\n|$)", mathReplace2, s) + + s = re.sub(r"\.\. math::[ \r]*\n+((.|\n)*?)(\n[ \r]*\n|$)", mathReplace2, s) s = re.sub(r":math:`([^`]+?)`", mathReplace, s) s = re.sub(r" *:sup:", "^", s) @@ -574,6 +575,7 @@ class RstParser(object): s = re.sub(r"[\n ]+\.", ".", s) s = s.replace("**", "") + s = re.sub(r"``([^\n]+?)``", "\\1", s) s = s.replace("``", "\"") s = s.replace("`", "\"") s = s.replace("\"\"", "\"") @@ -688,7 +690,7 @@ def mathReplace(match): m = m.replace("}", ")") #print "%s ===> %s" % (match.group(0), m) - return m + return "" + m + "" if __name__ == "__main__": if len(sys.argv) < 2: