Function: org-publish-resolve-external-link

org-publish-resolve-external-link is a byte-compiled function defined in ox-publish.el.gz.

Signature

(org-publish-resolve-external-link SEARCH FILE &optional PREFER-CUSTOM)

Documentation

Return reference for element matching string SEARCH in FILE.

Return value is an internal reference, as a string.

This function allows resolving external links with a search option, e.g.,

  [[file:file.org::*heading][description]]
  [[file:file.org::#custom-id][description]]
  [[file:file.org::fuzzy][description]]

When PREFER-CUSTOM is non-nil, and SEARCH targets a headline in FILE, return its custom ID, if any.

It only makes sense to use this if export backend builds references with org-export-get-reference.

Source Code

;; Defined in /usr/src/emacs/lisp/org/ox-publish.el.gz
(defun org-publish-resolve-external-link (search file &optional prefer-custom)
  "Return reference for element matching string SEARCH in FILE.

Return value is an internal reference, as a string.

This function allows resolving external links with a search
option, e.g.,

  [[file:file.org::*heading][description]]
  [[file:file.org::#custom-id][description]]
  [[file:file.org::fuzzy][description]]

When PREFER-CUSTOM is non-nil, and SEARCH targets a headline in
FILE, return its custom ID, if any.

It only makes sense to use this if export backend builds
references with `org-export-get-reference'."
  (cond
   ((and prefer-custom
	 (if (string-prefix-p "#" search)
	     (substring search 1)
	   (with-current-buffer (find-file-noselect file)
	     (org-with-point-at 1
	       (let ((org-link-search-must-match-exact-headline t))
		 (condition-case err
		     (org-link-search search nil t)
		   (error
		    (signal 'org-link-broken (cdr err)))))
	       (and (derived-mode-p 'org-mode)
                    (org-at-heading-p)
		    (org-string-nw-p (org-entry-get (point) "CUSTOM_ID"))))))))
   ((not org-publish-cache)
    (progn
      (message "Reference %S in file %S cannot be resolved without publishing"
	       search
	       file)
      "MissingReference"))
   (t
    (let* ((filename (file-truename file))
	   (crossrefs
	    (org-publish-cache-get-file-property filename :crossrefs nil t))
	   (cells (org-export-string-to-search-cell search)))
      (or
       ;; Look for reference associated to search cells triggered by
       ;; LINK.  It can match when targeted file has been published
       ;; already.
       (let ((known (cdr (cl-some (lambda (c) (assoc c crossrefs)) cells))))
	 (and known (org-export-format-reference known)))
       ;; Search cell is unknown so far.  Generate a new internal
       ;; reference that will be used when the targeted file will be
       ;; published.
       (let ((new (org-export-new-reference crossrefs)))
	 (dolist (cell cells) (push (cons cell new) crossrefs))
	 (org-publish-cache-set-file-property filename :crossrefs crossrefs)
	 (org-export-format-reference new)))))))