Skip to content

Commit

Permalink
Fix #185 by always restoring hashed html blocks at the end of convers…
Browse files Browse the repository at this point in the history
…ion.

Nested hashes don't get unravelled in `_form_paragraphs`
  • Loading branch information
Crozzers committed Jul 22, 2023
1 parent 863a3af commit 4ea5035
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/markdown2.py
Original file line number Diff line number Diff line change
Expand Up @@ -2638,9 +2638,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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<div
>
<h3>Archons of the Colophon</h3>
<p>by Paco Xander Nathan
</p>
</div>

0 comments on commit 4ea5035

Please sign in to comment.