ox-html: Fix org-html-table-row wrt lexical binding

* lisp/ox-html.el (org-html-table-row-open-tag):
(org-html-table-row-close-tag): New variables.
(org-html-table-row-tags): Remove variable.

(org-html-table-row): Use new variables.
This commit is contained in:
Fabrice Popineau 2016-02-03 00:10:24 +01:00 committed by Nicolas Goaziou
parent cd9856cc76
commit 6af83e0aa7
2 changed files with 76 additions and 55 deletions

View File

@ -248,10 +248,12 @@ plain list.
fixltx2e is obsolete, see LaTeX News 22.
** Miscellaneous
*** Beamer export back-ends uses ~org-latex-prefer-user-labels~
*** ~:preparation-function~ called earlier during publishing
Functions in this list are called before any file is associated to the
current projet. Thus, they can be used to generate to be published
Org files.
*** Function ~org-remove-indentation~ changes.
The new algorithm doesn't remove TAB characters not used for
indentation.
@ -267,12 +269,20 @@ Note that only ~%(...)~ placeholders initially present in the
template, or introduced using a file placeholder, i.e., ~%[...]~ are
expanded. This prevents evaluating potentially malicious code when
another placeholder, e.g., ~%i~ expands to a S-exp.
*** Links stored by ~org-gnus-store-link~ in nnir groups
Since gnus nnir groups are temporary, ~org-gnus-store-link~ now refers
to the article's original group.
*** ~org-babel-check-confirm-evaluate~ is now a function instead of a macro
The calling convention has changed.
*** HTML export table row customization changes
Variable ~org-html-table-row-tags~ has been split into
~org-html-table-row-open-tag~ and ~org-html-table-row-close-tag~.
Both new variables can be either a string or a function which will be
called with 6 parameters.
* Version 8.3
** Incompatible changes

View File

@ -170,7 +170,8 @@
(:html-viewport nil nil org-html-viewport)
(:html-inline-images nil nil org-html-inline-images)
(:html-table-attributes nil nil org-html-table-default-attributes)
(:html-table-row-tags nil nil org-html-table-row-tags)
(:html-table-row-open-tag nil nil org-html-table-row-open-tag)
(:html-table-row-close-tag nil nil org-html-table-row-close-tag)
(:html-xml-declaration nil nil org-html-xml-declaration)
(:infojs-opt "INFOJS_OPT" nil nil)
;; Redefine regular options.
@ -859,43 +860,50 @@ See also the variable `org-html-table-align-individual-fields'."
:group 'org-export-html
:type '(cons (string :tag "Opening tag") (string :tag "Closing tag")))
(defcustom org-html-table-row-tags '("<tr>" . "</tr>")
"The opening and ending tags for table rows.
(defcustom org-html-table-row-open-tag "<tr>"
"The opening tag for table rows.
This is customizable so that alignment options can be specified.
Instead of strings, these can be Lisp forms that will be
Instead of strings, these can be a Lisp function that will be
evaluated for each row in order to construct the table row tags.
During evaluation, these variables will be dynamically bound so that
you can reuse them:
The function will be called with these arguments:
`row-number': row number (0 is the first row)
`rowgroup-number': group number of current row
`start-rowgroup-p': non-nil means the row starts a group
`end-rowgroup-p': non-nil means the row ends a group
`top-row-p': non-nil means this is the top row
`bottom-row-p': non-nil means this is the bottom row
`number': row number (0 is the first row)
`group-number': group number of current row
`start-group-p': non-nil means the row starts a group
`end-group-p': non-nil means the row ends a group
`topp': non-nil means this is the top row
`bottomp': non-nil means this is the bottom row
For example:
\(setq org-html-table-row-tags
(cons \\='(cond (top-row-p \"<tr class=\\\"tr-top\\\">\")
(bottom-row-p \"<tr class=\\\"tr-bottom\\\">\")
(t (if (= (mod row-number 2) 1)
\"<tr class=\\\"tr-odd\\\">\"
\"<tr class=\\\"tr-even\\\">\")))
\"</tr>\"))
\(setq org-html-table-row-open-tag
\(lambda (number group-number start-group-p end-group-p topp bottomp)
\(cond (topp \"<tr class=\\\"tr-top\\\">\")
\(bottomp \"<tr class=\\\"tr-bottom\\\">\")
\(t (if (= (mod number 2) 1)
\"<tr class=\\\"tr-odd\\\">\"
\"<tr class=\\\"tr-even\\\">\")))))
will use the \"tr-top\" and \"tr-bottom\" classes for the top row
and the bottom row, and otherwise alternate between \"tr-odd\" and
\"tr-even\" for odd and even rows."
:group 'org-export-html
:type '(cons
(choice :tag "Opening tag"
(string :tag "Specify")
(sexp))
(choice :tag "Closing tag"
(string :tag "Specify")
(sexp))))
:type '(choice :tag "Opening tag"
(string :tag "Specify")
(function)))
(defcustom org-html-table-row-close-tag "</tr>"
"The closing tag for table rows.
This is customizable so that alignment options can be specified.
Instead of strings, this can be a Lisp function that will be
evaluated for each row in order to construct the table row tags.
See documentation of `org-html-table-row-open-tag'."
:group 'org-export-html
:type '(choice :tag "Closing tag"
(string :tag "Specify")
(function)))
(defcustom org-html-table-align-individual-fields t
"Non-nil means attach style attributes for alignment to each table field.
@ -3302,42 +3310,45 @@ communication channel."
;; Rules are ignored since table separators are deduced from
;; borders of the current row.
(when (eq (org-element-property :type table-row) 'standard)
(let* ((rowgroup-number (org-export-table-row-group table-row info))
(row-number (org-export-table-row-number table-row info))
(start-rowgroup-p
(let* ((group (org-export-table-row-group table-row info))
(number (org-export-table-row-number table-row info))
(start-group-p
(org-export-table-row-starts-rowgroup-p table-row info))
(end-rowgroup-p
(end-group-p
(org-export-table-row-ends-rowgroup-p table-row info))
;; `top-row-p' and `end-rowgroup-p' are not used directly
;; but should be set so that `org-html-table-row-tags' can
;; use them (see the docstring of this variable.)
(top-row-p (and (equal start-rowgroup-p '(top))
(equal end-rowgroup-p '(below top))))
(bottom-row-p (and (equal start-rowgroup-p '(above))
(equal end-rowgroup-p '(bottom above))))
(rowgroup-tags
(topp (and (equal start-group-p '(top))
(equal end-group-p '(below top))))
(bottomp (and (equal start-group-p '(above))
(equal end-group-p '(bottom above))))
(row-open-tag
(pcase (plist-get info :html-table-row-open-tag)
((and accessor (pred functionp))
(funcall accessor
number group start-group-p end-group-p topp bottomp))
(accessor accessor)))
(row-close-tag
(pcase (plist-get info :html-table-row-close-tag)
((and accessor (pred functionp))
(funcall accessor
number group start-group-p end-group-p topp bottomp))
(accessor accessor)))
(group-tags
(cond
;; Case 1: Row belongs to second or subsequent rowgroups.
((not (= 1 rowgroup-number))
'("<tbody>" . "\n</tbody>"))
;; Case 2: Row is from first rowgroup. Table has >=1 rowgroups.
;; Row belongs to second or subsequent groups.
((not (= 1 group)) '("<tbody>" . "\n</tbody>"))
;; Row is from first group. Table has >=1 groups.
((org-export-table-has-header-p
(org-export-get-parent-table table-row) info)
'("<thead>" . "\n</thead>"))
;; Case 2: Row is from first and only row group.
;; Row is from first and only group.
(t '("<tbody>" . "\n</tbody>")))))
;; Silence byte-compiler.
bottom-row-p top-row-p row-number
(concat
;; Begin a rowgroup?
(when start-rowgroup-p (car rowgroup-tags))
;; Actual table row.
(concat "\n" (eval (car (plist-get info :html-table-row-tags)) t)
contents
"\n"
(eval (cdr (plist-get info :html-table-row-tags)) t))
;; End a rowgroup?
(when end-rowgroup-p (cdr rowgroup-tags))))))
(concat (and start-group-p (car group-tags))
(concat "\n"
row-open-tag
contents
"\n"
row-close-tag)
(and end-group-p (cdr group-tags))))))
;;;; Table