Skip to content
Draft
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
12 changes: 6 additions & 6 deletions lib/markdown2.py
Original file line number Diff line number Diff line change
Expand Up @@ -2584,7 +2584,7 @@ class GFMItalicAndBoldProcessor(Extra):
def run(self, text: str):
nesting = True
orig_text = ""
while nesting and orig_text != _hash_text(text):
while nesting or orig_text != _hash_text(text):
orig_text = _hash_text(text)
nesting = False

Expand Down Expand Up @@ -2838,14 +2838,16 @@ def should_process_imbalanced_delimiter_runs(
open_syntax = open.group(1)[open_offset:]

syntax = close.group(1)
em_type = syntax[0]
left, right = self.delimiter_left_or_right(close)

if len(open_syntax) < len(syntax) and len(syntax) >= 3:
# if closing syntax is bigger and its >= three long then focus on closing any
# open em spans
return True

if next_delim_run is None:
# if no delimiter run after OR the next run is of a different syntax
if next_delim_run is None or next_delim_run[0].group(1)[0] != em_type:
return True

if len(open_syntax) < len(syntax) and (
Expand Down Expand Up @@ -3450,12 +3452,10 @@ def process_span(self, open: re.Match[str], close: re.Match[str], offset: int, m
open_syntax = open.group(1)[offset:]
close_syntax = close.group(1)

if len(open_syntax) > 2 or open_syntax != close_syntax:
return [text], None

if '_' in open_syntax:
min_syntax = min(open_syntax, close_syntax)
# if using _this_ syntax, hash it to avoid processing, but don't hash the contents incase of nested syntax
text = text.replace(open_syntax, _hash_text(self.name + open_syntax))
text = text.replace(min_syntax, _hash_text(self.name + min_syntax))
return [text], None
elif '_' in text:
# if the text within the bold/em markers contains '_' then hash those chars to protect them from em_re
Expand Down
3 changes: 3 additions & 0 deletions test/tm-cases/code_friendly_issue671.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<p>__A___B_C_D_E_F_G</p>

<p><strong>A_B</strong> <a href="https://example.com/">C_D_E</a></p>
1 change: 1 addition & 0 deletions test/tm-cases/code_friendly_issue671.opts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{'extras': ['code-friendly']}
3 changes: 3 additions & 0 deletions test/tm-cases/code_friendly_issue671.text
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
__A___B_C_D_E_F_G

**A_B** [C_D_E](https://example.com/)
7 changes: 7 additions & 0 deletions test/tm-cases/gfm_emphasis_issue671.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<p><em>A-></em><strong>B</strong></p>

<p><strong>A-></strong><strong>B</strong></p>

<p>*<em>A</em> B_<em>C</em></p>

<p>*<em>A</em> B C_D. X Y Z *</p>
7 changes: 7 additions & 0 deletions test/tm-cases/gfm_emphasis_issue671.text
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
*A->***B**

**A->****B**

**A* B_*C*

**A* B C_D. X Y Z *
Loading