Compare commits

..

2 Commits

Author SHA1 Message Date
99f89be39c
Resolve Org bookmark links on export
Replace bookmark links on export with their actual targets, as the bookmarks itself are of little
use in the final document.
2025-07-24 11:45:44 +02:00
cd90381ad0
Fix capitalization in docstring 2025-07-23 21:07:00 +02:00
2 changed files with 21 additions and 2 deletions

View File

@ -718,6 +718,7 @@ split horizontally again, but this extra work should not matter much."
org-password-manager-get-password-by-id
db/org-bookmark-open
db/org-bookmark-store-link
db/org-bookmark-export
db/org-lint-invalid-bookmark-link
db/org-lint-possible-bookmark-link))
@ -1016,7 +1017,8 @@ split horizontally again, but this extra work should not matter much."
number))))
(org-link-set-parameters "bookmark"
:follow #'db/org-bookmark-open
:store #'db/org-bookmark-store-link)
:store #'db/org-bookmark-store-link
:export #'db/org-bookmark-export)
(when (eq system-type 'windows-nt)
(org-link-set-parameters "onenote" :follow #'db/org-onenote-open)
(org-link-set-parameters "outlook" :follow #'db/org-outlook-open))

View File

@ -482,7 +482,7 @@ Via %%(with-temp-buffer (db/org-add-link-to-current-clock) (string-trim (buffer-
(defun db/find-parent-task ()
;; http://doc.norang.ca/org-mode.html#Clocking
"Return point of the nearest parent task, and NIL if no such task exists.
"Return point of the nearest parent task, and nil if no such task exists.
Ignores headlines tagged with NOP or PERIODIC, as those items
should not be clocked."
@ -2262,6 +2262,23 @@ PARAMS may contain the following values:
(org-link-store-props :link (concat "bookmark:" bookmark)
:description bookmark))))
(defun db/org-bookmark-export (path description backend)
"Export Org bookmark links by resolving them to their target path.
PATH denotes the bookmark name, while DESCRIPTION is the (optional)
description of that link. BACKEND denotes the target format for export."
(condition-case err
(let* ((bmk-target (or (bookmark-prop-get path 'location)
(bookmark-prop-get path 'filename)
(user-error "Cannot resolve bookmark for export: %s"
path))))
;; TODO: the following might be quite heavy, as it invokes the Org parser again. Maybe
;; exporting links can be done more easily?
(org-export-string-as (org-link-make-string bmk-target description)
backend))
(error (error "Error of type “%s” while exporting bookmark “%s”: “%s”"
(car err) path (cadr err)))))
(defun db/org-lint-invalid-bookmark-link (ast)
"Org lint checker to verify bookmark links in AST point to known bookmarks."
(bookmark-maybe-load-default-file)