In ox.el (org-export-resolve-id-link) we need to remove search string from path
when checking for id.

ID links can have search string. For example:

  id:4E8212FF-55F3-4E23-A63C-DB0EA8003FBA::*Heading

This patch does the following:

When searching for matching id, remove the part beginning at ::. For
backwards compatibility with links that can have :: within their id,
also check for any id that match the full path. This is similar to
what is done at org-id-open in org-id.el .
From 725ea594b3ef1403074300584c4eb0e266b201c1 Mon Sep 17 00:00:00 2001
From: Bibek Panthi <bpanthi...@gmail.com>
Date: Wed, 14 May 2025 00:12:47 -0500
Subject: [PATCH] lisp/ox.el: Fix export of id links with search string

* ox.el (org-export-resolve-id-link): Remove search string from path
when checking for id

ID links can have search string. For example:

  id:4E8212FF-55F3-4E23-A63C-DB0EA8003FBA::*Heading

When searching for matching id, remove the part beginning at ::. For
backwards compatibility with links that can have :: within their id,
also check for any id that match the full path. This is similar to
what is done at org-id-open in org-id.el .

TINYCHANGE
---
 lisp/ox.el | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/lisp/ox.el b/lisp/ox.el
index 06c346b65..91ce86b70 100644
--- a/lisp/ox.el
+++ b/lisp/ox.el
@@ -4554,7 +4554,11 @@
 Return value can be the headline element matched in current parse
 tree or a file name.  Assume LINK type is either \"id\" or
 \"custom-id\".  Throw an error if no match is found."
-  (let ((id (org-element-property :path link)))
+  (let* ((path (org-element-property :path link))
+        (option (and (string-match "::\\(.*\\)\\'" path)
+                     (match-string 1 path)))
+        (id (if (not option) path
+              (substring path 0 (match-beginning 0)))))
     ;; First check if id is within the current parse tree.
     (or (let ((local-ids (or (plist-get info :id-local-cache)
                              (let ((table (make-hash-table :test #'equal)))
@@ -4573,7 +4577,8 @@
                                  info)
                                (plist-put info :id-local-cache table)
                                table))))
-          (gethash id local-ids))
+          (gethash id local-ids)
+         (gethash path local-ids)) ;; Backwards compatibility for ids that 
have ::
         ;; Otherwise, look for external files.
         (cdr (assoc id (plist-get info :id-alist)))
         (signal 'org-link-broken (list id)))))
-- 
2.39.5 (Apple Git-154)

Reply via email to