From d47f66d6d06407eb9022afe9e44dc20df7266487 Mon Sep 17 00:00:00 2001 From: Nicolas Goaziou Date: Tue, 26 Aug 2014 15:05:52 +0200 Subject: [PATCH] ox: Implement `org-export-table-row-in-header-p' * lisp/ox.el (org-export-table-row-in-header-p): New function. (org-export-table-row-starts-header-p, org-export-table-row-ends-header-p): Use new function. * testing/lisp/test-ox.el (test-org-export/table-row-in-header-p): New test. --- lisp/ox.el | 27 ++++++++++++++++----------- testing/lisp/test-ox.el | 19 +++++++++++++++++++ 2 files changed, 35 insertions(+), 11 deletions(-) diff --git a/lisp/ox.el b/lisp/ox.el index 72aafa27e..0c0b275ef 100644 --- a/lisp/ox.el +++ b/lisp/ox.el @@ -4434,9 +4434,10 @@ code." ;; `org-export-table-cell-ends-colgroup-p', ;; `org-export-table-row-starts-rowgroup-p', ;; `org-export-table-row-ends-rowgroup-p', -;; `org-export-table-row-starts-header-p' and -;; `org-export-table-row-ends-header-p' indicate position of current -;; row or cell within the table. +;; `org-export-table-row-starts-header-p', +;; `org-export-table-row-ends-header-p' and +;; `org-export-table-row-in-header-p' indicate position of current row +;; or cell within the table. (defun org-export-table-has-special-column-p (table) "Non-nil when TABLE has a special column. @@ -4790,21 +4791,25 @@ INFO is a plist used as a communication channel." (car (org-element-contents table-row)) info))) (or (memq 'bottom borders) (memq 'below borders))))) +(defun org-export-table-row-in-header-p (table-row info) + "Non-nil when TABLE-ROW is located within table's header. +INFO is a plist used as a communication channel. Always return +nil for special rows and rows separators." + (and (org-export-table-has-header-p + (org-export-get-parent-table table-row) info) + (eql (org-export-table-row-group table-row info) 1))) + (defun org-export-table-row-starts-header-p (table-row info) "Non-nil when TABLE-ROW is the first table header's row. INFO is a plist used as a communication channel." - (and (org-export-table-has-header-p - (org-export-get-parent-table table-row) info) - (org-export-table-row-starts-rowgroup-p table-row info) - (= (org-export-table-row-group table-row info) 1))) + (and (org-export-table-row-in-header-p table-row info) + (org-export-table-row-starts-rowgroup-p table-row info))) (defun org-export-table-row-ends-header-p (table-row info) "Non-nil when TABLE-ROW is the last table header's row. INFO is a plist used as a communication channel." - (and (org-export-table-has-header-p - (org-export-get-parent-table table-row) info) - (org-export-table-row-ends-rowgroup-p table-row info) - (= (org-export-table-row-group table-row info) 1))) + (and (org-export-table-row-in-header-p table-row info) + (org-export-table-row-ends-rowgroup-p table-row info))) (defun org-export-table-row-number (table-row info) "Return TABLE-ROW number. diff --git a/testing/lisp/test-ox.el b/testing/lisp/test-ox.el index e9029581a..e67ee95ff 100644 --- a/testing/lisp/test-ox.el +++ b/testing/lisp/test-ox.el @@ -2912,6 +2912,25 @@ Another text. (ref:text) (if (org-export-table-row-ends-rowgroup-p row info) 'yes 'no)) info))))) +(ert-deftest test-org-export/table-row-in-header-p () + "Test `org-export-table-row-in-header-p' specifications." + ;; Standard test. Separators are always nil. + (should + (equal + '(yes no no) + (org-test-with-parsed-data "| a |\n|---|\n| b |" + (org-element-map tree 'table-row + (lambda (row) + (if (org-export-table-row-in-header-p row info) 'yes 'no)) info)))) + ;; Nil when there is no header. + (should + (equal + '(no no) + (org-test-with-parsed-data "| a |\n| b |" + (org-element-map tree 'table-row + (lambda (row) + (if (org-export-table-row-in-header-p row info) 'yes 'no)) info))))) + (ert-deftest test-org-export/table-row-starts-header-p () "Test `org-export-table-row-starts-header-p' specifications." ;; 1. Only the row starting the first row group starts the table