PY-16871 Unescape asterisks in parameter names and don't turn them into hyperlinks
authorMikhail Golubev <mikhail.golubev@jetbrains.com>
Wed, 23 Sep 2015 14:21:17 +0000 (17:21 +0300)
committerMikhail Golubev <mikhail.golubev@jetbrains.com>
Wed, 23 Sep 2015 15:42:18 +0000 (18:42 +0300)
python/helpers/rest_formatter.py

index 98f99150b0ea0296746de92ad9c1a204e4146de0..24b0c7bcbb0b78f705ae86839dee69ce79465403 100644 (file)
@@ -112,8 +112,10 @@ class RestHTMLTranslator(_EpydocHTMLTranslator):
       if rawsource.startswith("param "):
         index = rawsource.index("param ")
         if len(child.children) == 0: continue
-        child.children[0] = Text(rawsource[index + 6:])
-        fields[rawsource[index + 6:]] = n
+        # Strip leading escaped asterisks for vararg parameters in Google code style docstrings
+        trimmed_name = re.sub(r'\\\*', '*', rawsource[index + 6:])
+        child.children[0] = Text(trimmed_name)
+        fields[trimmed_name] = n
       if rawsource == "return":
         fields["return"] = n
 
@@ -123,7 +125,7 @@ class RestHTMLTranslator(_EpydocHTMLTranslator):
       rawsource = child.rawsource
       if rawsource.startswith("type "):
         index = rawsource.index("type ")
-        name = rawsource[index + 5:]
+        name = re.sub(r'\\\*', '*', rawsource[index + 5:])
         if fields.has_key(name):
           fields[name].type = n.children[1][0][0]
           node.children.remove(n)
@@ -141,6 +143,13 @@ class RestHTMLTranslator(_EpydocHTMLTranslator):
   def unknown_departure(self, node):
     """ Ignore unknown nodes """
 
+  def visit_problematic(self, node):
+    """Don't insert hyperlinks to nowhere for e.g. unclosed asterisks."""
+    # Note that children text elements will be visited anyway
+
+  def depart_problematic(self, node):
+    pass
+
   def visit_block_quote(self, node):
     self.body.append(self.emptytag(node, "br"))