[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/markdown-mode 1535b958a6 3/3: Merge pull request #763 from
|
From: |
ELPA Syncer |
|
Subject: |
[nongnu] elpa/markdown-mode 1535b958a6 3/3: Merge pull request #763 from jrblevin/issue-762 |
|
Date: |
Wed, 17 May 2023 03:02:02 -0400 (EDT) |
branch: elpa/markdown-mode
commit 1535b958a6f55a50a6991c700baa7ce44243c125
Merge: 5d98592fe5 44f0e89534
Author: Shohei YOSHIDA <syohex@gmail.com>
Commit: GitHub <noreply@github.com>
Merge pull request #763 from jrblevin/issue-762
Fix invalid inline link parsing if it has both description and title
---
CHANGES.md | 2 ++
markdown-mode.el | 22 +++++++++++-----------
tests/markdown-test.el | 8 ++++++++
3 files changed, 21 insertions(+), 11 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..00918a23d4 100644
--- a/markdown-mode.el
+++ b/markdown-mode.el
@@ -5734,7 +5734,7 @@ See also `markdown-mode-map'.")
(defun markdown-imenu-create-nested-index ()
"Create and return a nested imenu index alist for the current buffer.
See `imenu-create-index-function' and `imenu--index-alist' for details."
- (let* ((root '(nil . nil))
+ (let* ((root (list nil))
(min-level 9999)
hashes headers)
(save-excursion
@@ -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"