Skip to content

Commit

Permalink
Merge pull request #521 from Crozzers/fix-issue-185
Browse files Browse the repository at this point in the history
Always restore hashed HTML blocks (issue #185)
  • Loading branch information
nicholasserra committed Jul 23, 2023
2 parents 6c5fb43 + 9bdc064 commit c18de16
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGES.md
Expand Up @@ -3,6 +3,7 @@
## python-markdown2 2.4.10 (not yet released)

- [pull #520] Allow more relative links in safe mode (issue #517)
- [pull #521] Always restore hashed HTML blocks (issue #185)
- [pull #522] Add `middle-word-em` extra


Expand Down
5 changes: 4 additions & 1 deletion lib/markdown2.py
Expand Up @@ -2648,9 +2648,12 @@ def _do_link_patterns(self, text):

def _unescape_special_chars(self, text):
# Swap back in all the special characters we've hidden.
hashmap = tuple(self._escape_table.items()) + tuple(self._code_table.items())
# html_blocks table is in format {hash: item} compared to usual {item: hash}
hashmap += tuple(tuple(reversed(i)) for i in self.html_blocks.items())
while True:
orig_text = text
for ch, hash in list(self._escape_table.items()) + list(self._code_table.items()):
for ch, hash in hashmap:
text = text.replace(hash, ch)
if text == orig_text:
break
Expand Down
9 changes: 9 additions & 0 deletions test/tm-cases/hash_html_blocks.html
@@ -0,0 +1,9 @@
<div
>
<h3>Archons of the Colophon</h3>


<p>by Paco Xander Nathan
</p>

</div>
6 changes: 6 additions & 0 deletions test/tm-cases/hash_html_blocks.text
@@ -0,0 +1,6 @@
<div
>
<h3>Archons of the Colophon</h3>
<p>by Paco Xander Nathan
</p>
</div>

0 comments on commit c18de16

Please sign in to comment.