emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[nongnu] elpa/markdown-mode 0a6a8d8593 2/3: Support links wrapped with a


From: ELPA Syncer
Subject: [nongnu] elpa/markdown-mode 0a6a8d8593 2/3: Support links wrapped with angle brackets
Date: Mon, 2 Oct 2023 04:00:59 -0400 (EDT)

branch: elpa/markdown-mode
commit 0a6a8d85934f8a8d289c43316a07b179498d9ac1
Author: Shohei YOSHIDA <syohex@gmail.com>
Commit: Shohei YOSHIDA <syohex@gmail.com>

    Support links wrapped with angle brackets
---
 markdown-mode.el       | 11 +++++++----
 tests/markdown-test.el |  8 ++++++++
 2 files changed, 15 insertions(+), 4 deletions(-)

diff --git a/markdown-mode.el b/markdown-mode.el
index 284fc411ce..0cf1b54556 100644
--- a/markdown-mode.el
+++ b/markdown-mode.el
@@ -7855,10 +7855,13 @@ Value is a list of elements describing 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))))
+          ;; A link can contain spaces if it is wrapped with angle brackets
+          (cond ((string-match "\\`<\\(.+\\)>\\'" destination-part)
+                 (setq url (match-string-no-properties 1 destination-part)))
+                ((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)))
+                (t (setq url destination-part)))))
        ;; Reference link at point.
        ((thing-at-point-looking-at markdown-regex-link-reference)
         (setq bang (match-string-no-properties 1)
diff --git a/tests/markdown-test.el b/tests/markdown-test.el
index 10b89ae2ed..c8213d82f7 100644
--- a/tests/markdown-test.el
+++ b/tests/markdown-test.el
@@ -5366,6 +5366,14 @@ Detail: 
https://github.com/jrblevin/markdown-mode/issues/430";
   (markdown-test-string "![text](url \"title\")"
     (should (equal (markdown-link-at-pos (point)) '(1 21 "text" "url" nil 
"title" "!")))))
 
+(ert-deftest test-markdown-link/inline-link-with-brackets ()
+  "Test `markdown-link-at-pos' return values with .
+Details: https://github.com/jrblevin/markdown-mode/issues/800
+
+A link can contain spaces if it is wrapped with angle brackets"
+  (markdown-test-string "[text](<file name has space>)"
+    (should (equal (markdown-link-at-pos (point)) '(1 30 "text" "file name has 
space" nil nil nil)))))
+
 (ert-deftest test-markdown-link/reference-link-at-pos ()
   "Test `markdown-link-at-pos' return values with a reference link."
   (markdown-test-string "[text][ref]"



reply via email to

[Prev in Thread] Current Thread [Next in Thread]