Initialize.
(
self,
token: str,
tags: str,
md: Markdown,
smart: bool = False,
double: bool = False
)
| 643 | SPACE = re.compile(r'\s') |
| 644 | |
| 645 | def __init__( |
| 646 | self, |
| 647 | token: str, |
| 648 | tags: str, |
| 649 | md: Markdown, |
| 650 | smart: bool = False, |
| 651 | double: bool = False |
| 652 | ) -> None: |
| 653 | """Initialize.""" |
| 654 | |
| 655 | md.delimiters = self |
| 656 | self.regions: list[tuple[int, int, int, int, tuple[str, str], int]] = [] |
| 657 | # Unpaired delimiter. The entries are the same as `Delimiter.stack`. |
| 658 | # HTML element cache of valid regions. Each entry holds the element, the location it replaces, |
| 659 | # and the location of the token Python Markdown will call us for once the element has been replaced. |
| 660 | self.cache: list[tuple[etree.Element, int, int, int]] = [] |
| 661 | # The entries are the same as `Delimiter.stack`. |
| 662 | self.stack: list[tuple[int, int, bool, int, int]] = [] |
| 663 | # Position of every delimiter token (valid or not) encountered while pairing, in ascending order. |
| 664 | self.positions: list[int] = [] |
| 665 | # For each token and run length, how deep the last failed rule of 3 search went and the entry at that depth. |
| 666 | self.searched: dict[tuple[str, int], tuple[int, tuple[int, int, bool, int, int]]] = {} |
| 667 | self.tokens: list[str] = [] |
| 668 | self.delimiters: dict[str, Delimiter] = {} |
| 669 | self.cache_index = 0 |
| 670 | self.cache_pos = 0 |
| 671 | # Info about the unused part of a closing delimiter run that directly follows the last returned element |
| 672 | self.remainder: tuple[str, str] | None = None |
| 673 | self.md = md |
| 674 | # API for Markdown to pass `safe_mode` into instance |
| 675 | self.safe_mode = False |
| 676 | self.add(token, tags, smart, double) |
| 677 | |
| 678 | def add( |
| 679 | self, |