From 8f2315888ea4294df11905b5308b200bf1b2d0f1 Mon Sep 17 00:00:00 2001 From: Crozzers Date: Mon, 2 Mar 2026 20:31:45 +0000 Subject: [PATCH] Fix #680 --- lib/markdown2.py | 5 ++--- test/tm-cases/reference_link_lookalike_issue680.html | 1 + test/tm-cases/reference_link_lookalike_issue680.text | 1 + 3 files changed, 4 insertions(+), 3 deletions(-) create mode 100644 test/tm-cases/reference_link_lookalike_issue680.html create mode 100644 test/tm-cases/reference_link_lookalike_issue680.text diff --git a/lib/markdown2.py b/lib/markdown2.py index 9b693530..16e5d50f 100755 --- a/lib/markdown2.py +++ b/lib/markdown2.py @@ -1460,7 +1460,7 @@ def _sanitize_html(self, s: str) -> str: [ ]? # one optional space (?:\n[ ]*)? # one optional newline followed by spaces \[ - (?P.*?) + (?P[^\[\]]*?) \] ''', re.X | re.S) @@ -3179,7 +3179,6 @@ def run(self, text: str): start_idx = text.index('[', curr_pos) except ValueError: break - text_length = len(text) # Find the matching closing ']'. # Markdown.pl allows *matching* brackets in link text so we @@ -3190,7 +3189,7 @@ def run(self, text: str): for p in range( start_idx + 1, - min(start_idx + MAX_LINK_TEXT_SENTINEL, text_length) + min(start_idx + MAX_LINK_TEXT_SENTINEL, len(text)) ): ch = text[p] if ch == ']': diff --git a/test/tm-cases/reference_link_lookalike_issue680.html b/test/tm-cases/reference_link_lookalike_issue680.html new file mode 100644 index 00000000..182d8906 --- /dev/null +++ b/test/tm-cases/reference_link_lookalike_issue680.html @@ -0,0 +1 @@ +

[A] [B]

diff --git a/test/tm-cases/reference_link_lookalike_issue680.text b/test/tm-cases/reference_link_lookalike_issue680.text new file mode 100644 index 00000000..ad07eb9d --- /dev/null +++ b/test/tm-cases/reference_link_lookalike_issue680.text @@ -0,0 +1 @@ +[[A](http://a.com)] [[B](http://b.com)] \ No newline at end of file