diff --git a/markdown_it/rules_block/state_block.py b/markdown_it/rules_block/state_block.py index 96a2f88f..445ad265 100644 --- a/markdown_it/rules_block/state_block.py +++ b/markdown_it/rules_block/state_block.py @@ -147,8 +147,12 @@ def skipEmptyLines(self, from_pos: int) -> int: def skipSpaces(self, pos: int) -> int: """Skip spaces from given position.""" - while pos < len(self.src): - if not isStrSpace(self.src[pos]): + while True: + try: + current = self.src[pos] + except IndexError: + break + if not isStrSpace(current): break pos += 1 return pos @@ -165,16 +169,24 @@ def skipSpacesBack(self, pos: int, minimum: int) -> int: def skipChars(self, pos: int, code: int) -> int: """Skip character code from given position.""" - while pos < len(self.src): - if self.srcCharCode[pos] != code: + while True: + try: + current = self.srcCharCode[pos] + except IndexError: + break + if current != code: break pos += 1 return pos def skipCharsStr(self, pos: int, ch: str) -> int: """Skip character string from given position.""" - while pos < len(self.src): - if self.src[pos] != ch: + while True: + try: + current = self.src[pos] + except IndexError: + break + if current != ch: break pos += 1 return pos