|
1 | 1 | from __future__ import annotations |
2 | 2 |
|
3 | 3 | from pathlib import Path, PurePath |
4 | | -from typing import Iterable, Callable |
| 4 | +from typing import Callable, Iterable |
5 | 5 |
|
6 | 6 | from markdown_it import MarkdownIt |
7 | 7 | from rich import box |
@@ -304,15 +304,22 @@ class MarkdownOrderedList(MarkdownList): |
304 | 304 | """ |
305 | 305 |
|
306 | 306 | def compose(self) -> ComposeResult: |
| 307 | + suffix = ". " |
| 308 | + start = 1 |
| 309 | + if self._blocks and isinstance(self._blocks[0], MarkdownOrderedListItem): |
| 310 | + try: |
| 311 | + start = int(self._blocks[0].bullet) |
| 312 | + except ValueError: |
| 313 | + pass |
307 | 314 | symbol_size = max( |
308 | | - len(block.bullet) |
309 | | - for block in self._blocks |
| 315 | + len(f"{number}{suffix}") |
| 316 | + for number, block in enumerate(self._blocks, start) |
310 | 317 | if isinstance(block, MarkdownListItem) |
311 | 318 | ) |
312 | | - for block in self._blocks: |
| 319 | + for number, block in enumerate(self._blocks, start): |
313 | 320 | if isinstance(block, MarkdownListItem): |
314 | 321 | bullet = MarkdownBullet() |
315 | | - bullet.symbol = block.bullet.rjust(symbol_size + 1) |
| 322 | + bullet.symbol = f"{number}{suffix}".rjust(symbol_size + 1) |
316 | 323 | yield Horizontal(bullet, VerticalScroll(*block._blocks)) |
317 | 324 |
|
318 | 325 | self._blocks.clear() |
@@ -636,7 +643,7 @@ async def update(self, markdown: str) -> None: |
636 | 643 | stack.append(MarkdownOrderedList()) |
637 | 644 | elif token.type == "list_item_open": |
638 | 645 | if token.info: |
639 | | - stack.append(MarkdownOrderedListItem(f"{token.info}. ")) |
| 646 | + stack.append(MarkdownOrderedListItem(token.info)) |
640 | 647 | else: |
641 | 648 | item_count = sum( |
642 | 649 | 1 |
|
0 commit comments