Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Patching Ox-html to support ID export
(defun org-html--reference (datum info &optional named-only)
"Return an appropriate reference for DATUM.
DATUM is an element or a `target' type object. INFO is the
current export state, as a plist.
When NAMED-ONLY is non-nil and DATUM has no NAME keyword, return
nil. This doesn't apply to headlines, inline tasks, radio
targets and targets."
(let* ((type (org-element-type datum))
(user-label
(org-element-property
(pcase type
((or `headline `inlinetask) :CUSTOM_ID)
((or `radio-target `target) :value)
(_ :name))
datum))
(user-label (or user-label
(when-let ((path (org-element-property :ID datum)))
(concat "ID-" path)))))
(cond
((and user-label
(or (plist-get info :html-prefer-user-labels)
;; Used CUSTOM_ID property unconditionally.
(memq type '(headline inlinetask))))
user-label)
((and named-only
(not (memq type '(headline inlinetask radio-target target)))
(not user-label))
nil)
(t
(org-export-get-reference datum info)))))
@chatziiola
Copy link

chatziiola commented Oct 15, 2021

Hey, I'm sorry to bother you but that gist no longer seems to work. I've checked that this function is being run instead of the default one in ox-html, yet org-publish doesn't parse my ID links correctly. Should I look somewhere else?

P.S I've already checked your braindump project, as well as the other sites that are mentioned, but i want something simpler, and thought that by posting this here others could benefit from it too. I should, also, mention that I haven't much experience with elisp. I read the short introduction manual that comes with emacs but my experience is, obviously, limited.

@savolla
Copy link

savolla commented Aug 8, 2022

this does not work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment