about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--config.org41
1 files changed, 41 insertions, 0 deletions
diff --git a/config.org b/config.org index 65dc47a..93e136d 100644 --- a/config.org +++ b/config.org
@@ -1488,6 +1488,47 @@ I’ve put org mode under Applications, as opposed to Writing, because it’s m
1488 (add-hook 'emacs-lisp-mode-hook #'org-link-minor-mode) 1488 (add-hook 'emacs-lisp-mode-hook #'org-link-minor-mode)
1489 #+end_src 1489 #+end_src
1490 1490
1491*** Useful HTML Anchors
1492
1493 #+begin_src emacs-lisp
1494 (defun my/ensure-headline-ids (&rest _)
1495 "Ensure better headlines for Org trees.
1496
1497 Use CUSTOM_ID property, or barring that, a \"fixed\" title.
1498
1499 All non-alphanumeric characters are cleverly replaced with ‘-’.
1500
1501 If multiple trees end-up with the same id property, issue a
1502 message and undo any property insertion thus far.
1503
1504 E.g., ↯ We'll go on a ∀∃⇅ adventure
1505 ↦ We'll-go-on-a-adventure
1506 "
1507 (interactive)
1508 (let ((ids))
1509 (org-map-entries
1510 (lambda ()
1511 (org-with-point-at (point)
1512 (let ((id (org-entry-get nil "CUSTOM_ID")))
1513 (unless id
1514 (thread-last (nth 4 (org-heading-components))
1515 (s-replace-regexp "[^[:alnum:]']" "-")
1516 (s-replace-regexp "-+" "-")
1517 (s-chop-prefix "-")
1518 (s-chop-suffix "-")
1519 (setq id))
1520 (if (not (member id ids))
1521 (push id ids)
1522 (message-box "Oh no, a repeated id!\n\n\t%s" id)
1523 (undo)
1524 (setq quit-flag t))
1525 (org-entry-put nil "CUSTOM_ID" id))))))))
1526
1527 ;; Whenever html & md export happens, ensure we have headline ids.
1528 (advice-add 'org-html-export-to-html :before 'my/ensure-headline-ids)
1529 (advice-add 'org-md-export-to-markdown :before 'my/ensure-headline-ids)
1530 #+end_src
1531
1491** Git 1532** Git
1492 1533
1493#+begin_src emacs-lisp 1534#+begin_src emacs-lisp