in src/doc_builder/autodoc.py [0:0]
def get_signature_component_markdown(name, anchor, signature, object_doc, source_link=None, is_getset_desc=False):
"""
Returns the svelte `Docstring` component string.
Args:
- **name** (`str`) -- The name of the function or class to document.
- **anchor** (`str`) -- The anchor name of the function or class that will be used for hash links.
- **signature** (`List(Dict(str,str))`) -- The signature of the object.
- **object_doc** (`str`) -- The docstring of the the object.
- **source_link** (Union[`str`, `None`], *optional*, defaults to `None`) -- The github source link of the the object.
- **is_getset_desc** (`bool`, *optional*, defaults to `False`) -- Whether the type of obj is `getset_descriptor`.
"""
object_doc = _re_returns.sub(lambda m: inside_example_finder_closure(m, "returns"), object_doc)
object_doc = _re_parameters.sub(lambda m: inside_example_finder_closure(m, "parameters"), object_doc)
object_doc, parameters = regex_closure(object_doc, _re_parameters)
object_doc, return_description = regex_closure(object_doc, _re_returns)
object_doc, returntype = regex_closure(object_doc, _re_returntype)
object_doc, yield_description = regex_closure(object_doc, _re_yields)
object_doc, yieldtype = regex_closure(object_doc, _re_yieldtype)
object_doc, raise_description = regex_closure(object_doc, _re_raises)
object_doc, raisederrors = regex_closure(object_doc, _re_raisederrors)
object_doc = remove_example_tags(object_doc)
object_doc = hashlink_example_codeblock(object_doc, anchor, False)
# TODO: maybe something like method defintion ?
# markdown_str = "<docstring>"
markdown_str = ""
# markdown_str += f"<name>{name}</name>"
markdown_str += f"Docstring for: {anchor}\n"
markdown_str += f"{object_doc.strip()}\n"
# TODO: useful info to have
# if source_link:
# markdown_str += f"<source>{source_link}</source>"
if len(signature):
signature = json.dumps(signature)
markdown_str += f"Arguments: {signature}\n"
# TODO: write a string that says it is a get method
# if is_getset_desc:
# markdown_str += "<isgetsetdescriptor>"
if parameters is not None:
parameters_str = ""
groups = _re_parameter_group.split(parameters)
group_default = groups.pop(0)
parameters_str += f"Arguments description:\n{group_default}\n"
n_groups = len(groups) // 2
for idx in range(n_groups):
group = groups[2 * idx + 1]
parameters_str += f"\n{group}\n"
markdown_str += parameters_str
if returntype is not None:
markdown_str += (
f"Returns: {returntype}{f' that is {return_description}' if return_description is not None else ''}\n"
)
if yieldtype is not None:
markdown_str += (
f"Yields: {yieldtype}{f' that is {yield_description}' if yield_description is not None else ''}\n"
)
if raisederrors is not None:
markdown_str += (
f"Raises: {raisederrors}{f' that is {raise_description}' if raise_description is not None else ''}\n"
)
markdown_str = re.sub(r"\n+", "\n", markdown_str)
# print(markdown_str)
return markdown_str