MCPcopy Create free account
hub / github.com/Python-Markdown/markdown / get_items

Method get_items

markdown/blockprocessors.py:424–451  ·  view source on GitHub ↗

Break a block into list items.

(self, block: str)

Source from the content-addressed store, hash-verified

422 self.parser.state.reset()
423
424 def get_items(self, block: str) -> list[str]:
425 """ Break a block into list items. """
426 # The lines of an item are collected in a list and joined once at the end.
427 # Appending per line, as in `item = '{}\n{}'.format(item, line)`, copies the
428 # whole item every time, which is quadratic in the number of lines of an item.
429 items: list[list[str]] = []
430 for line in block.split('\n'):
431 m = self.CHILD_RE.match(line)
432 if m:
433 # This is a new list item
434 # Check first item for the start index
435 if not items and self.TAG == 'ol':
436 # Detect the integer value of first list item
437 INTEGER_RE = re.compile(r'(\d+)')
438 self.STARTSWITH = INTEGER_RE.match(m.group(1)).group()
439 # Append to the list
440 items.append([m.group(3)])
441 elif self.INDENT_RE.match(line):
442 # This is an indented (possibly nested) item.
443 if items[-1][0].startswith(' '*self.tab_length):
444 # Previous item was indented. Append to that item.
445 items[-1].append(line)
446 else:
447 items.append([line])
448 else:
449 # This is another line of previous item. Append to that item.
450 items[-1].append(line)
451 return ['\n'.join(item) for item in items]
452
453
454class UListProcessor(OListProcessor):

Callers 1

runMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected