Переглянути джерело

org-export: Fix table export bug with cells made of only one object

* contrib/lisp/org-export.el (org-export-table-row-is-special-p,
  org-export-table-cell-width, org-export-table-cell-alignment):
  Ensure cell only contains a string before trying to match width
  cookie.
* testing/lisp/test-org-export.el: Modify tests accordingly.

Thanks to Eric Fraga for discovering and investigating about this.
Nicolas Goaziou 13 роки тому
батько
коміт
01d83dc1f4
2 змінених файлів з 27 додано та 19 видалено
  1. 23 15
      contrib/lisp/org-export.el
  2. 4 4
      testing/lisp/test-org-export.el

+ 23 - 15
contrib/lisp/org-export.el

@@ -3262,8 +3262,11 @@ All special rows will be ignored during export."
 	   (mapc
 	    (lambda (cell)
 	      (let ((value (org-element-contents cell)))
+		;; Since VALUE is a secondary string, the following
+		;; checks avoid expanding it with `org-export-data'.
 		(cond ((not value))
 		      ((and (not (cdr value))
+			    (stringp (car value))
 			    (string-match "\\`<[lrc]?\\([0-9]+\\)?>\\'"
 					  (car value)))
 		       (setq special-row-p 'cookie))
@@ -3313,13 +3316,15 @@ same column as TABLE-CELL, or nil."
 	((org-export-table-row-is-special-p row info)
 	 (let ((value (org-element-contents
 		       (elt (org-element-contents row) column))))
-	   (cond
-	    ((not value))
-	    ((and (not (cdr value))
-		  (string-match "\\`<[lrc]?\\([0-9]+\\)?>\\'" (car value))
-		  (match-string 1 (car value)))
+	   ;; The following checks avoid expanding unnecessarily the
+	   ;; cell with `org-export-data'
+	   (when (and value
+		      (not (cdr value))
+		      (stringp (car value))
+		      (string-match "\\`<[lrc]?\\([0-9]+\\)?>\\'" (car value))
+		      (match-string 1 (car value)))
 	     (setq cookie-width
-		   (string-to-number (match-string 1 (car value))))))))
+		   (string-to-number (match-string 1 (car value)))))))
 	;; Ignore table rules.
 	((eq (org-element-property :type row) 'rule))))
      (org-element-contents table))
@@ -3352,13 +3357,15 @@ Possible values are `left', `right' and `center'."
 	((org-export-table-row-is-special-p row info)
 	 (let ((value (org-element-contents
 		       (elt (org-element-contents row) column))))
-	   (cond
-	    ((not value))
-	    ((and (not (cdr value))
-		  (string-match "\\`<\\([lrc]\\)?\\([0-9]+\\)?>\\'"
-				(car value))
-		  (match-string 1 (car value)))
-	     (setq cookie-align (match-string 1 (car value)))))))
+	   ;; Since VALUE is a secondary string, the following checks
+	   ;; avoid useless expansion through `org-export-data'.
+	   (when (and value
+		      (not (cdr value))
+		      (stringp (car value))
+		      (string-match "\\`<\\([lrc]\\)?\\([0-9]+\\)?>\\'"
+				    (car value))
+		      (match-string 1 (car value)))
+	     (setq cookie-align (match-string 1 (car value))))))
 	;; Ignore table rules.
 	((eq (org-element-property :type row) 'rule))
 	;; In a standard row, check if cell's contents are expressing
@@ -3366,9 +3373,10 @@ Possible values are `left', `right' and `center'."
 	;; Though, don't bother if an alignment cookie has already
 	;; defined cell's alignment.
 	((not cookie-align)
-	 (let ((value (org-element-interpret-data
+	 (let ((value (org-export-data
 		       (org-element-contents
-			(elt (org-element-contents row) column)))))
+			(elt (org-element-contents row) column))
+		       info)))
 	   (incf total-cells)
 	   (when (string-match org-table-number-regexp value)
 	     (incf number-cells))))))

+ 4 - 4
testing/lisp/test-org-export.el

@@ -724,8 +724,8 @@ Another text. (ref:text)
       (org-element-map
        (org-element-parse-buffer) 'table 'identity nil 'first-match)))))
 
-(ert-deftest test-org-export/special-row ()
-  "Test if special rows in a table are properly recognized."
+(ert-deftest test-org-export/table-row-is-special-p ()
+  "Test `org-export-table-row-is-special-p' specifications."
   ;; 1. A row is special if it has a special marking character in the
   ;;    special column.
   (org-test-with-parsed-data "| ! | 1 |"
@@ -746,7 +746,7 @@ Another text. (ref:text)
      (org-export-table-row-is-special-p
       (org-element-map tree 'table-row 'identity nil 'first-match) info)))
   ;; 4. Everything else isn't considered as special.
-  (org-test-with-parsed-data "| a |   | c |"
+  (org-test-with-parsed-data "| \alpha |   | c |"
     (should-not
      (org-export-table-row-is-special-p
       (org-element-map tree 'table-row 'identity nil 'first-match) info)))
@@ -894,7 +894,7 @@ Another text. (ref:text)
     (org-test-with-temp-text "
 | text      |
 | some text |
-| 12345     |"
+| \alpha    |"
       (let* ((tree (org-element-parse-buffer))
 	     (info `(:parse-tree ,tree)))
 	(should