aboutsummaryrefslogtreecommitdiff
path: root/sx-question-mode.el
diff options
context:
space:
mode:
Diffstat (limited to 'sx-question-mode.el')
-rw-r--r--sx-question-mode.el27
1 files changed, 24 insertions, 3 deletions
diff --git a/sx-question-mode.el b/sx-question-mode.el
index 3cc06b5..6dc8395 100644
--- a/sx-question-mode.el
+++ b/sx-question-mode.el
@@ -387,12 +387,34 @@ where `value' is given `face' as its face.
(goto-char (point-min))
(while (null (eobp))
;; Don't fill pre blocks.
- (unless (sx-question-mode--move-over-pre)
+ (unless (sx-question-mode--dont-fill-here)
(skip-chars-forward "\r\n[:blank:]")
(fill-paragraph)
(forward-paragraph)))
(buffer-string)))
+(defvar 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://...")
+
+(defun sx-question-mode--dont-fill-here ()
+ "If text shouldn't be filled here, return t and skip over it."
+ (or (sx-question-mode--move-over-pre)
+ ;; Skip headers and references
+ (let ((pos (point)))
+ (skip-chars-forward "\r\n[:blank:]")
+ (goto-char (line-beginning-position))
+ (if (or (looking-at-p (format sx-question-mode--reference-regexp ".+"))
+ (looking-at-p "^#"))
+ ;; Returns non-nil
+ (forward-paragraph)
+ ;; Go back and return nil
+ (goto-char pos)
+ nil))))
+
(defvar sx-question-mode--link-regexp
;; Done at compile time.
(rx "[" (group-n 1 (1+ (not (any "]")))) "]"
@@ -454,8 +476,7 @@ If ID is nil, use FALLBACK-ID instead."
(save-match-data
(goto-char (point-min))
(when (search-forward-regexp
- (format (rx line-start (0+ blank) "[%s]:" (0+ blank)
- (group-n 1 (1+ (not blank))))
+ (format sx-question-mode--reference-regexp
(or id fallback-id))
nil t)
(match-string-no-properties 1)))))