Skip to content

Commit 9616588

Browse files
committed
👌 Improve performance of "text" inline rule
1 parent 1a43fa3 commit 9616588

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

markdown_it/rules_inline/text.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import re
2+
13
# Skip text characters for text token, place those to pending buffer
24
# and increment current pos
35
from .state_inline import StateInline
@@ -34,13 +36,15 @@
3436
"}",
3537
"~",
3638
}
39+
_RE_TERMINATOR_CHAR = re.compile("[" + re.escape("".join(_TerminatorChars)) + "]")
3740

3841

3942
def text(state: StateInline, silent: bool) -> bool:
4043
pos = state.pos
4144
posMax = state.posMax
42-
while (pos < posMax) and state.src[pos] not in _TerminatorChars:
43-
pos += 1
45+
46+
terminator_char = _RE_TERMINATOR_CHAR.search(state.src, pos)
47+
pos = terminator_char.start() if terminator_char else posMax
4448

4549
if pos == state.pos:
4650
return False

0 commit comments

Comments
 (0)