Skip to content

Commit

Permalink
Support links wrapped with angle brackets
Browse files Browse the repository at this point in the history
  • Loading branch information
syohex committed Oct 2, 2023
1 parent 7cb16b9 commit 0a6a8d8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
11 changes: 7 additions & 4 deletions markdown-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 8 additions & 0 deletions tests/markdown-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -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]"
Expand Down

0 comments on commit 0a6a8d8

Please sign in to comment.