Skip to content

Commit

Permalink
👌 Improve performance of "text" inline rule (#347)
Browse files Browse the repository at this point in the history
  • Loading branch information
hukkin authored Dec 17, 2024
1 parent 1a43fa3 commit c5161b5
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions markdown_it/rules_inline/text.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit c5161b5

Please sign in to comment.