org-e-ascii: Ensure consistent cross-referencing between elements and links

* contrib/lisp/org-e-ascii.el (org-e-ascii--has-caption-or-name-p):
  New function.
(org-e-ascii--build-caption, org-e-ascii-link): Use new function.

This patch ensures only elements with a name or a caption are counted
in when a fuzzy link pointing to an element is resolved.
This commit is contained in:
Nicolas Goaziou 2012-05-20 13:57:58 +02:00
parent c91bcb368f
commit 65c0e18892
1 changed files with 16 additions and 5 deletions

View File

@ -676,6 +676,16 @@ title."
(concat "\n"
(make-string (length first-part) under-char))))))))
(defun org-e-ascii--has-caption-or-name-p (element info)
"Non-nil when ELEMENT has a caption or a name affiliated keyword.
INFO is a plist used as a communication channel.
This function is meant to be used as a predicate for
`org-export-get-ordinal'."
(or (org-element-property :caption element)
(org-element-property :name element)))
(defun org-e-ascii--build-caption (element info)
"Return caption string for ELEMENT, if applicable.
@ -692,9 +702,7 @@ keyword."
;; src-block with either a caption or a name.
(let ((reference
(org-export-get-ordinal
element info nil
(lambda (el info) (or (org-element-property :caption el)
(org-element-property :name el)))))
element info nil 'org-e-ascii--has-caption-or-name-p))
(title-fmt (org-e-ascii--translate
(case (org-element-type element)
(table "Table %d: %s")
@ -1458,11 +1466,14 @@ INFO is a plist holding contextual information."
;; targets.
((string= type "fuzzy")
(let ((destination (org-export-resolve-fuzzy-link link info)))
;; Ignore invisible "#+target: path".
;; Ignore invisible "#+TARGET: path".
(unless (eq (org-element-type destination) 'keyword)
(if (org-string-nw-p desc) desc
(when destination
(let ((number (org-export-get-ordinal destination info)))
(let ((number
(org-export-get-ordinal
destination info nil
'org-e-ascii--has-caption-or-name-p)))
(when number
(if (atom number) (number-to-string number)
(mapconcat 'number-to-string number ".")))))))))