Commit 2cf34c7f authored by Andrey Kamaev's avatar Andrey Kamaev

Fixed few more bugs in rst_parser. Fixed small typos in documentation.

parent ddd57e74
...@@ -113,7 +113,7 @@ Rect\_ ...@@ -113,7 +113,7 @@ Rect\_
------ ------
.. ocv:class:: Rect_ .. ocv:class:: Rect_
Template class for 2D rectangles, described by the following parameters:: Template class for 2D rectangles, described by the following parameters:
* Coordinates of the top-left corner. This is a default interpretation of ``Rect_::x`` and ``Rect_::y`` in OpenCV. Though, in your algorithms you may count ``x`` and ``y`` from the bottom-left corner. * Coordinates of the top-left corner. This is a default interpretation of ``Rect_::x`` and ``Rect_::y`` in OpenCV. Though, in your algorithms you may count ``x`` and ``y`` from the bottom-left corner.
* Rectangle width and height. * Rectangle width and height.
...@@ -802,7 +802,7 @@ Provides matrix assignment operators. ...@@ -802,7 +802,7 @@ Provides matrix assignment operators.
.. ocv:function:: Mat& Mat::operator = (const MatExpr_Base& expr) .. ocv:function:: Mat& Mat::operator = (const MatExpr_Base& expr)
.. ocv:function:: Mat& operator = (const Scalar& s) .. ocv:function:: Mat& Mat::operator = (const Scalar& s)
:param m: Assigned, right-hand-side matrix. Matrix assignment is an O(1) operation. This means that no data is copied but the data is shared and the reference counter, if any, is incremented. Before assigning new data, the old data is de-referenced via :ocv:func:`Mat::release` . :param m: Assigned, right-hand-side matrix. Matrix assignment is an O(1) operation. This means that no data is copied but the data is shared and the reference counter, if any, is incremented. Before assigning new data, the old data is de-referenced via :ocv:func:`Mat::release` .
...@@ -855,7 +855,7 @@ The method makes a new header for the specified matrix row and returns it. This ...@@ -855,7 +855,7 @@ The method makes a new header for the specified matrix row and returns it. This
A.row(i) = A.row(j) + 0; A.row(i) = A.row(j) + 0;
// this is a bit longe, but the recommended method. // this is a bit longe, but the recommended method.
Mat Ai = A.row(i); M.row(j).copyTo(Ai); A.row(j).copyTo(A.row(i));
Mat::col Mat::col
------------ ------------
......
...@@ -129,7 +129,7 @@ class RstParser(object): ...@@ -129,7 +129,7 @@ class RstParser(object):
# continue capture seealso # continue capture seealso
if capturing_seealso: if capturing_seealso:
if l.startswith(" "): if not l or l.startswith(" "):
seealso = func.get("seealso",[]) seealso = func.get("seealso",[])
seealso.extend(l.split(",")) seealso.extend(l.split(","))
func["seealso"] = seealso func["seealso"] = seealso
...@@ -159,13 +159,6 @@ class RstParser(object): ...@@ -159,13 +159,6 @@ class RstParser(object):
else: else:
skip_code_lines = False skip_code_lines = False
if ll.startswith(".. "):
expected_brief = False
elif ll.endswith("::"):
# turn on line-skipping mode for code fragments
skip_code_lines = True
ll = ll[:len(ll)-2]
if ll.startswith(".. code-block::") or ll.startswith(".. math::") or ll.startswith(".. image::"): if ll.startswith(".. code-block::") or ll.startswith(".. math::") or ll.startswith(".. image::"):
skip_code_lines = True skip_code_lines = True
continue continue
...@@ -175,6 +168,13 @@ class RstParser(object): ...@@ -175,6 +168,13 @@ class RstParser(object):
skip_code_lines = True skip_code_lines = True
continue continue
if ll.startswith(".. "):
expected_brief = False
elif ll.endswith("::"):
# turn on line-skipping mode for code fragments
skip_code_lines = True
ll = ll[:len(ll)-2]
# parse ".. seealso::" blocks # parse ".. seealso::" blocks
if ll.startswith(".. seealso::"): if ll.startswith(".. seealso::"):
if ll.endswith(".. seealso::"): if ll.endswith(".. seealso::"):
...@@ -227,6 +227,8 @@ class RstParser(object): ...@@ -227,6 +227,8 @@ class RstParser(object):
# record other lines as long description # record other lines as long description
func["long"] = func.get("long", "") + "\n" + ll func["long"] = func.get("long", "") + "\n" + ll
if skip_code_lines:
func["long"] = func.get("long", "") + "\n"
# endfor l in lines # endfor l in lines
if fdecl.balance != 0: if fdecl.balance != 0:
...@@ -406,9 +408,11 @@ class RstParser(object): ...@@ -406,9 +408,11 @@ class RstParser(object):
seealso = [] seealso = []
for see in func["seealso"]: for see in func["seealso"]:
item = self.normalizeText(see.rstrip(".")).strip("\"") item = self.normalizeText(see.rstrip(".")).strip("\"")
if item: if item and (item.find(" ") < 0 or item.find("::operator") > 0):
seealso.append(item) seealso.append(item)
func["seealso"] = list(set(seealso)) func["seealso"] = list(set(seealso))
if not func["seealso"]:
del func["seealso"]
# special case for old C functions - section name should omit "cv" prefix # special case for old C functions - section name should omit "cv" prefix
if not func.get("isclass",False) and not func.get("isstruct",False): if not func.get("isclass",False) and not func.get("isstruct",False):
...@@ -444,9 +448,12 @@ class RstParser(object): ...@@ -444,9 +448,12 @@ class RstParser(object):
# remove tailing :: # remove tailing ::
s = re.sub(r"::$", "\n", s) s = re.sub(r"::$", "\n", s)
# remove extra line breaks before/after _ or , # remove extra line breaks before/after _ or ,
s = re.sub(r"\n[ ]*([_,])\n", r"\1", s) s = re.sub(r"\n[ ]*([_,])\n", r"\1 ", s)
# remove extra line breaks after ` # remove extra line breaks after `
#s = re.sub(r"`\n", "` ", s) #s = re.sub(r"`\n", "` ", s)
# remove extra space after ( and before )
s = re.sub(r"\([\n ]+", "(", s)
s = re.sub(r"[\n ]+\)", ")", s)
# remove extra line breaks after ".. note::" # remove extra line breaks after ".. note::"
s = re.sub(r"\.\. note::\n+", ".. note:: ", s) s = re.sub(r"\.\. note::\n+", ".. note:: ", s)
# remove extra line breaks before * # remove extra line breaks before *
...@@ -461,32 +468,52 @@ class RstParser(object): ...@@ -461,32 +468,52 @@ class RstParser(object):
s = re.sub(r"\n[ ]*`", " `", s) s = re.sub(r"\n[ ]*`", " `", s)
# remove trailing whitespaces # remove trailing whitespaces
s = re.sub(r"[ ]+$", "", s) s = re.sub(r"[ ]+$", "", s)
# remove whitespace before .
s = re.sub(r"[ ]+\.", "\.", s)
# remove .. for references # remove .. for references
s = re.sub(r"\.\. \[", "[", s) s = re.sub(r"\.\. \[", "[", s)
# unescape # unescape
s = re.sub(r"\\(.)", "\\1", s) s = re.sub(r"\\(.)", "\\1", s)
# compress whitespace
s = re.sub(r" +", " ", s)
# compress linebreaks
s = re.sub(r"\n\n+", "\n\n", s)
s = s.replace("**", "")
s = s.replace("``", "\"")
s = s.replace("`", "\"")
s = s.replace("\"\"", "\"")
s = s.replace(":ocv:cfunc:","")
s = s.replace(":ref:", "")
s = s.replace(":math:", "")
s = s.replace(":ocv:class:", "") s = s.replace(":ocv:class:", "")
s = s.replace(":ocv:struct:", "")
s = s.replace(":ocv:func:", "") s = s.replace(":ocv:func:", "")
s = s.replace(":ocv:cfunc:","")
s = s.replace(":c:type:", "") s = s.replace(":c:type:", "")
s = s.replace(":c:func:", "")
s = s.replace(":ref:", "")
s = s.replace(":math:", "")
s = s.replace(":func:", "")
s = s.replace("]_", "]") s = s.replace("]_", "]")
s = s.replace(".. note::", "Note:") s = s.replace(".. note::", "Note:")
s = s.replace(".. ocv:function::", "") s = s.replace(".. ocv:function::", "")
s = s.replace(".. ocv:cfunction::", "") s = s.replace(".. ocv:cfunction::", "")
# remove ".. identifier:" lines
s = re.sub(r"(^|\n)\.\. [a-zA-Z_0-9]+(::[a-zA-Z_0-9]+)?:(\n|$)", "\n ", s)
# unwrap urls
s = re.sub(r"`([^`<]+ )<(https?://[^>]+)>`_", "\\1(\\2)", s)
# remove whitespace before .
s = re.sub(r"[ ]+\.", ".", s)
# remove tailing whitespace
s = re.sub(r" +(\n|$)", "\\1", s)
# remove leading whitespace
s = re.sub(r"(^|\n) +", "\\1", s)
# compress line breaks
s = re.sub(r"\n\n+", "\n\n", s)
# remove other newlines
s = re.sub(r"([^.\n])\n([^*#\n])", "\\1 \\2", s)
# compress whitespace
s = re.sub(r" +", " ", s)
# remove extra space before .
s = re.sub(r"[\n ]+\.", ".", s)
s = s.replace("**", "")
s = s.replace("``", "\"")
s = s.replace("`", "\"")
s = s.replace("\"\"", "\"")
s = s.strip() s = s.strip()
return s return s
...@@ -510,7 +537,7 @@ if __name__ == "__main__": ...@@ -510,7 +537,7 @@ if __name__ == "__main__":
parser = RstParser(hdr_parser.CppHeaderParser()) parser = RstParser(hdr_parser.CppHeaderParser())
if module == "all": if module == "all":
for m in ["core", "flann", "imgproc", "ml", "highgui", "video", "features2d", "calib3d", "objdetect", "legacy", "contrib", "gpu", "androidcamera", "haartraining", "java", "ocl", "python", "stitching", "traincascade", "ts"]: for m in ["core", "flann", "imgproc", "ml", "highgui", "video", "features2d", "calib3d", "objdetect", "legacy", "contrib", "gpu", "androidcamera", "haartraining", "java", "python", "stitching", "traincascade", "ts"]:
parser.parse(m, os.path.join(rst_parser_dir, "../" + m)) parser.parse(m, os.path.join(rst_parser_dir, "../" + m))
else: else:
parser.parse(module, os.path.join(rst_parser_dir, "../" + module)) parser.parse(module, os.path.join(rst_parser_dir, "../" + module))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment