Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion markdown_it/common/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ def escapeHtml(raw: str) -> str:


def escapeRE(string: str) -> str:
string = REGEXP_ESCAPE_RE.sub("\\$&", string)
string = REGEXP_ESCAPE_RE.sub(r"\\\g<0>", string)
return string


Expand Down
8 changes: 8 additions & 0 deletions tests/test_port/test_misc.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from importlib.util import find_spec
import re

import pytest

Expand Down Expand Up @@ -133,3 +134,10 @@ def test_backtick_closer_ending_at_pos_max():
("code_inline", "a", "``")
]
assert state.pos == 5


def test_escape_re():
"""``utils.escapeRE`` backslash-escapes regex characters, as upstream does."""
escaped = MarkdownIt().utils.escapeRE("a.b*c$")
assert escaped == r"a\.b\*c\$"
assert re.fullmatch(escaped, "a.b*c$")