Skip to content

👌 Improve performance of "text" inline rule #347

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 17, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions markdown_it/rules_inline/text.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
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 @@ -34,13 +36,15 @@
"}",
"~",
}
_RE_TERMINATOR_CHAR = 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 = _RE_TERMINATOR_CHAR.search(state.src, pos)
pos = terminator_char.start() if terminator_char else posMax

if pos == state.pos:
return False
Expand Down
Loading