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.
This commit is contained in:
Nicolas Goaziou 2014-08-26 15:05:52 +02:00
parent 81906c52ae
commit d47f66d6d0
2 changed files with 35 additions and 11 deletions

View File

@ -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.

View File

@ -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