浏览代码

org-e-ascii/org-e-latex/org-e-md: Use new caption tool

* contrib/lisp/org-e-ascii.el (org-e-ascii--build-caption,
  org-e-ascii--list-listings, org-e-ascii--list-tables): Use new
  caption tool.
* contrib/lisp/org-e-latex.el (org-e-latex--caption/label-string): New
  signature.  Use new caption tool.
(org-e-latex-link--inline-image, org-e-latex-src-block,
org-e-latex-table--org-table): Apply signature change.
* contrib/lisp/org-md.el (org-md-link): Use new caption tool.
Nicolas Goaziou 13 年之前
父节点
当前提交
28f8ca60c7
共有 3 个文件被更改,包括 41 次插入48 次删除
  1. 10 8
      contrib/lisp/org-e-ascii.el
  2. 28 36
      contrib/lisp/org-e-latex.el
  3. 3 4
      contrib/lisp/org-md.el

+ 10 - 8
contrib/lisp/org-e-ascii.el

@@ -577,7 +577,7 @@ INFO is a plist used as a communication channel.
 The caption string contains the sequence number of ELEMENT along
 The caption string contains the sequence number of ELEMENT along
 with its real caption.  Return nil when ELEMENT has no affiliated
 with its real caption.  Return nil when ELEMENT has no affiliated
 caption keyword."
 caption keyword."
-  (let ((caption (org-element-property :caption element)))
+  (let ((caption (org-export-get-caption element)))
     (when caption
     (when caption
       ;; Get sequence number of current src-block among every
       ;; Get sequence number of current src-block among every
       ;; src-block with a caption.
       ;; src-block with a caption.
@@ -590,7 +590,7 @@ caption keyword."
 			  (src-block "Listing %d: %s"))
 			  (src-block "Listing %d: %s"))
 			info)))
 			info)))
 	(org-e-ascii--fill-string
 	(org-e-ascii--fill-string
-	 (format title-fmt reference (org-export-data (car caption) info))
+	 (format title-fmt reference (org-export-data 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)
@@ -653,9 +653,10 @@ generation.  INFO is a plist used as a communication channel."
 	     (org-trim
 	     (org-trim
 	      (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)))
-		  ;; Use short name in priority, if available.
-		  (org-export-data (or (cdr caption) (car caption)) info))
+		;; Use short name in priority, if available.
+		(let ((caption (or (org-export-get-caption src-block t)
+				   (org-export-get-caption src-block))))
+		  (org-export-data 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")))))
@@ -690,9 +691,10 @@ generation.  INFO is a plist used as a communication channel."
 	     (org-trim
 	     (org-trim
 	      (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)))
-		  ;; Use short name in priority, if available.
-		  (org-export-data (or (cdr caption) (car caption)) info))
+		;; Use short name in priority, if available.
+		(let ((caption (or (org-export-get-caption table t)
+				   (org-export-get-caption table))))
+		  (org-export-data 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")))))

+ 28 - 36
contrib/lisp/org-e-latex.el

@@ -824,31 +824,27 @@ These are the .aux, .log, .out, and .toc files."
 
 
 ;;; Internal Functions
 ;;; Internal Functions
 
 
-(defun org-e-latex--caption/label-string (caption label info)
-  "Return caption and label LaTeX string for floats.
+(defun org-e-latex--caption/label-string (element info)
+  "Return caption and label LaTeX string for ELEMENT.
 
 
-CAPTION is a cons cell of secondary strings, the car being the
-standard caption and the cdr its short form.  LABEL is a string
-representing the label.  INFO is a plist holding contextual
-information.
-
-If there's no caption nor label, return the empty string.
+INFO is a plist holding contextual information.  If there's no
+caption nor label, return the empty string.
 
 
 For non-floats, see `org-e-latex--wrap-label'."
 For non-floats, see `org-e-latex--wrap-label'."
-  (let ((label-str (if label (format "\\label{%s}" label) "")))
+  (let* ((label (org-element-property :name element))
+	 (label-str (if label (format "\\label{%s}" label) ""))
+	 (main (org-export-get-caption element))
+	 (short (org-export-get-caption element t)))
     (cond
     (cond
-     ((and (not caption) (not label)) "")
-     ((not caption) (format "\\label{%s}\n" label))
+     ((and (not main) (not label)) "")
+     ((not main) (format "\\label{%s}\n" label))
      ;; Option caption format with short name.
      ;; Option caption format with short name.
-     ((cdr caption)
-      (format "\\caption[%s]{%s%s}\n"
-	      (org-export-data (cdr caption) info)
-	      label-str
-	      (org-export-data (car caption) info)))
+     (short (format "\\caption[%s]{%s%s}\n"
+		    (org-export-data short info)
+		    label-str
+		    (org-export-data main info)))
      ;; Standard caption format.
      ;; Standard caption format.
-     (t (format "\\caption{%s%s}\n"
-		label-str
-		(org-export-data (car caption) info))))))
+     (t (format "\\caption{%s%s}\n" label-str (org-export-data main info))))))
 
 
 (defun org-e-latex--guess-babel-language (header info)
 (defun org-e-latex--guess-babel-language (header info)
   "Set Babel's language according to LANGUAGE keyword.
   "Set Babel's language according to LANGUAGE keyword.
@@ -1703,10 +1699,7 @@ used as a communication channel."
 	 (path (let ((raw-path (org-element-property :path link)))
 	 (path (let ((raw-path (org-element-property :path link)))
 		 (if (not (file-name-absolute-p raw-path)) raw-path
 		 (if (not (file-name-absolute-p raw-path)) raw-path
 		   (expand-file-name raw-path))))
 		   (expand-file-name raw-path))))
-	 (caption (org-e-latex--caption/label-string
-		   (org-element-property :caption parent)
-		   (org-element-property :name parent)
-		   info))
+	 (caption (org-e-latex--caption/label-string parent info))
 	 ;; Retrieve latex attributes from the element around.
 	 ;; Retrieve latex attributes from the element around.
 	 (attr (let ((raw-attr
 	 (attr (let ((raw-attr
 		      (mapconcat #'identity
 		      (mapconcat #'identity
@@ -2049,7 +2042,7 @@ contextual information."
     (cond
     (cond
      ;; Case 1.  No source fontification.
      ;; Case 1.  No source fontification.
      ((not org-e-latex-listings)
      ((not org-e-latex-listings)
-      (let ((caption-str (org-e-latex--caption/label-string caption label info))
+      (let ((caption-str (org-e-latex--caption/label-string src-block info))
 	    (float-env (when caption "\\begin{figure}[H]\n%s\n\\end{figure}")))
 	    (float-env (when caption "\\begin{figure}[H]\n%s\n\\end{figure}")))
 	(format
 	(format
 	 (or float-env "%s")
 	 (or float-env "%s")
@@ -2063,10 +2056,10 @@ contextual information."
 			 custom-env))
 			 custom-env))
      ;; Case 3.  Use minted package.
      ;; Case 3.  Use minted package.
      ((eq org-e-latex-listings 'minted)
      ((eq org-e-latex-listings 'minted)
-      (let ((float-env (when (or label caption)
-			 (format "\\begin{listing}[H]\n%%s\n%s\\end{listing}"
-				 (org-e-latex--caption/label-string
-				  caption label info))))
+      (let ((float-env
+	     (when (or label caption)
+	       (format "\\begin{listing}[H]\n%%s\n%s\\end{listing}"
+		       (org-e-latex--caption/label-string src-block info))))
 	    (body
 	    (body
 	     (format
 	     (format
 	      "\\begin{minted}[%s]{%s}\n%s\\end{minted}"
 	      "\\begin{minted}[%s]{%s}\n%s\\end{minted}"
@@ -2103,12 +2096,12 @@ contextual information."
       (let ((lst-lang
       (let ((lst-lang
 	     (or (cadr (assq (intern lang) org-e-latex-listings-langs)) lang))
 	     (or (cadr (assq (intern lang) org-e-latex-listings-langs)) lang))
 	    (caption-str
 	    (caption-str
-	     (when caption
-	       (let ((main (org-export-data (car caption) info)))
-		 (if (not (cdr caption)) (format "{%s}" main)
-		   (format "{[%s]%s}"
-			   (org-export-data (cdr caption) info)
-			   main))))))
+	     (let ((main (org-export-get-caption src-block))
+		   (secondary (org-export-get-caption src-block t)))
+	       (if (not secondary) (format "{%s}" (org-export-data main info))
+		 (format "{[%s]%s}"
+			 (org-export-data secondary info)
+			 (org-export-data main info))))))
 	(concat
 	(concat
 	 ;; Options.
 	 ;; Options.
 	 (format "\\lstset{%s}\n"
 	 (format "\\lstset{%s}\n"
@@ -2302,8 +2295,7 @@ channel.
 
 
 This function assumes TABLE has `org' as its `:type' attribute."
 This function assumes TABLE has `org' as its `:type' attribute."
   (let* ((label (org-element-property :name table))
   (let* ((label (org-element-property :name table))
-	 (caption (org-e-latex--caption/label-string
-		   (org-element-property :caption table) label info))
+	 (caption (org-e-latex--caption/label-string table info))
 	 (attr (mapconcat 'identity
 	 (attr (mapconcat 'identity
 			  (org-element-property :attr_latex table)
 			  (org-element-property :attr_latex table)
 			  " "))
 			  " "))

+ 3 - 4
contrib/lisp/org-md.el

@@ -286,10 +286,9 @@ a communication channel."
 					   ".")))))))
 					   ".")))))))
 	  ((org-export-inline-image-p link org-e-html-inline-image-rules)
 	  ((org-export-inline-image-p link org-e-html-inline-image-rules)
 	   (format "![%s](%s)"
 	   (format "![%s](%s)"
-		   (let ((caption
-			  (org-element-property
-			   :caption (org-export-get-parent-element link))))
-		     (when caption (org-export-data (car caption) info)))
+		   (let ((caption (org-export-get-caption
+				   (org-export-get-parent-element link))))
+		     (when caption (org-export-data caption info)))
 		   path))
 		   path))
 	  ((string= type "coderef")
 	  ((string= type "coderef")
 	   (let ((ref (org-element-property :path link)))
 	   (let ((ref (org-element-property :path link)))