Convert all docstrings in ``_docstrings_list`` into a single sphinx-legible text block.
()
| 25 | |
| 26 | |
| 27 | def _parse_docstrings() -> str: |
| 28 | """Convert all docstrings in ``_docstrings_list`` into a single |
| 29 | sphinx-legible text block. |
| 30 | |
| 31 | """ |
| 32 | type_list_ret = [] |
| 33 | for name, value, doc in _docstrings_list: |
| 34 | s = textwrap.dedent(doc).replace("\n", "\n ") |
| 35 | |
| 36 | # Replace sections by rubrics |
| 37 | lines = s.split("\n") |
| 38 | new_lines = [] |
| 39 | indent = "" |
| 40 | for line in lines: |
| 41 | m = re.match(r'^(\s+)[-=]+\s*$', line) |
| 42 | if m and new_lines: |
| 43 | prev = textwrap.dedent(new_lines.pop()) |
| 44 | if prev == "Examples": |
| 45 | indent = "" |
| 46 | new_lines.append(f'{m.group(1)}.. rubric:: {prev}') |
| 47 | else: |
| 48 | indent = 4 * " " |
| 49 | new_lines.append(f'{m.group(1)}.. admonition:: {prev}') |
| 50 | new_lines.append("") |
| 51 | else: |
| 52 | new_lines.append(f"{indent}{line}") |
| 53 | |
| 54 | s = "\n".join(new_lines) |
| 55 | s_block = f""".. data:: {name}\n :value: {value}\n {s}""" |
| 56 | type_list_ret.append(s_block) |
| 57 | return "\n".join(type_list_ret) |
| 58 | |
| 59 | |
| 60 | add_newdoc('ArrayLike', 'typing.Union[...]', |
no test coverage detected