If I have an org-mode buffer like that looks like:
* My headline :PROPERTIES: :ID: id1 :END: * My second headline :PROPERTIES: :ID: id2 :END:
And I export this to HTML with a table-of-contents, the table of contents uses
#sec-2 as the anchor links for each headline.
I would like it to automatically use
#ID-id2 so that I can change the order of the headlines without changing where the links point to. Is there a way to tell org-mode to export the table of contents using these anchors instead?
EDIT As Jonathan suggested below, I have created a custom function to use
:CUSTOM_ID: instead, here is my setup in case others find it useful:
(defun my/org-custom-id-get (&optional pom create prefix) "Get the CUSTOM_ID property of the entry at point-or-marker POM. If POM is nil, refer to the entry at point. If the entry does not have an CUSTOM_ID, the function returns nil. However, when CREATE is non nil, create a CUSTOM_ID if none is present already. PREFIX will be passed through to `org-id-new'. In any case, the CUSTOM_ID of the entry is returned." (interactive) (org-with-point-at pom (let ((id (org-entry-get nil "CUSTOM_ID"))) (cond ((and id (stringp id) (string-match "\\S-" id)) id) (create (setq id (org-id-new prefix)) (org-entry-put pom "CUSTOM_ID" id) (org-id-add-location id (buffer-file-name (buffer-base-buffer))) id))))) (defun my/org-add-ids-to-headlines-in-file () "Add CUSTOM_ID properties to all headlines in the current file which do not already have one." (interactive) (org-map-entries (lambda () (my/org-custom-id-get (point) 'create)))) ;; automatically add ids to captured headlines (add-hook 'org-capture-prepare-finalize-hook (lambda () (my/org-custom-id-get (point) 'create)))))
Which I can then use the
my/org-add-ids-to-headlines-in-file function to add
:CUSTOM_ID: properties to each headline in a file.