diff --git a/CHANGES.md b/CHANGES.md index 920c3024..d49a42cb 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -2,7 +2,7 @@ ## python-markdown2 2.5.5 (not yet released) -(nothing yet) +- [pull #639] Fix middle-word-em interfering with strongs (#637) ## python-markdown2 2.5.4 diff --git a/lib/markdown2.py b/lib/markdown2.py index b706215f..9c2a4bf2 100755 --- a/lib/markdown2.py +++ b/lib/markdown2.py @@ -3309,42 +3309,42 @@ def __init__(self, md: Markdown, options: Union[dict, bool, None]): options.setdefault('allowed', True) super().__init__(md, options) - self.liberal_em_re = self.em_re - if not options['allowed']: - self.em_re = re.compile(r'(?<=\b)%s(?=\b)' % self.em_re.pattern, self.em_re.flags) - self.liberal_em_re = re.compile( - r''' - ( # \1 - must be a single em char in the middle of a word - (? self.md.stage: + text = text.replace(self.hash_table['_'], '_') + text = text.replace(self.hash_table['*'], '*') + return text - def sub(self, match: re.Match) -> str: - syntax = match.group(1) - if len(syntax) != 1: - # strong syntax + def sub(self, match: re.Match): + if match.re != self.middle_word_em_re: return super().sub(match) - return '%s' % match.group(2) + + syntax = match.group(1) + return self.hash_table[syntax] class Numbering(Extra): diff --git a/test/tm-cases/middle_word_em_issue637.html b/test/tm-cases/middle_word_em_issue637.html new file mode 100644 index 00000000..5670b8de --- /dev/null +++ b/test/tm-cases/middle_word_em_issue637.html @@ -0,0 +1,2 @@ +
Visit GitHub for code repositories and +Stack Overflow for programming help.
diff --git a/test/tm-cases/middle_word_em_issue637.opts b/test/tm-cases/middle_word_em_issue637.opts new file mode 100644 index 00000000..f1455c41 --- /dev/null +++ b/test/tm-cases/middle_word_em_issue637.opts @@ -0,0 +1 @@ +{'extras': {'middle-word-em': False}} \ No newline at end of file diff --git a/test/tm-cases/middle_word_em_issue637.text b/test/tm-cases/middle_word_em_issue637.text new file mode 100644 index 00000000..5ca8a0a1 --- /dev/null +++ b/test/tm-cases/middle_word_em_issue637.text @@ -0,0 +1,2 @@ +Visit [**GitHub**](https://github.com) for code repositories and +[**Stack Overflow**](https://stackoverflow.com) for programming help. \ No newline at end of file diff --git a/test/tm-cases/middle_word_em_with_extra_ems.html b/test/tm-cases/middle_word_em_with_extra_ems.html index fb1bb95c..a86b1932 100644 --- a/test/tm-cases/middle_word_em_with_extra_ems.html +++ b/test/tm-cases/middle_word_em_with_extra_ems.html @@ -16,4 +16,4 @@one*two*three
-onetwothree
+one*two*three