Function: org-link-make-string

org-link-make-string is a byte-compiled function defined in ol.el.gz.

Signature

(org-link-make-string LINK &optional DESCRIPTION)

Documentation

Make a bracket link, consisting of LINK and DESCRIPTION.

LINK is escaped with backslashes for inclusion in buffer.

Aliases

org-make-link-string (obsolete since 9.3)

Source Code

;; Defined in /usr/src/emacs/lisp/org/ol.el.gz
(defun org-link-make-string (link &optional description)
  "Make a bracket link, consisting of LINK and DESCRIPTION.
LINK is escaped with backslashes for inclusion in buffer."
  (let* ((zero-width-space (string ?\x200B))
	 (description
	  (and (org-string-nw-p description)
	       ;; Description cannot contain two consecutive square
	       ;; brackets, or end with a square bracket.  To prevent
	       ;; this, insert a zero width space character between
	       ;; the brackets, or at the end of the description.
	       (replace-regexp-in-string
		"\\(]\\)\\(]\\)"
		(concat "\\1" zero-width-space "\\2")
		(replace-regexp-in-string "]\\'"
					  (concat "\\&" zero-width-space)
					  (org-trim description))))))
    (if (not (org-string-nw-p link))
        (or description
            (error "Empty link"))
      (format "[[%s]%s]"
	      (org-link-escape link)
	      (if description (format "[%s]" description) "")))))