def _process(self, node: docspec.ApiObject): if not node.docstring: return lines = [] current_lines = [] in_codeblock = False keyword = None def _commit(): if keyword: generate_sections_markdown(lines, {keyword: current_lines}) else: lines.extend(current_lines) current_lines.clear() for line in node.docstring.split('\n'): if line.startswith("```"): in_codeblock = not in_codeblock current_lines.append(line) continue if in_codeblock: current_lines.append(line) continue line = line.strip() if line in self._keywords_map: _commit() keyword = self._keywords_map[line] continue if keyword is None: lines.append(line) continue for param_re in self._param_res: param_match = param_re.match(line) if param_match: if 'type' in param_match.groupdict(): current_lines.append( '- `{param}` _{type}_ - {desc}'.format( **param_match.groupdict())) else: current_lines.append('- `{param}` - {desc}'.format( **param_match.groupdict())) break if not param_match: current_lines.append(' {line}'.format(line=line)) _commit() node.docstring = '\n'.join(lines)
def _process(self, node: docspec.ApiObject): if not getattr(node, 'docstring', None): return lines = [] codeblock_opened = False current_section = None for line in node.docstring.split('\n'): if line.startswith("```"): codeblock_opened = (not codeblock_opened) if not codeblock_opened: line, current_section = self._preprocess_line( line, current_section) lines.append(line) node.docstring = '\n'.join(lines)
def _process(self, obj: docspec.ApiObject): if not obj.docstring: return None for name in ('google', 'pydocmd', 'sphinx'): indicator = '@doc:fmt:' + name if indicator in obj.docstring: obj.docstring = obj.docstring.replace(indicator, '') return getattr(self, name)._process(obj) if self.sphinx.check_docstring_format(obj.docstring): return self.sphinx._process(obj) if self.google.check_docstring_format(obj.docstring): return self.google._process(obj) return self.pydocmd._process(obj)
def _preprocess_refs( self, node: docspec.ApiObject, resolver: Resolver, reverse: docspec.ReverseMap, unresolved: Dict[str, List[str]], ) -> None: if not node.docstring: return def handler(match): ref = match.group("ref") parens = match.group("parens") or "" trailing = (match.group("trailing") or "").lstrip("#") # Remove the dot from the ref if its trailing (it is probably just # the end of the sentence). has_trailing_dot = False if trailing and trailing.endswith("."): trailing = trailing[:-1] has_trailing_dot = True elif not parens and ref.endswith("."): ref = ref[:-1] has_trailing_dot = True href = resolver.resolve_ref(node, ref) if href: result = "[`{}`]({})".format(ref + parens + trailing, href) else: uid = ".".join(x.name for x in reverse.path(node)) unresolved.setdefault(uid, []).append(ref) result = "`{}`".format(ref + parens) # Add back the dot. if has_trailing_dot: result += "." return result node.docstring = re.sub( r"\B:obj:`(?P<ref>[\w\d\._]+)(?P<parens>\(\))?(?P<trailing>#[\w\d\._]+)?`", handler, node.docstring, )