mirror of
https://git.savannah.gnu.org/git/emacs/org-mode.git
synced 2024-07-15 14:16:27 +00:00
org-export: Only number elements with a caption
* contrib/lisp/org-export.el (org-export-collect-elements): Collect elements with a caption only. (org-export-collect-tables, org-export-collect-figures, org-export-collect-listings): Update docstring. * contrib/lisp/org-e-ascii.el (org-e-ascii--has-caption-p): Renamed from `org-e-ascii--has-caption-or-name-p'. (org-e-ascii-link): Use previous function. (org-e-ascii--build-caption, org-e-ascii--list-listings, org-e-ascii--list-tables): Do not use #+NAME keyword as a fallback caption.
This commit is contained in:
parent
937b56ec89
commit
dc976e1139
|
@ -676,41 +676,34 @@ title."
|
||||||
(concat "\n"
|
(concat "\n"
|
||||||
(make-string (length first-part) under-char))))))))
|
(make-string (length first-part) under-char))))))))
|
||||||
|
|
||||||
(defun org-e-ascii--has-caption-or-name-p (element info)
|
(defun org-e-ascii--has-caption-p (element info)
|
||||||
"Non-nil when ELEMENT has a caption or a name affiliated keyword.
|
"Non-nil when ELEMENT has a caption affiliated keyword.
|
||||||
|
INFO is a plist used as a communication channel. This function
|
||||||
INFO is a plist used as a communication channel.
|
is meant to be used as a predicate for `org-export-get-ordinal'."
|
||||||
|
(org-element-property :caption element))
|
||||||
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)
|
(defun org-e-ascii--build-caption (element info)
|
||||||
"Return caption string for ELEMENT, if applicable.
|
"Return caption string for ELEMENT, if applicable.
|
||||||
|
|
||||||
INFO is a plist used as a communication channel.
|
INFO is a plist used as a communication channel.
|
||||||
|
|
||||||
The caption string contains the sequence number of ELEMENT if it
|
The caption string contains the sequence number of ELEMENT along
|
||||||
has a name affiliated keyword, along with the real caption, if
|
with its real caption. Return nil when ELEMENT has no affiliated
|
||||||
any. Return nil when ELEMENT has no affiliated caption or name
|
caption keyword."
|
||||||
keyword."
|
(let ((caption (org-element-property :caption element)))
|
||||||
(let ((caption (org-element-property :caption element))
|
(when caption
|
||||||
(name (org-element-property :name element)))
|
|
||||||
(when (or caption name)
|
|
||||||
;; Get sequence number of current src-block among every
|
;; Get sequence number of current src-block among every
|
||||||
;; src-block with either a caption or a name.
|
;; src-block with a caption.
|
||||||
(let ((reference
|
(let ((reference
|
||||||
(org-export-get-ordinal
|
(org-export-get-ordinal
|
||||||
element info nil 'org-e-ascii--has-caption-or-name-p))
|
element info nil 'org-e-ascii--has-caption-p))
|
||||||
(title-fmt (org-e-ascii--translate
|
(title-fmt (org-e-ascii--translate
|
||||||
(case (org-element-type element)
|
(case (org-element-type element)
|
||||||
(table "Table %d: %s")
|
(table "Table %d: %s")
|
||||||
(src-block "Listing %d: %s")) info)))
|
(src-block "Listing %d: %s"))
|
||||||
|
info)))
|
||||||
(org-e-ascii--fill-string
|
(org-e-ascii--fill-string
|
||||||
(format
|
(format title-fmt reference (org-export-data (car caption) info))
|
||||||
title-fmt reference
|
|
||||||
(if (not caption) name (org-export-data (car caption) info)))
|
|
||||||
(org-e-ascii--current-text-width element info) info)))))
|
(org-e-ascii--current-text-width element info) info)))))
|
||||||
|
|
||||||
(defun org-e-ascii--build-toc (info &optional n keyword)
|
(defun org-e-ascii--build-toc (info &optional n keyword)
|
||||||
|
@ -774,9 +767,8 @@ generation. INFO is a plist used as a communication channel."
|
||||||
(org-e-ascii--indent-string
|
(org-e-ascii--indent-string
|
||||||
(org-e-ascii--fill-string
|
(org-e-ascii--fill-string
|
||||||
(let ((caption (org-element-property :caption src-block)))
|
(let ((caption (org-element-property :caption src-block)))
|
||||||
(if (not caption) (org-element-property :name src-block)
|
;; Use short name in priority, if available.
|
||||||
;; Use short name in priority, if available.
|
(org-export-data (or (cdr caption) (car caption)) info))
|
||||||
(org-export-data (or (cdr caption) (car caption)) info)))
|
|
||||||
(- text-width (length initial-text)) info)
|
(- text-width (length initial-text)) info)
|
||||||
(length initial-text))))))
|
(length initial-text))))))
|
||||||
(org-export-collect-listings info) "\n")))))
|
(org-export-collect-listings info) "\n")))))
|
||||||
|
@ -812,9 +804,8 @@ generation. INFO is a plist used as a communication channel."
|
||||||
(org-e-ascii--indent-string
|
(org-e-ascii--indent-string
|
||||||
(org-e-ascii--fill-string
|
(org-e-ascii--fill-string
|
||||||
(let ((caption (org-element-property :caption table)))
|
(let ((caption (org-element-property :caption table)))
|
||||||
(if (not caption) (org-element-property :name table)
|
;; Use short name in priority, if available.
|
||||||
;; Use short name in priority, if available.
|
(org-export-data (or (cdr caption) (car caption)) info))
|
||||||
(org-export-data (or (cdr caption) (car caption)) info)))
|
|
||||||
(- text-width (length initial-text)) info)
|
(- text-width (length initial-text)) info)
|
||||||
(length initial-text))))))
|
(length initial-text))))))
|
||||||
(org-export-collect-tables info) "\n")))))
|
(org-export-collect-tables info) "\n")))))
|
||||||
|
@ -1472,8 +1463,7 @@ INFO is a plist holding contextual information."
|
||||||
(when destination
|
(when destination
|
||||||
(let ((number
|
(let ((number
|
||||||
(org-export-get-ordinal
|
(org-export-get-ordinal
|
||||||
destination info nil
|
destination info nil 'org-e-ascii--has-caption-p)))
|
||||||
'org-e-ascii--has-caption-or-name-p)))
|
|
||||||
(when number
|
(when number
|
||||||
(if (atom number) (number-to-string number)
|
(if (atom number) (number-to-string number)
|
||||||
(mapconcat 'number-to-string number ".")))))))))
|
(mapconcat 'number-to-string number ".")))))))))
|
||||||
|
|
|
@ -3766,8 +3766,7 @@ Return a list of all exportable headlines as parsed elements."
|
||||||
"Collect referenceable elements of a determined type.
|
"Collect referenceable elements of a determined type.
|
||||||
|
|
||||||
TYPE can be a symbol or a list of symbols specifying element
|
TYPE can be a symbol or a list of symbols specifying element
|
||||||
types to search. Only elements with a caption or a name are
|
types to search. Only elements with a caption are collected.
|
||||||
collected.
|
|
||||||
|
|
||||||
INFO is a plist used as a communication channel.
|
INFO is a plist used as a communication channel.
|
||||||
|
|
||||||
|
@ -3779,18 +3778,16 @@ Return a list of all elements found, in order of appearance."
|
||||||
(org-element-map
|
(org-element-map
|
||||||
(plist-get info :parse-tree) type
|
(plist-get info :parse-tree) type
|
||||||
(lambda (element)
|
(lambda (element)
|
||||||
(and (or (org-element-property :caption element)
|
(and (org-element-property :caption element)
|
||||||
(org-element-property :name element))
|
|
||||||
(or (not predicate) (funcall predicate element))
|
(or (not predicate) (funcall predicate element))
|
||||||
element)) info))
|
element))
|
||||||
|
info))
|
||||||
|
|
||||||
(defun org-export-collect-tables (info)
|
(defun org-export-collect-tables (info)
|
||||||
"Build a list of tables.
|
"Build a list of tables.
|
||||||
|
|
||||||
INFO is a plist used as a communication channel.
|
INFO is a plist used as a communication channel.
|
||||||
|
|
||||||
Return a list of table elements with a caption or a name
|
Return a list of table elements with a caption."
|
||||||
affiliated keyword."
|
|
||||||
(org-export-collect-elements 'table info))
|
(org-export-collect-elements 'table info))
|
||||||
|
|
||||||
(defun org-export-collect-figures (info predicate)
|
(defun org-export-collect-figures (info predicate)
|
||||||
|
@ -3801,9 +3798,9 @@ a function which accepts one argument: a paragraph element and
|
||||||
whose return value is non-nil when that element should be
|
whose return value is non-nil when that element should be
|
||||||
collected.
|
collected.
|
||||||
|
|
||||||
A figure is a paragraph type element, with a caption or a name,
|
A figure is a paragraph type element, with a caption, verifying
|
||||||
verifying PREDICATE. The latter has to be provided since
|
PREDICATE. The latter has to be provided since a \"figure\" is
|
||||||
a \"figure\" is a vague concept that may depend on back-end.
|
a vague concept that may depend on back-end.
|
||||||
|
|
||||||
Return a list of elements recognized as figures."
|
Return a list of elements recognized as figures."
|
||||||
(org-export-collect-elements 'paragraph info predicate))
|
(org-export-collect-elements 'paragraph info predicate))
|
||||||
|
@ -3813,8 +3810,7 @@ Return a list of elements recognized as figures."
|
||||||
|
|
||||||
INFO is a plist used as a communication channel.
|
INFO is a plist used as a communication channel.
|
||||||
|
|
||||||
Return a list of src-block elements with a caption or a name
|
Return a list of src-block elements with a caption."
|
||||||
affiliated keyword."
|
|
||||||
(org-export-collect-elements 'src-block info))
|
(org-export-collect-elements 'src-block info))
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue