[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/markdown-mode cdac22a7cf 1/3: Fix invalid inline link pars
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/markdown-mode cdac22a7cf 1/3: Fix invalid inline link parsing if it has both description and title |
Date: |
Wed, 17 May 2023 03:02:02 -0400 (EDT) |
branch: elpa/markdown-mode
commit cdac22a7cf97609d8b09a3525d78f056eae8e08f
Author: Shohei YOSHIDA <syohex@gmail.com>
Commit: Shohei YOSHIDA <syohex@gmail.com>
Fix invalid inline link parsing if it has both description and title
---
CHANGES.md | 2 ++
markdown-mode.el | 20 ++++++++++----------
tests/markdown-test.el | 8 ++++++++
3 files changed, 20 insertions(+), 10 deletions(-)
diff --git a/CHANGES.md b/CHANGES.md
index d8225299d2..e554571a49 100644
--- a/CHANGES.md
+++ b/CHANGES.md
@@ -30,6 +30,7 @@
- Fix to mistake to handle the line as delimiter row[GH-747][]
- Fix wrong displaying horizontal rule in `markdown-view-mode` [GH-747][]
- HTML-escape title in `markdown-add-xhtml-header-and-footer`
[markdown-xwidget-issue-9](https://github.com/cfclrk/markdown-xwidget/issues/9)
+ - Fix wrong inline link parsing that has link title[GH-762][]
[gh-377]: https://github.com/jrblevin/markdown-mode/issues/377
[gh-572]: https://github.com/jrblevin/markdown-mode/issues/572
@@ -41,6 +42,7 @@
[gh-743]: https://github.com/jrblevin/markdown-mode/issues/743
[gh-747]: https://github.com/jrblevin/markdown-mode/issues/747
[gh-753]: https://github.com/jrblevin/markdown-mode/issues/753
+ [gh-762]: https://github.com/jrblevin/markdown-mode/issues/762
# Markdown Mode 2.5
diff --git a/markdown-mode.el b/markdown-mode.el
index 317ec76d8b..3021ca9975 100644
--- a/markdown-mode.el
+++ b/markdown-mode.el
@@ -7798,19 +7798,19 @@ Value is a list of elements describing the link:
((thing-at-point-looking-at markdown-regex-link-inline)
(setq bang (match-string-no-properties 1)
begin (match-beginning 0)
- end (match-end 0)
text (match-string-no-properties 3)
url (match-string-no-properties 6))
- (if (match-end 7)
- (setq title (substring (match-string-no-properties 7) 1 -1))
- ;; #408 URL contains close parenthesis case
- (goto-char (match-beginning 5))
- (let ((paren-end (scan-sexps (point) 1)))
- (when (and paren-end (< end paren-end))
- (setq url (buffer-substring (match-beginning 6) (1-
paren-end)))))))
+ ;; consider nested parentheses
+ ;; if link target contains parentheses, (match-end 0) isn't correct
end position of the link
+ (let* ((close-pos (scan-sexps (match-beginning 5) 1))
+ (destination-part (string-trim (buffer-substring-no-properties
(1+ (match-beginning 5)) (1- close-pos)))))
+ (setq end close-pos)
+ (if (string-match "\\([^ ]+\\)\\s-+\\(.+\\)" destination-part)
+ (setq url (match-string-no-properties 1 destination-part)
+ title (substring (match-string-no-properties 2
destination-part) 1 -1))
+ (setq url destination-part))))
;; Reference link at point.
- ((or (thing-at-point-looking-at markdown-regex-link-inline)
- (thing-at-point-looking-at markdown-regex-link-reference))
+ ((thing-at-point-looking-at markdown-regex-link-reference)
(setq bang (match-string-no-properties 1)
begin (match-beginning 0)
end (match-end 0)
diff --git a/tests/markdown-test.el b/tests/markdown-test.el
index 8e4773f4f1..000974653e 100644
--- a/tests/markdown-test.el
+++ b/tests/markdown-test.el
@@ -5330,6 +5330,14 @@ Detail:
https://github.com/jrblevin/markdown-mode/issues/408"
(let ((link (markdown-link-at-pos (point))))
(should (string= (nth 3 link) url))))))
+(ert-deftest test-markdown-link/link-contains-parenthesis-and-label ()
+ "Test URL which contains close parenthesis.
+Detail: https://github.com/jrblevin/markdown-mode/issues/762"
+ (markdown-test-string ".png \"label\")"
+ (let ((link (markdown-link-at-pos (point))))
+ (should (string= (nth 3 link) "url(par).png"))
+ (should (string= (nth 5 link) "label")))))
+
(ert-deftest test-markdown-link/start-or-end-with-spaces ()
"Test `markdown-link-at-pos' return values with URL part starts/ends with
spaces.
Detail: https://github.com/jrblevin/markdown-mode/issues/514"