commit 64141744239182e60e2655e2ed24664461397e26
parent 9dceda02d10adcabec2504da8e39cefa2e5b0336
Author: Kévin Le Gouguec <kevin.legouguec@gmail.com>
Date: Tue, 6 Oct 2020 11:54:26 +0200
Split preprocessor into smaller functions
Diffstat:
1 file changed, 25 insertions(+), 18 deletions(-)
diff --git a/repo/www/preprocess-org.el b/repo/www/preprocess-org.el
@@ -35,29 +35,36 @@
;; pandoc does not recognize, format some other stuff arbitrarily,
;; *then* I'll run pandoc on the result.
+(defun pp-org/list-tags ()
+ (goto-char (point-min))
+ (while (re-search-forward org-heading-regexp nil t)
+ (save-excursion
+ (save-match-data
+ (when-let ((tags (org-get-tags (point))))
+ (insert "\n#+begin_tags\n")
+ (dolist (tag tags)
+ (insert "- " tag "\n"))
+ (insert "#+end_tags\n"))))))
+
+(defun pp-org/expand-links ()
+ (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))))))
+
(defun preprocess-org (input)
(with-temp-buffer
(insert "#+OPTIONS: ^:{} tags:nil\n")
(insert-file-contents input)
(org-mode)
- (while (re-search-forward org-heading-regexp nil t)
- (save-excursion
- (save-match-data
- (when-let ((tags (org-get-tags (point))))
- (insert "\n#+begin_tags\n")
- (dolist (tag tags)
- (insert "- " tag "\n"))
- (insert "#+end_tags\n")))))
;; TODO: dump properties
;; TODO: fontify TODO keywords
- (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)))))
+ (pp-org/list-tags)
+ (pp-org/expand-links)
(princ (buffer-string))))