From 9dceda02d10adcabec2504da8e39cefa2e5b0336 Mon Sep 17 00:00:00 2001 From: Kévin Le Gouguec Date: Tue, 6 Oct 2020 11:00:24 +0200 Subject: Handle link abbreviations --- repo/www/preprocess-org.el | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'repo') diff --git a/repo/www/preprocess-org.el b/repo/www/preprocess-org.el index bad9f90..fda4476 100644 --- a/repo/www/preprocess-org.el +++ b/repo/www/preprocess-org.el @@ -1,3 +1,5 @@ +;; -*- lexical-binding: t -*- + ;; How I Convert Org Files To HTML. ;; ================================ ;; @@ -48,5 +50,14 @@ (insert "#+end_tags\n"))))) ;; TODO: dump properties ;; TODO: fontify TODO keywords - ;; TODO: expand #+LINK abbreviations + (pcase-dolist (`(,key . ,expansion) org-link-abbrev-alist-local) + (goto-char (point-min)) + (let ((link-re (rx "[[" (group (literal key) ":" + (group (+ (not "]")))))) + (replacement (if (string-match-p "%s" expansion) + (lambda (tag) (format expansion tag)) + (lambda (tag) (concat expansion tag))))) + (while (re-search-forward link-re nil t) + (let ((full-link (funcall replacement (match-string 2)))) + (replace-match full-link t t nil 1))))) (princ (buffer-string)))) -- cgit v1.2.3