Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

modified to keep existing CUSTOM_IDs #33

Open
timbirms opened this issue Sep 14, 2024 · 1 comment
Open

modified to keep existing CUSTOM_IDs #33

timbirms opened this issue Sep 14, 2024 · 1 comment
Assignees

Comments

@timbirms
Copy link

(defun org-make-toc--link-entry-github (pos)
  "Return text for entry at POS converted to GitHub style link."
  (-when-let* ((title (org-link-display-format (org-entry-get pos "ITEM")))
               (target (--> title
                            org-link-display-format
                            (downcase it)
                            (replace-regexp-in-string " " "-" it)
                            (replace-regexp-in-string "[^[:alnum:]_-]" "" it)))
               (filename (if org-make-toc-filename-prefix
                             (file-name-nondirectory (buffer-file-name))
                           "")))
    (let ((existing-id (org-entry-get pos "CUSTOM_ID")))
      ;; Only set the CUSTOM_ID if it doesn't already exist
      (unless existing-id
        (when org-make-toc-insert-custom-ids
          (setf target (or (gethash pos org-make-toc-ids)
                           (setf (gethash pos org-make-toc-ids)
                                 (org-make-toc--disambiguate target))))
          (org-set-property "CUSTOM_ID" target)))
      (org-link-make-string (concat filename "#" (or existing-id target))
                            (org-make-toc--visible-text title)))))

thank you very much for all you do!

@alphapapa
Copy link
Owner

Hi Tim,

Thanks, this seems like a good idea, and an obvious one in hindsight. Would you like to contribute it as a patch and have it merged?

Thanks for the kind words.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants