Skip to content

Commit 3cb89bb

Browse files
committed
Fix Tilde, Caret performance with long, invalid delimiters
1 parent d3d1f90 commit 3cb89bb

2 files changed

Lines changed: 7 additions & 3 deletions

File tree

‎docs/src/markdown/about/changelog.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ icon: lucide/scroll-text
66
## 12.1
77

88
- **NEW**: SuperFences: Add optional `reset` function that can be specified for custom fences.
9+
- **FIX**: Tilde, Caret: Fix performance for long invalid delimiters.
910

1011
## 12.0.1
1112

‎pymdownx/delimiterprocessor.py‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,8 @@ def _build_patterns(self, token: str) -> str:
219219
flags=re.UNICODE
220220
)
221221

222+
self.bad = re.compile(fr'{etoken}+')
223+
222224
return fr'{etoken}'
223225

224226
def reset(self) -> None:
@@ -557,10 +559,11 @@ def handleMatch( # type: ignore[override]
557559
# If token is not an opening, quit
558560
m2 = self.get_match(data, m.start(0))
559561
if m2 is None or m2.lastgroup[0] == 'e': # type: ignore[index]
560-
if m2 is not None:
561-
m = m2
562+
if m2 is None:
563+
delim = self.delimiters[m.group(0)]
564+
m2 = delim.bad.match(data, m.start(0))
562565
# Advance past the full length of the delimiter found
563-
return None, m.start(0), m.end(0)
566+
return None, m2.start(0), m2.end(0)
564567

565568
# Get the stack and regions
566569
token = data[m.start(0)]

0 commit comments

Comments
 (0)