Skip to content

Commit d60c16f

Browse files
committed
Unescape any backslash escaped inline raw HTML
Fixes #1358.
1 parent 93054dd commit d60c16f

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

docs/change_log/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ Python-Markdown Change Log
66
*under development*: version 3.4.4 (a bug-fix release).
77

88
* Add a special case for initial 's to smarty extension (#1305).
9+
* Unescape any backslash escaped inline raw HTML (#1358).
910

1011
March 23, 2023: version 3.4.3 (a bug-fix release).
1112

markdown/inlinepatterns.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,7 @@ def handleMatch(self, m, data): # pragma: no cover
416416
class HtmlInlineProcessor(InlineProcessor):
417417
""" Store raw inline html and return a placeholder. """
418418
def handleMatch(self, m, data):
419-
rawhtml = self.unescape(m.group(1))
419+
rawhtml = self.backslash_unescape(self.unescape(m.group(1)))
420420
place_holder = self.md.htmlStash.store(rawhtml)
421421
return place_holder, m.start(0), m.end(0)
422422

@@ -438,6 +438,18 @@ def get_stash(m):
438438

439439
return util.INLINE_PLACEHOLDER_RE.sub(get_stash, text)
440440

441+
def backslash_unescape(self, text):
442+
""" Return text with backslash escapes undone (backslashes are restored). """
443+
try:
444+
RE = self.md.treeprocessors['unescape'].RE
445+
except KeyError: # pragma: no cover
446+
return text
447+
448+
def _unescape(m):
449+
return chr(int(m.group(1)))
450+
451+
return RE.sub(_unescape, text)
452+
441453

442454
class AsteriskProcessor(InlineProcessor):
443455
"""Emphasis processor for handling strong and em matches inside asterisks."""

tests/test_syntax/inline/test_raw_html.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,6 @@ def test_inline_html_angle_brackets(self):
2828
self.assertMarkdownRenders("<span>e>c</span>", "<p><span>e&gt;c</span></p>")
2929
self.assertMarkdownRenders("<span>e < c</span>", "<p><span>e &lt; c</span></p>")
3030
self.assertMarkdownRenders("<span>e > c</span>", "<p><span>e &gt; c</span></p>")
31+
32+
def test_inline_html_backslashes(self):
33+
self.assertMarkdownRenders('<img src="..\\..\\foo.png">', '<p><img src="..\\..\\foo.png"></p>')

0 commit comments

Comments
 (0)