(
out: TextIO,
obj: Section | Table | list,
base_stats: Stats,
head_stats: Stats | None = None,
level: int = 2,
)
| 1411 | |
| 1412 | |
| 1413 | def output_markdown( |
| 1414 | out: TextIO, |
| 1415 | obj: Section | Table | list, |
| 1416 | base_stats: Stats, |
| 1417 | head_stats: Stats | None = None, |
| 1418 | level: int = 2, |
| 1419 | ) -> None: |
| 1420 | def to_markdown(x): |
| 1421 | if hasattr(x, "markdown"): |
| 1422 | return x.markdown() |
| 1423 | elif isinstance(x, str): |
| 1424 | return x |
| 1425 | elif x is None: |
| 1426 | return "" |
| 1427 | else: |
| 1428 | raise TypeError(f"Can't convert {x} to markdown") |
| 1429 | |
| 1430 | match obj: |
| 1431 | case Section(): |
| 1432 | if obj.title: |
| 1433 | print("#" * level, obj.title, file=out) |
| 1434 | print(file=out) |
| 1435 | print("<details>", file=out) |
| 1436 | print("<summary>", obj.summary, "</summary>", file=out) |
| 1437 | print(file=out) |
| 1438 | if obj.doc: |
| 1439 | print(obj.doc, file=out) |
| 1440 | |
| 1441 | if head_stats is not None and obj.comparative is False: |
| 1442 | print("Not included in comparative output.\n") |
| 1443 | else: |
| 1444 | for part in obj.part_iter(base_stats, head_stats): |
| 1445 | output_markdown(out, part, base_stats, head_stats, level=level + 1) |
| 1446 | print(file=out) |
| 1447 | if obj.title: |
| 1448 | print("</details>", file=out) |
| 1449 | print(file=out) |
| 1450 | |
| 1451 | case Table(): |
| 1452 | header, rows = obj.get_table(base_stats, head_stats) |
| 1453 | if len(rows) == 0: |
| 1454 | return |
| 1455 | |
| 1456 | alignments = [] |
| 1457 | for item in header: |
| 1458 | if item.endswith(":"): |
| 1459 | alignments.append("right") |
| 1460 | else: |
| 1461 | alignments.append("left") |
| 1462 | |
| 1463 | print("<table>", file=out) |
| 1464 | print("<thead>", file=out) |
| 1465 | print("<tr>", file=out) |
| 1466 | for item, align in zip(header, alignments): |
| 1467 | if item.endswith(":"): |
| 1468 | item = item[:-1] |
| 1469 | print(f'<th align="{align}">{item}</th>', file=out) |
| 1470 | print("</tr>", file=out) |
no test coverage detected
searching dependent graphs…