diff options
author | Yuchen Pei <id@ypei.org> | 2023-07-16 09:01:24 +1000 |
---|---|---|
committer | Yuchen Pei <id@ypei.org> | 2023-07-16 09:01:24 +1000 |
commit | 15ca70137ae47732fceae7bbb30f399f0d90c99e (patch) | |
tree | f719d8513b5295c29fd8bd4e969a6c461dc3560e | |
parent | 455b893d25923b18c5de7ec0d50d918677883a10 (diff) |
Fix ref rendering with ref counter and help echo
-rw-r--r-- | wiki-markup.el | 36 |
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." |