summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Goaziou <n.goaziou@gmail.com>2012-05-03 14:29:30 +0200
committerNicolas Goaziou <n.goaziou@gmail.com>2012-05-03 14:29:30 +0200
commit01d83dc1f4880717c149181a0f8d7975bfc9e172 (patch)
tree87fedda572834179dda5e4c27e28cfde81beb680
parentf4791557e2a1e10f6a8aaadfb94b93372a70e969 (diff)
downloadorg-mode-01d83dc1f4880717c149181a0f8d7975bfc9e172.tar.gz
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.
-rw-r--r--contrib/lisp/org-export.el38
-rw-r--r--testing/lisp/test-org-export.el8
2 files changed, 27 insertions, 19 deletions
diff --git a/contrib/lisp/org-export.el b/contrib/lisp/org-export.el
index 4d4adc0..c2ef8b8 100644
--- a/contrib/lisp/org-export.el
+++ b/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))))))
diff --git a/testing/lisp/test-org-export.el b/testing/lisp/test-org-export.el
index 244d0df..82002e2 100644
--- a/testing/lisp/test-org-export.el
+++ b/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