kaushalmodi / ox-hugo

A carefully crafted Org exporter back-end for Hugo
https://ox-hugo.scripter.co
GNU General Public License v3.0
867 stars 130 forks source link

Add support for user-defined processing of links #720

Open krisbalintona opened 11 months ago

krisbalintona commented 11 months ago

Would it be reasonable to allow users to create their own functions to transform org link types into markdown links? For instance, if the user (or a package that the user uses) creates their own org link type, this feature would allow the user to control what ox-hugo does with the link.

In my case, I use Denote. Denote defines denote links, which are links between denote files. I use a per-file workflow and would like denote links between org files (which are exported as pages to my site) to be exported as relative web page links on the site. Right now, I do this by overriding org-hugo-link and handling denote links specially.

Taking a look at org-hugo-link, I think it would be possible to iterate through user-defined functions that take type and raw-path as arguments and returns the link (as a string). This would be similar to org-hugo-tag-processing-functions; we can call this proposed, user-exposed variable org-hugo-link-processing-functions. If I'm not mistaken, this could be done at the beginning of the cond in org-hugo-link, prior to org-hugo's default processing.

This feature gives the user flexibility for interpreting their own link types as well as existing link types, meaning users do not have to override the entire function in order to change how one type of link is transformed. Take my use case described above: I can simply convert my existing code into a function and add it to org-hugo-link-processing-functions. Finally, this proposed feature will not affect existing configurations.

If this sounds appealing, I can go ahead and draft a pull request for it.