From cfbc79c5a569b4b2569b1d1edf1535edadd9bce4 Mon Sep 17 00:00:00 2001 From: Crozzers Date: Sun, 17 Dec 2023 14:37:41 +0000 Subject: [PATCH 1/2] 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] From 2fb92a93b2dccfdcedb6ca68e646d190e15c46d2 Mon Sep 17 00:00:00 2001 From: Crozzers Date: Sun, 17 Dec 2023 15:37:59 +0000 Subject: [PATCH 2/2] Update changelog --- CHANGES.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGES.md b/CHANGES.md index 9a5ac73e..fd70e0cf 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -5,6 +5,7 @@ - [pull #547] Update `markdown-in-html` extra to handle markdown on same line as HTML (#546) - [pull #550] Fix tables with trailing whitespace not being recognized (#549) - [pull #545] Fix multiple instances of strong emphasis (`**`) in one line (#541) +- [pull #556] Fix incorrect parsing of links after square brackets (#552) ## python-markdown2 2.4.11