Konubinix' opinionated web of thoughts

Org-Gfm-Export-to-Markdown Using Different Id Each Time

Fleeting

org export using different id each time

It uses the CUSTOM_ID and falls back on org-export-get-reference that in turn generates a random number.

I can use the kebab implementation from https://jeffkreeftmeijer.com/ox-html-stable-ids/

(defun org-html-stable-ids--to-kebab-case (string)
  "Convert STRING to kebab-case."
  (string-trim
   (replace-regexp-in-string
    "[^a-z0-9]+" "-"
    (downcase string))
   "-" "-"))

And simply advise org-gfm-format-toc and inject the kebab case of the title in the CUSTOM_ID if it is not provided.

This creates the correct toc, but the links are still bad, because ox-gfm derives from ox-md that contains the function org-md-headline that generates the anchors like this

(format "<a id=\"%s\"></a>"
                (or (org-element-property :CUSTOM_ID headline)
                (org-export-get-reference headline info)))

I would need to advise this function as well, but also the others that deal with CUSTOM_ID, like org-md-link.

This looks like a rabbit hole.