0

In the process of exporting Org files to html, I would like an org-protocol link in Org mode to export to html using the html export backend.

In my Org file, my org-protocol link is styled like this:

[[org-protocol://open-file?file=/Users/user/Download/test.org][Link to test file]]

org-protocol://open-file is a custom protocol as defined in this answer.

This should export to html like this:

<a href="org-protocol://open-file?file=/Users/user/Download/test.org">Link to test file</a>

When I test conversion to html using org-html-convert-region-to-html, I get the error Unable to resolve link: "org-protocol://open-file?file=/Users/user/Download/test.org".

System information: Emacs 27.2, Org mode 9.4.4, MacOS 12.2.1.

How can I export my org-protocol link to html?

2
  • Does the link in the Org file actrually work? If you click on it, does the file open? I get an error saying "No match for fuzzy expression: org-protocol://open...".
    – NickD
    Mar 19, 2022 at 5:09
  • It doesn't work in the org file, but the HTML code works in a webpage. I've tested org-protocol by putting the example HTML link in an HTML source block, which exports correctly and functions as expected. I guess I forgot to mention that org-protocol://open-file is a custom protocol, that I've defined using this answer. My initial asssumption was that getting org-protocol links to work properly in Org was a separate problem from exporting them to HTML, but it could be related.
    – jrasband
    Mar 19, 2022 at 21:45

1 Answer 1

0

The solution is to add org-protocol to org-link-parameters, as suggested by this solution and this solution.

Having this code in my init.el fixed my problem:

(org-link-set-parameters
 "org-protocol"
 :export (lambda (path desc backend)
       (cond
        ((eq 'html backend)
         (format "<a href=\"org-protocol:%s\">%s</a>" path desc)))))

It's likely that one could fix the error mentioned in NickD's comment by setting the :follow parameter for "org-protocol" in a similar way, but that's not related to the original question about exporting links.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.