Function: org-element-link-interpreter

org-element-link-interpreter is a byte-compiled function defined in org-element.el.gz.

Signature

(org-element-link-interpreter LINK CONTENTS)

Documentation

Interpret LINK object as Org syntax.

CONTENTS is the contents of the object, or nil.

Source Code

;; Defined in /usr/src/emacs/lisp/org/org-element.el.gz
(defun org-element-link-interpreter (link contents)
  "Interpret LINK object as Org syntax.
CONTENTS is the contents of the object, or nil."
  (let ((type (org-element-property :type link))
	(path (org-element-property :path link)))
    (if (string= type "radio") path
      (let ((fmt (pcase (org-element-property :format link)
		   ;; Links with contents and internal links have to
		   ;; use bracket syntax.  Ignore `:format' in these
		   ;; cases.  This is also the default syntax when the
		   ;; property is not defined, e.g., when the object
		   ;; was crafted by the user.
		   ((guard contents)
		    (format "[[%%s][%s]]"
			    ;; Since this is going to be used as
			    ;; a format string, escape percent signs
			    ;; in description.
			    (replace-regexp-in-string "%" "%%" contents)))
		   ((or `bracket
			`nil
			(guard (member type '("coderef" "custom-id" "fuzzy"))))
		    "[[%s]]")
		   ;; Otherwise, just obey to `:format'.
		   (`angle "<%s>")
		   (`plain "%s")
		   (f (error "Wrong `:format' value: %s" f)))))
	(format fmt
		(pcase type
		  ("coderef" (format "(%s)" path))
		  ("custom-id" (concat "#" path))
		  ("file"
		   (let ((app (org-element-property :application link))
			 (opt (org-element-property :search-option link))
                         (type-explicit-p (org-element-property :type-explicit-p link)))
		     (concat (and type-explicit-p type)
                             (and type-explicit-p app (concat "+" app))
                             (and type-explicit-p ":")
			     path
			     (and opt (concat "::" opt)))))
		  ("fuzzy" path)
		  (_ (concat type ":" path))))))))