|
38 | 38 | (require 'thingatpt) |
39 | 39 | (require 'cl-lib) |
40 | 40 | (require 'url-parse) |
| 41 | +(require 'url-util) |
41 | 42 | (require 'button) |
42 | 43 | (require 'color) |
43 | 44 | (require 'rx) |
@@ -8167,6 +8168,27 @@ See `markdown-wiki-link-p' for more information." |
8167 | 8168 | (thing-at-point-looking-at markdown-regex-uri) |
8168 | 8169 | (thing-at-point-looking-at markdown-regex-angle-uri)))))) |
8169 | 8170 |
|
| 8171 | +(defun markdown--unhex-url-string (url) |
| 8172 | + "Unhex control characters and spaces in URL. |
| 8173 | +This is similar to `url-unhex-string' but this doesn't unhex all percent-encoded |
| 8174 | +characters." |
| 8175 | + (let ((str (or url "")) |
| 8176 | + (tmp "") |
| 8177 | + (case-fold-search t)) |
| 8178 | + (while (string-match "%\\([01][0-9a-f]\\|20\\)" str) |
| 8179 | + (let* ((start (match-beginning 0)) |
| 8180 | + (ch1 (url-unhex (elt str (+ start 1)))) |
| 8181 | + (code (+ (* 16 ch1) |
| 8182 | + (url-unhex (elt str (+ start 2)))))) |
| 8183 | + (setq tmp (concat |
| 8184 | + tmp (substring str 0 start) |
| 8185 | + (cond |
| 8186 | + ((or (= code ?\n) (= code ?\r)) |
| 8187 | + " ") |
| 8188 | + (t (byte-to-string code)))) |
| 8189 | + str (substring str (match-end 0))))) |
| 8190 | + (concat tmp str))) |
| 8191 | + |
8170 | 8192 | (defun markdown-link-at-pos (pos) |
8171 | 8193 | "Return properties of link or image at position POS. |
8172 | 8194 | Value is a list of elements describing the link: |
@@ -8202,7 +8224,7 @@ Value is a list of elements describing the link: |
8202 | 8224 | (setq url (match-string-no-properties 1 destination-part) |
8203 | 8225 | title (substring (match-string-no-properties 2 destination-part) 1 -1))) |
8204 | 8226 | (t (setq url destination-part))) |
8205 | | - (setq url (url-unhex-string url)))) |
| 8227 | + (setq url (markdown--unhex-url-string url)))) |
8206 | 8228 | ;; Reference link at point. |
8207 | 8229 | ((thing-at-point-looking-at markdown-regex-link-reference) |
8208 | 8230 | (setq bang (match-string-no-properties 1) |
|
0 commit comments