aboutsummaryrefslogtreecommitdiff
path: root/wiki-markup.el
diff options
context:
space:
mode:
authorYuchen Pei <id@ypei.org>2023-07-16 09:01:24 +1000
committerYuchen Pei <id@ypei.org>2023-07-16 09:01:24 +1000
commit15ca70137ae47732fceae7bbb30f399f0d90c99e (patch)
treef719d8513b5295c29fd8bd4e969a6c461dc3560e /wiki-markup.el
parent455b893d25923b18c5de7ec0d50d918677883a10 (diff)
Fix ref rendering with ref counter and help echo
Diffstat (limited to 'wiki-markup.el')
-rw-r--r--wiki-markup.el36
1 files changed, 22 insertions, 14 deletions
diff --git a/wiki-markup.el b/wiki-markup.el
index f6543b5..dfc9cfb 100644
--- a/wiki-markup.el
+++ b/wiki-markup.el
@@ -103,20 +103,28 @@ This can be overriden with .dir-locals.el."
6)))
(defun wiki-do-refs (limit)
- (while (re-search-forward "<ref\\([^>]*\\)>" limit t)
- (let ((start (match-beginning 0))
- (end (if (string-suffix-p "/" (match-string 1))
- (match-end 0)
- (when (search-forward "</ref>" limit t)
- (match-end 0))))
- (next-start (save-excursion
- (when (re-search-forward "<ref[^>/]*>" limit t)
- (match-beginning 0)))))
- (cond ((not end) (goto-char limit))
- ((or (not next-start) (>= next-start end))
- (put-text-property start end 'display ";)")
- (goto-char end))
- (t (goto-char next-start))))))
+ (let ((ref-counter 0))
+ (while (re-search-forward "<ref\\([^>]*\\)>" limit t)
+ (let ((start (match-beginning 0))
+ (end (if (string-suffix-p "/" (match-string 1))
+ (match-end 0)
+ (when (search-forward "</ref>" limit t)
+ (match-end 0))))
+ (next-start (save-excursion
+ (when (re-search-forward "<ref[^>/]*>" limit t)
+ (match-beginning 0)))))
+ (cond ((not end) (goto-char limit))
+ ((or (not next-start) (>= next-start end))
+ (setq ref-counter (1+ ref-counter))
+ (let ((original-text
+ (buffer-substring-no-properties start end)))
+ (put-text-property start end
+ 'display (format "[%d]" ref-counter))
+ (put-text-property start end
+ 'help-echo original-text))
+ (add-face-text-property start end 'org-link)
+ (goto-char end))
+ (t (goto-char next-start)))))))
(defun wiki-set-template-face (limit)
"Set template faces."