diff --git a/lib/markdown2.py b/lib/markdown2.py index 330ddea8..194a23d7 100755 --- a/lib/markdown2.py +++ b/lib/markdown2.py @@ -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 @@ -2838,6 +2838,7 @@ 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: @@ -2845,7 +2846,8 @@ def should_process_imbalanced_delimiter_runs( # 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 ( @@ -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 diff --git a/test/tm-cases/code_friendly_issue671.html b/test/tm-cases/code_friendly_issue671.html new file mode 100644 index 00000000..1f41b82d --- /dev/null +++ b/test/tm-cases/code_friendly_issue671.html @@ -0,0 +1,3 @@ +
__A___B_C_D_E_F_G
+ +A_B C_D_E
diff --git a/test/tm-cases/code_friendly_issue671.opts b/test/tm-cases/code_friendly_issue671.opts new file mode 100644 index 00000000..8eb3b9ef --- /dev/null +++ b/test/tm-cases/code_friendly_issue671.opts @@ -0,0 +1 @@ +{'extras': ['code-friendly']} \ No newline at end of file diff --git a/test/tm-cases/code_friendly_issue671.text b/test/tm-cases/code_friendly_issue671.text new file mode 100644 index 00000000..f3e9bb83 --- /dev/null +++ b/test/tm-cases/code_friendly_issue671.text @@ -0,0 +1,3 @@ +__A___B_C_D_E_F_G + +**A_B** [C_D_E](https://example.com/) \ No newline at end of file diff --git a/test/tm-cases/gfm_emphasis_issue671.html b/test/tm-cases/gfm_emphasis_issue671.html new file mode 100644 index 00000000..16f51368 --- /dev/null +++ b/test/tm-cases/gfm_emphasis_issue671.html @@ -0,0 +1,7 @@ +A->B
+ +A->B
+ +*A B_C
+ +*A B C_D. X Y Z *
diff --git a/test/tm-cases/gfm_emphasis_issue671.text b/test/tm-cases/gfm_emphasis_issue671.text new file mode 100644 index 00000000..1a045d70 --- /dev/null +++ b/test/tm-cases/gfm_emphasis_issue671.text @@ -0,0 +1,7 @@ +*A->***B** + +**A->****B** + +**A* B_*C* + +**A* B C_D. X Y Z *