org-export unable to resolve link; is it possible?
poulpoulsen opened this issue · 9 comments
hello,
i tried to export a zk file with links using the org-exporter.
unfortunately i'm not able to do that.
it seems, that org cannot resolve the zk-link.
i tried to use your provided function to change
(defun zk-org-try-to-follow-link (fn &optional arg) "When 'org-open-at-point' FN fails, try 'zk-follow-link-at-point'. Optional ARG." (let ((org-link-search-must-match-exact-headline t)) (condition-case nil (apply fn arg) (error (zk-follow-link-at-point))))) (advice-add 'org-open-at-point :around #'zk-org-try-to-follow-link)
but without luck.
any idea?
or is it impossible?
Regards
Poul
Hi, the short answer is no, org can't resolve links because they are not org-links. The function you reference is simply a workaround for following links.
There has been some work on more complete org integration here #8 , but it's not something that I have worked on.
hello,
this is a sad answer :-(
for me it is important, to export and/or convert org files.
without the working links i can't do that.
Or am i wrong?
You can set the variable org-export-with-broken-links
to t
or mark
.
When set to t
, the file will export, just without exporting the links. That is, the ID numbers will be absent from the exported file.
When set to mark
the file will export, and all links will be prefaced by the text "BROKEN LINK:". Not ideal, but at least it exports?
I'm not familiar enough with org-export to know if its possible to advise the export function to deal specially with certain kinds of broken links.
Out of curiosity, what format(s) are you typically exporting to?
Here's a little hack that might help you out, if no other solution comes to the surface.
Basically, it's a filter that transforms the "BROKEN LINK: ID" output (when org-export-with-broken-links
is set to 'mark
) into valid HTML link format. But it could be altered to transform into useful output for any org-export backend (theoretically).
(setq org-export-with-broken-links 'mark)
(defun zk-org-link-filter (data backend _info)
(cond
((and (eq 'html backend)
(string-match
(concat "\\[BROKEN LINK: \\(?:" zk-id-regexp "\\)")
data))
(let* ((id (match-string 1 data))
(file (zk--parse-id 'file-path id)))
(format "<a href=\"%s\">%s</a>" file id)))))
(add-to-list 'org-export-filter-link-functions 'zk-org-link-filter)
hello,
i tested your hack and with html export it works. Thank you.
Usually i export to pdf, odt or via pandoc.
is this hack possible for pdf or the other ones?
thank you!
Poul
The filter is essentially a find-and-replace function, to render the file-path and description in the proper format. So, you if you know the proper format for a backend, you can just add conditionals to the zk-link-filter
that will perform the right transformation. Transformations for some backends might be more complex than others.
Here's an example that includes html, as above, and latex. I'm not sure what the plaintext output for ODT links is, or I would have attempted it here. And I can't help with pandoc I'm afraid.
(defun zk-link-filter (data backend _info)
(when (string-match
(concat "\\[BROKEN LINK: \\(?:" zk-id-regexp "\\)")
data)
(let* ((id (match-string 1 data))
(file (org-export-file-uri
(zk--parse-id 'file-path id))))
(cond
((eq 'html backend)
(format "<a href=\"%s\">%s</a>" file id))
((eq 'latex backend)
(progn
(setq file
(replace-regexp-in-string
"{"
"\\\\{"
(replace-regexp-in-string
"}"
"\\\\}"
file)))
(format "\\href{%s}{%s}" file id)))))))
hello,
and yes for pdf creation and html it works now.
for odt and pandoc i have to study your code and to understand.
Regards
Poul
Org exports are now (theoretically) possible with org-link support provided in zk-org-link.el
This requires replacing all zk-style links [[202012101234]] with org-style links [[zk:202012101234]]. (This can be done with a macro, but be careful... :) )
I have done only minimal testing of the org-link support, so feedback welcome/appreciated.