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

Pair Shortcodes with _other_ org elements #675

Closed ispringle closed 1 year ago

ispringle commented 1 year ago

I'm wondering if it would be at all possible to specify org elements other than blocks with a shortcode. For example, I use a block for footnotes and citations in my blog posts because I prefer my footnotes to be spans inline with the content and then push those to the left sidebar with CSS. However, I'd much prefer to just use the actual footnote syntax provided by Org because it's far cleaner and portable.

My thought was provide a way to use the same shortcode pairing idea that exists for blocks, but allow for using them with at least some other non-block org elements. Elements that would probably be most easy to port would be ones that are "wrapped" already, for example an org footnote is "wrapped" if it's inlined, eg [fn:note: my footnote] is already wrapped and wouldn't be too difficult to determine what's trying to be put inside of the shortcode. I'm not sure what the syntax in the properties would be, but maybe something like #+hugo_paired_shortcodes_{element kind}: %shortcode, where {element kind} would be the specific, supported org element.

kaushalmodi commented 1 year ago

Hello.

I'm wondering if it would be at all possible to specify org elements other than blocks with a shortcode.

That's not in the plans. It's very user and developer friendly to extend the Org special blocks for shortcodes.

However, I'd much prefer to just use the actual footnote syntax provided by Org because it's far cleaner and portable.

That would require you to override the org-blackfriday-footnote-reference function. One way would be to create a custom exporter that extends ox-hugo and then specify your custom function to handle the footnote-reference element.

Dummy code:

(org-export-define-derived-backend 'custom 'hugo
  :translate-alist '((footnote-reference . my-footnote-rendering-fn)))

My thought was provide a way to use the same shortcode pairing idea that exists for blocks, but allow for using them with at least some other non-block org elements.

Org provides 2 primary ways of allowing the user to specify custom "codes". Special org blocks is one of them, and Org drawers is the other.

Can you provide more details on what you are trying to implement?


Note that ox-hugo was designed with the philosophy that more things be done in the Org syntax. Reliance on Hugo shortcodes should be done only as the last alternative .. at least that's my designing principle for almost all the features in ox-hugo.

ispringle commented 1 year ago

So here's what I was thinking this would look like:

#+ox_hugo_footnote_shortcade: %footnote

* My Blog Post
...

And then he said, "foo!"[fn:: blah blah blah]

No need to inject the unnatural, albeit native src_block for this footnote. Instead ox-hugo would just know that whenever it encounters a footnote in this org document it should wrap the markdown as a shortcode instead of as a footnote.

This wouldn't work for all org elements, since not all are "wrapping" (delineate the start and end of the element). I think this would go very far towards furthering ox-hugo's mission to get it done with Org syntax.

kaushalmodi commented 1 year ago

@pard68 Implementing this is not on my priority list at the moment. Would you be willing to implement this as an extension to ox-hugo and then share it with the Emacs community?

kaushalmodi commented 1 year ago

@ispringle Sorry, I don't have time to implement this feature. If you have something working, please share that in the Discussions section of this repo.