summaryrefslogtreecommitdiff
path: root/repo/www
diff options
context:
space:
mode:
authorKévin Le Gouguec <kevin.legouguec@gmail.com>2020-10-06 11:54:26 +0200
committerKévin Le Gouguec <kevin.legouguec@gmail.com>2020-10-06 11:54:26 +0200
commit64141744239182e60e2655e2ed24664461397e26 (patch)
tree8c312c2ae6d8c12caafcd61ed0855480091d8043 /repo/www
parent9dceda02d10adcabec2504da8e39cefa2e5b0336 (diff)
downloadmemory-leaks-64141744239182e60e2655e2ed24664461397e26.tar.xz
Split preprocessor into smaller functions
Diffstat (limited to 'repo/www')
-rw-r--r--repo/www/preprocess-org.el43
1 files changed, 25 insertions, 18 deletions
diff --git a/repo/www/preprocess-org.el b/repo/www/preprocess-org.el
index fda4476..4963326 100644
--- 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))))