From org-num--make-overlay
we find that org-nume-mode
does not insert extra contents in a buffer, but only creates the numbers as overlays (via the 'after-string' property). So, to get the numbers, you should get the appropriate property of that overlay. The following function provides an example for how to achieve what you want:
(defun org-replace-links-descs (&rest _) ; accepts, any number of 'unused'; arguments
(interactive)
(if (not org-num-mode)
(message "org-num-mode not active")
(goto-char (point-min))
(while (not (stringp (org-next-link)))
(let* ((context (org-element-context))
(beg (org-element-property :begin context))
(end (org-element-property :end context))
(cbeg (org-element-property :contents-begin context))
(cend (org-element-property :contents-end context))
(raw-link (org-element-property :raw-link context))
file
num)
(when (string-match "\\(^*\\|:\\*\\)" raw-link)
(save-excursion
(org-link-open context)
(unless org-num-mode (org-num-mode))
(skip-chars-forward "*")
;; there can be multiple overlays so we filter out 'org-num' overlay
(when (string-match "^file" raw-link)
(setq file (nth 1 (split-string raw-link ":"))))
(setq num (substring
(car
(delete nil
(mapcar (lambda (o)
(when (overlay-get o 'org-num)
(overlay-get o 'after-string)))
(overlays-at (point)))))
0 -1)))
(let ((new-desc (concat file (when file ":") num)))
(if cbeg
(replace-region-contents cbeg cend (lambda () new-desc))
(goto-char (1- end))
(insert "[" new-desc "]"))))))))
(defun my-org-export-dispatch ()
(interactive)
(when org-num-mode
(org-replace-links-descs))
(org-export-dispatch))
Now, you can call the org-replace-links-descs
function 'manually' before export, or you can create a custom function, where you call org-replace-links-descs
before you export function, like in the my-org-export-dispatch
example, to 'trigger' the export (another option would be to advise the export function, but if using a 'custom export function' is an option, then that would be the easiest solution).