(node: Any, ordered: bool, depth: int)
| 163 | |
| 164 | |
| 165 | def _render_list(node: Any, ordered: bool, depth: int) -> Text: |
| 166 | result = Text() |
| 167 | items = list(node.children) |
| 168 | start = 1 |
| 169 | if ordered: |
| 170 | try: |
| 171 | start = int(node.attrGet("start") or 1) |
| 172 | except (TypeError, ValueError): |
| 173 | start = 1 |
| 174 | |
| 175 | for i, item in enumerate(items): |
| 176 | indent = " " * depth |
| 177 | cont = indent + " " |
| 178 | if ordered: |
| 179 | prefix = f"{_list_number(depth, start + i)}. " |
| 180 | else: |
| 181 | prefix = "- " |
| 182 | result.append(indent + prefix) |
| 183 | first = True |
| 184 | for child in item.children or []: |
| 185 | if child.type == "paragraph": |
| 186 | if not first: |
| 187 | result.append("\n" + cont) |
| 188 | _append_with_cont_indent(result, _render_inline_container(child), cont) |
| 189 | first = False |
| 190 | elif child.type in ("bullet_list", "ordered_list"): |
| 191 | result.append("\n") |
| 192 | result.append_text( |
| 193 | _render_list( |
| 194 | child, |
| 195 | ordered=(child.type == "ordered_list"), |
| 196 | depth=depth + 1, |
| 197 | ) |
| 198 | ) |
| 199 | elif child.type in ("fence", "code_block"): |
| 200 | if not first: |
| 201 | result.append("\n" + cont) |
| 202 | _append_with_cont_indent(result, _render_code_as_text(child), cont) |
| 203 | first = False |
| 204 | else: |
| 205 | rendered = _render_block(child) |
| 206 | if rendered is None: |
| 207 | continue |
| 208 | if not first: |
| 209 | result.append("\n" + cont) |
| 210 | if isinstance(rendered, Text): |
| 211 | _append_with_cont_indent(result, rendered, cont) |
| 212 | first = False |
| 213 | if i < len(items) - 1: |
| 214 | result.append("\n") |
| 215 | return result |
| 216 | |
| 217 | |
| 218 | def _list_number(depth: int, n: int) -> str: |
no test coverage detected