diff --git a/markdown_it/rules_inline/text.py b/markdown_it/rules_inline/text.py index f306b2e4..18b2fcc7 100644 --- a/markdown_it/rules_inline/text.py +++ b/markdown_it/rules_inline/text.py @@ -1,3 +1,6 @@ +import functools +import re + # Skip text characters for text token, place those to pending buffer # and increment current pos from .state_inline import StateInline @@ -36,11 +39,17 @@ } +@functools.cache +def _terminator_char_regex() -> re.Pattern[str]: + return re.compile("[" + re.escape("".join(_TerminatorChars)) + "]") + + def text(state: StateInline, silent: bool) -> bool: pos = state.pos posMax = state.posMax - while (pos < posMax) and state.src[pos] not in _TerminatorChars: - pos += 1 + + terminator_char = _terminator_char_regex().search(state.src, pos) + pos = terminator_char.start() if terminator_char else posMax if pos == state.pos: return False