Break a block into list items.
(self, block: str)
| 416 | self.parser.state.reset() |
| 417 | |
| 418 | def get_items(self, block: str) -> list[str]: |
| 419 | """ Break a block into list items. """ |
| 420 | items = [] |
| 421 | for line in block.split('\n'): |
| 422 | m = self.CHILD_RE.match(line) |
| 423 | if m: |
| 424 | # This is a new list item |
| 425 | # Check first item for the start index |
| 426 | if not items and self.TAG == 'ol': |
| 427 | # Detect the integer value of first list item |
| 428 | INTEGER_RE = re.compile(r'(\d+)') |
| 429 | self.STARTSWITH = INTEGER_RE.match(m.group(1)).group() |
| 430 | # Append to the list |
| 431 | items.append(m.group(3)) |
| 432 | elif self.INDENT_RE.match(line): |
| 433 | # This is an indented (possibly nested) item. |
| 434 | if items[-1].startswith(' '*self.tab_length): |
| 435 | # Previous item was indented. Append to that item. |
| 436 | items[-1] = '{}\n{}'.format(items[-1], line) |
| 437 | else: |
| 438 | items.append(line) |
| 439 | else: |
| 440 | # This is another line of previous item. Append to that item. |
| 441 | items[-1] = '{}\n{}'.format(items[-1], line) |
| 442 | return items |
| 443 | |
| 444 | |
| 445 | class UListProcessor(OListProcessor): |