aboutsummaryrefslogtreecommitdiff
path: root/sx-question-print.el
diff options
context:
space:
mode:
Diffstat (limited to 'sx-question-print.el')
-rw-r--r--sx-question-print.el67
1 files changed, 39 insertions, 28 deletions
diff --git a/sx-question-print.el b/sx-question-print.el
index 3e9db59..70ce139 100644
--- a/sx-question-print.el
+++ b/sx-question-print.el
@@ -126,7 +126,9 @@ the editor's name."
:group 'sx-question-mode)
(defcustom sx-question-mode-separator
- (concat (make-string 80 ?_) "\n")
+ (concat (propertize (make-string 72 ?\s)
+ 'face '(underline sx-question-mode-header))
+ "\n")
"Separator used between header and body."
:type 'string
:group 'sx-question-mode)
@@ -329,16 +331,12 @@ DATA can represent a question or an answer."
(sx-tag--format-tags .tags .site_par)
nil))
;; Body
- (insert "\n"
- (propertize sx-question-mode-separator
- 'face 'sx-question-mode-header))
+ (insert "\n" sx-question-mode-separator)
(sx--wrap-in-overlay
'(face sx-question-mode-content-face)
(insert "\n")
(sx-question-mode--insert-markdown .body_markdown)
- (insert "\n"
- (propertize sx-question-mode-separator
- 'face 'sx-question-mode-header)))
+ (insert "\n" sx-question-mode-separator))
;; Clean up commments manually deleted. The `append' call is
;; to ensure `comments' is a list and not a vector.
(let ((comments (cl-remove-if #'sx--deleted-p .comments)))
@@ -433,10 +431,11 @@ E.g.:
(and (opt "!") "[" (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 (and "http" (opt "s") "://") ""
+ (group-n 4 (and "http" (opt "s") "://"
(>= 2 (any lower numeric "_%"))
"."
- (>= 2 (any lower numeric "/._%&#?=;"))))))
+ (>= 2 (any lower numeric "_%"))
+ (* (any lower numeric "-/._%&#?=;"))))))
"Regexp matching markdown links.")
(defun sx-question-mode--process-markdown-in-region (beg end)
@@ -447,24 +446,24 @@ font-locks code-blocks according to mode."
;; Paragraph filling
(let ((paragraph-start
"\f\\|[ \t]*$\\|[ \t]*[*+-] \\|[ \t]*[0-9]+\\.[ \t]\\|[ \t]*: ")
- (paragraph-separate "\\(?:[ \t\f]*\\|.* \\)$")
+ (paragraph-separate "\\(?:[ \t\f]*\\|.* \\)$")
(adaptive-fill-first-line-regexp "\\`[ \t]*>[ \t]*?\\'")
(adaptive-fill-function #'markdown-adaptive-fill-function))
(save-restriction
- (save-excursion
- (narrow-to-region beg end)
- ;; Compact links.
- (sx-question-mode--process-links-in-buffer)
- (sx-question-mode--process-html-tags (point-min) (point-max))
- ;; And now the filling and other handlings.
- (goto-char (point-min))
- (while (null (eobp))
- ;; Don't fill pre blocks.
- (unless (sx-question-mode--dont-fill-here)
- (let ((beg (point)))
- (skip-chars-forward "\r\n[:blank:]")
- (forward-paragraph)
- (fill-region beg (point)))))))))
+ (narrow-to-region beg end)
+ ;; Compact links.
+ (sx-question-mode--process-links-in-buffer)
+ (sx-question-mode--process-html-tags (point-min) (point-max))
+ ;; And now the filling and other handlings.
+ (goto-char (point-min))
+ (while (null (eobp))
+ ;; Don't fill pre blocks.
+ (unless (sx-question-mode--dont-fill-here)
+ (let ((beg (point)))
+ (skip-chars-forward "\r\n[:blank:]")
+ (forward-paragraph)
+ (fill-region beg (point)))))
+ (goto-char (point-max)))))
(defun sx-question-mode--insert-markdown (text)
"Return TEXT fontified according to `markdown-mode'."
@@ -474,6 +473,15 @@ font-locks code-blocks according to mode."
;; affects the entire buffer even if we narrow.
(with-temp-buffer
(insert text)
+ ;; Trim whitespace
+ (goto-char (point-max))
+ (skip-chars-backward "\r\n[:blank:]")
+ (delete-region (point) (point-max))
+ (goto-char (point-min))
+ (skip-chars-forward "\r\n[:blank:]")
+ (forward-line 0)
+ (delete-region (point-min) (point))
+ ;; Font lock
(delay-mode-hooks (markdown-mode))
(font-lock-mode -1)
(when sx-question-mode-bullet-appearance
@@ -562,9 +570,10 @@ Image links are downloaded and displayed, if
(when (stringp url)
(replace-match "")
(sx-question-mode--insert-link
- (unless image-p
- (or (if sx-question-mode-pretty-links text full-text)
- url))
+ (cond (image-p nil)
+ ((and sx-question-mode-pretty-links text))
+ ((not text) (sx--shorten-url url))
+ (t full-text))
url)
(when image-p
(sx-question-mode--create-image url (- (point) 2))))))))))
@@ -606,7 +615,9 @@ URL is used as 'help-echo and 'url properties."
;; Mouse-over
'help-echo
(format sx-button--link-help-echo
- (propertize (sx--shorten-url url)
+ ;; If TEXT is a shortened url, we don't shorten URL.
+ (propertize (if (string-match "^https?:" (or text ""))
+ url (sx--shorten-url url))
'face 'font-lock-function-name-face))
;; For visiting and stuff.
'sx-button-url url