Function: org-odt-link--infer-description

org-odt-link--infer-description is a byte-compiled function defined in ox-odt.el.gz.

Signature

(org-odt-link--infer-description DESTINATION INFO)

Source Code

;; Defined in /usr/src/emacs/lisp/org/ox-odt.el.gz
(defun org-odt-link--infer-description (destination info)
  ;; DESTINATION is a headline or an element (like paragraph,
  ;; verse-block etc) to which a "#+NAME: label" can be attached.

  ;; Note that labels that are attached to captioned entities - inline
  ;; images, math formulae and tables - get resolved as part of
  ;; `org-odt-format-label' and `org-odt--enumerate'.

  ;; Create a cross-reference to DESTINATION but make best-efforts to
  ;; create a *meaningful* description.  Check item numbers, section
  ;; number and section title in that order.

  ;; NOTE: Counterpart of `org-export-get-ordinal'.
  ;; FIXME: Handle footnote-definition footnote-reference?
  (let* ((genealogy (org-element-lineage destination))
	 (data (reverse genealogy))
	 (label (if (org-element-type-p destination '(headline target))
                    (org-export-get-reference destination info)
                  (error "FIXME: Unable to resolve %S" destination))))
    (or
     (let* ( ;; Locate top-level list.
	    (top-level-list
	     (cl-loop for x on data
		      when (org-element-type-p (car x) 'plain-list)
		      return x))
	    ;; Get list item nos.
	    (item-numbers
	     (cl-loop for (plain-list item . rest) on top-level-list by #'cddr
		      until (not (org-element-type-p plain-list 'plain-list))
		      collect (when (eq (org-element-property :type
							      plain-list)
					'ordered)
				(1+ (length (org-export-get-previous-element
					     item info t))))))
	    ;; Locate top-most listified headline.
	    (listified-headlines
	     (cl-loop for x on data
		      when (and (org-element-type-p (car x) 'headline)
				(org-export-low-level-p (car x) info))
		      return x))
	    ;; Get listified headline numbers.
	    (listified-headline-nos
	     (cl-loop for el in listified-headlines
		      when (org-element-type-p el 'headline)
		      collect (when (org-export-numbered-headline-p el info)
				(1+ (length (org-export-get-previous-element
					     el info t)))))))
       ;; Combine item numbers from both the listified headlines and
       ;; regular list items.

       ;; Case 1: Check if all the parents of list item are numbered.
       ;; If yes, link to the item proper.
       (let ((item-numbers (append listified-headline-nos item-numbers)))
	 (when (and item-numbers (not (memq nil item-numbers)))
	   (format "<text:bookmark-ref text:reference-format=\"number-all-superior\" text:ref-name=\"%s\">%s</text:bookmark-ref>"
		   label
		   (mapconcat (lambda (n) (if (not n) " "
                                            (concat (number-to-string n) ".")))
			      item-numbers "")))))
     ;; Case 2: Locate a regular and numbered headline in the
     ;; hierarchy.  Display its section number.
     (let ((headline
	    (and
	     ;; Test if destination is a numbered headline.
	     (org-export-numbered-headline-p destination info)
	     (cl-loop for el in (cons destination genealogy)
		      when (and (org-element-type-p el 'headline)
				(not (org-export-low-level-p el info))
				(org-export-numbered-headline-p el info))
		      return el))))
       ;; We found one.
       (when headline
	 (format "<text:bookmark-ref text:reference-format=\"chapter\" text:ref-name=\"OrgXref.%s\">%s</text:bookmark-ref>"
		 label
		 (mapconcat 'number-to-string (org-export-get-headline-number
					       headline info) "."))))
     ;; Case 4: Locate a regular headline in the hierarchy.  Display
     ;; its title.
     (let ((headline (cl-loop for el in (cons destination genealogy)
			      when (and (org-element-type-p el 'headline)
					(not (org-export-low-level-p el info)))
			      return el)))
       ;; We found one.
       (when headline
	 (format "<text:bookmark-ref text:reference-format=\"text\" text:ref-name=\"OrgXref.%s\">%s</text:bookmark-ref>"
		 label
		 (let ((title (org-element-property :title headline)))
		   (org-export-data title info)))))
     (error "FIXME?"))))