From fe5b63e6a91239148bcd7e4cab0dbb3166fd1c9d Mon Sep 17 00:00:00 2001 From: Crozzers Date: Sat, 11 Oct 2025 12:11:47 +0100 Subject: [PATCH] Fix #646 --- lib/markdown2.py | 3 ++- test/tm-cases/code_friendly_issue646.html | 1 + test/tm-cases/code_friendly_issue646.opts | 1 + test/tm-cases/code_friendly_issue646.text | 1 + 4 files changed, 5 insertions(+), 1 deletion(-) create mode 100644 test/tm-cases/code_friendly_issue646.html create mode 100644 test/tm-cases/code_friendly_issue646.opts create mode 100644 test/tm-cases/code_friendly_issue646.text diff --git a/lib/markdown2.py b/lib/markdown2.py index 8b99ec3d..3f7e4b87 100755 --- a/lib/markdown2.py +++ b/lib/markdown2.py @@ -3003,7 +3003,8 @@ def __init__(self, md, options): def sub(self, match: re.Match) -> str: syntax = match.group(1) - text: str = match.string[match.start(): match.end()] + # use match.regs because strong/em regex may include preceding text in the match as well + text: str = match.string[match.regs[1][0]: match.end()] if '_' in syntax: # if using _this_ syntax, hash it to avoid processing, but don't hash the contents incase of nested syntax text = text.replace(syntax, _hash_text(self.name + syntax)) diff --git a/test/tm-cases/code_friendly_issue646.html b/test/tm-cases/code_friendly_issue646.html new file mode 100644 index 00000000..5c8e0779 --- /dev/null +++ b/test/tm-cases/code_friendly_issue646.html @@ -0,0 +1 @@ +

A_B

diff --git a/test/tm-cases/code_friendly_issue646.opts b/test/tm-cases/code_friendly_issue646.opts new file mode 100644 index 00000000..245e9828 --- /dev/null +++ b/test/tm-cases/code_friendly_issue646.opts @@ -0,0 +1 @@ +{"extras":["code-friendly"]} \ No newline at end of file diff --git a/test/tm-cases/code_friendly_issue646.text b/test/tm-cases/code_friendly_issue646.text new file mode 100644 index 00000000..8f94c786 --- /dev/null +++ b/test/tm-cases/code_friendly_issue646.text @@ -0,0 +1 @@ +A_**B** \ No newline at end of file