ebib
ebib copied to clipboard
Export HTML links
When exporting org-mode files to HTML, it would be nice if we could export the ebib links as links to actual papers or to the webpages of those papers. I have cooked this option as an :around advice for org-html-link, the function that exports links. Is there a better solution? Could this be part of ebib?
(defun jjgr-ebib-export-link-as-doi (orig-fun link desc info)
(let ((output nil))
(when (string= (org-element-property :type link) "ebib")
(let ((path (org-element-property :path link)))
(save-match-data
(string-match "^\\(.*?\\)\\(?:@\\(.*?\\)\\)?$" path)
(let* ((key (match-string 1 path))
(db-name (match-string 2 path))
(db (if db-name
(ebib--load-bibtex-file-internal
(ebib--locate-bibfile
db-name
(append ebib-bib-search-dirs
(list default-directory))))
(ebib--find-db-for-key key ebib--cur-db))))
(when db
(let* ((urls (ebib-get-field-value
ebib-url-field key db 'noerror 'unbraced 'xref))
(url (and urls (car (ebib--split-urls urls)))))
(when url
(setq output (format "<a href=\"%s\">%s</a>"
url
(or desc (format "[%s]" key)))))))))))
(if output
output
(funcall orig-fun link desc info))))
(advice-add 'org-html-link :around 'jjgr-ebib-export-link-as-doi)
When exporting org-mode files to HTML, it would be nice if we could export the ebib links as links to actual papers or to the webpages of those papers.
That would definitely be nice. :smiley:
I have cooked this option as an :around advice for org-html-link, the function that exports links. Is there a better solution? Could this be part of ebib?
There is a better solution, in fact, there's a canonical solution. When defining the link with org-link-set-parameters
(which happens in org-ebib.el
), there should be an :export
property that tells Org which function to use for exporting the link.
There's an example of such an :export
function in the Org manual here. If you feel up to it, feel free to create a PR. Otherwise, I'll try and find some time in the coming weeks.