From 078f76ad881721af70df5a2bd44e3a970c32efe7 Mon Sep 17 00:00:00 2001 From: Crozzers Date: Sat, 9 Dec 2023 11:36:52 +0000 Subject: [PATCH] Fix bad handling of consecutive bold words (#541) --- lib/markdown2.py | 4 ++-- test/tm-cases/consecutive_strong_em.html | 7 +++++++ test/tm-cases/consecutive_strong_em.text | 7 +++++++ 3 files changed, 16 insertions(+), 2 deletions(-) create mode 100644 test/tm-cases/consecutive_strong_em.html create mode 100644 test/tm-cases/consecutive_strong_em.text diff --git a/lib/markdown2.py b/lib/markdown2.py index 7d36c1c3..b9ae2479 100755 --- a/lib/markdown2.py +++ b/lib/markdown2.py @@ -2395,9 +2395,9 @@ def _do_tg_spoiler(self, text): text = self._tg_spoiler_re.sub(r"\1", text) return text - _strong_re = re.compile(r"(\*\*|__)(?=\S)(.*\S)\1", re.S) + _strong_re = re.compile(r"(\*\*|__)(?=\S)(.+?[*_]?)(?<=\S)\1", re.S) _em_re = r"(\*|_)(?=\S)(.*?\S)\1" - _code_friendly_strong_re = re.compile(r"\*\*(?=\S)(.*\S)\*\*", re.S) + _code_friendly_strong_re = re.compile(r"\*\*(?=\S)(.+?[*_]?)(?<=\S)\*\*", re.S) _code_friendly_em_re = r"\*(?=\S)(.+?)\*" def _do_italics_and_bold(self, text): if self.extras.get('middle-word-em', True) is False: diff --git a/test/tm-cases/consecutive_strong_em.html b/test/tm-cases/consecutive_strong_em.html new file mode 100644 index 00000000..b2e92c7b --- /dev/null +++ b/test/tm-cases/consecutive_strong_em.html @@ -0,0 +1,7 @@ +

a b c

+ +

a b c

+ +

a b c

+ +

a b c

diff --git a/test/tm-cases/consecutive_strong_em.text b/test/tm-cases/consecutive_strong_em.text new file mode 100644 index 00000000..1fde0000 --- /dev/null +++ b/test/tm-cases/consecutive_strong_em.text @@ -0,0 +1,7 @@ +**a** b **c** + +*a* b *c* + +__a__ b __c__ + +_a_ b _c_