From cfbc79c5a569b4b2569b1d1edf1535edadd9bce4 Mon Sep 17 00:00:00 2001 From: Crozzers Date: Sun, 17 Dec 2023 14:37:41 +0000 Subject: [PATCH] Fix incorrect parsing of links after square brackets Links parser would identify the first square brackets as invalid link and then continue from after the entire link, which skipped the valid link right next to the brackets --- lib/markdown2.py | 3 ++- test/tm-cases/link_after_square_brackets.html | 3 +++ test/tm-cases/link_after_square_brackets.text | 3 +++ 3 files changed, 8 insertions(+), 1 deletion(-) create mode 100644 test/tm-cases/link_after_square_brackets.html create mode 100644 test/tm-cases/link_after_square_brackets.text diff --git a/lib/markdown2.py b/lib/markdown2.py index 34a270b3..c0db9874 100755 --- a/lib/markdown2.py +++ b/lib/markdown2.py @@ -1786,7 +1786,8 @@ def _do_links(self, text): curr_pos = start_idx + 1 else: # This id isn't defined, leave the markup alone. - curr_pos = match.end() + # set current pos to end of link title and continue from there + curr_pos = p continue # Otherwise, it isn't markup. diff --git a/test/tm-cases/link_after_square_brackets.html b/test/tm-cases/link_after_square_brackets.html new file mode 100644 index 00000000..a5421f3c --- /dev/null +++ b/test/tm-cases/link_after_square_brackets.html @@ -0,0 +1,3 @@ +

[before] +Some link +[after]

diff --git a/test/tm-cases/link_after_square_brackets.text b/test/tm-cases/link_after_square_brackets.text new file mode 100644 index 00000000..7c569d7b --- /dev/null +++ b/test/tm-cases/link_after_square_brackets.text @@ -0,0 +1,3 @@ +[before] +[Some link](https://google.com) +[after]