aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSean Allred <code@seanallred.com>2015-01-07 20:00:01 -0500
committerSean Allred <code@seanallred.com>2015-01-07 20:00:01 -0500
commitab8ac65a7e22874cc4a56863e5aa9442c12cd0ae (patch)
tree6b853a0389206dacbb90e41ca361f2eb56efa701
parented5d64fb5ccc726444c824c2fb2ba6d7e81a1abf (diff)
parent9344809abe4b6b1b73038bd02b466900f1340bc3 (diff)
Merge pull request #218 from vermiculus/fix-plain-links
Fix plain links
-rw-r--r--sx-question-print.el17
1 files changed, 11 insertions, 6 deletions
diff --git a/sx-question-print.el b/sx-question-print.el
index 1e25d67..f6cd1dc 100644
--- a/sx-question-print.el
+++ b/sx-question-print.el
@@ -322,18 +322,22 @@ where `value' is given `face' as its face.
'face 'markdown-list-face)
"String to be displayed as the bullet of markdown list items.")
-(defvar sx-question-mode--reference-regexp
+(defconst sx-question-mode--reference-regexp
(rx line-start (0+ blank) "[%s]:" (0+ blank)
(group-n 1 (1+ (not blank))))
"Regexp used to find the url of labeled links.
E.g.:
[1]: https://...")
-(defvar sx-question-mode--link-regexp
+(defconst sx-question-mode--link-regexp
;; Done at compile time.
- (rx "[" (group-n 1 (1+ (not (any "]")))) "]"
- (or (and "(" (group-n 2 (1+ (not (any ")")))) ")")
- (and "[" (group-n 3 (1+ (not (any "]")))) "]")))
+ (rx (or (and "[" (group-n 1 (1+ (not (any "]")))) "]"
+ (or (and "(" (group-n 2 (1+ (not (any ")")))) ")")
+ (and "[" (group-n 3 (1+ (not (any "]")))) "]")))
+ (group-n 4 (and (or (and "http" (opt "s") "://") "")
+ (+ (any alnum "_%"))
+ "."
+ (+ (any alnum "/._%&#?=;"))))))
"Regexp matching markdown links.")
(defun sx-question-mode--fill-and-fontify (text)
@@ -377,6 +381,7 @@ E.g.:
(while (search-forward-regexp sx-question-mode--link-regexp nil t)
(let* ((text (match-string-no-properties 1))
(url (or (match-string-no-properties 2)
+ (match-string-no-properties 4)
(sx-question-mode-find-reference
(match-string-no-properties 3)
text)))
@@ -384,7 +389,7 @@ E.g.:
(when (stringp url)
(replace-match "")
(sx-question-mode--insert-link
- (if sx-question-mode-pretty-links text full-text)
+ (or (if sx-question-mode-pretty-links text full-text) url)
url))))))
(defun sx-question-mode--insert-link (text url)