From 8e34ea7b48e249386acf26540086bcbb8bca5e1f Mon Sep 17 00:00:00 2001 From: Carsten Dominik Date: Thu, 18 Jun 2009 07:07:22 +0200 Subject: [PATCH] HTML export: Make table row tag customizable Xin Shi writes: > Hello Experts, > > I use org-mode to produce a lot of big tables with numbers in > them. When I present these tables by HTML, I found it's hard to > keep track which row it is. I'm wondering if it's possible to > implement additional class attribute to the , such as: > > > > > > > >
OneFish
TwoFish
RedFish
BlueFish
> > So, that in the CSS file, it'll be easier to implement the color: > > > This commit introduces a new variable `org-export-table-row-tags' that can be used for this and similar purposes. For the example of the poster, one could use: (setq org-export-table-row-tags (cons '(if head "" (if (= (mod nline 2) 1) "" "")) "")) --- lisp/ChangeLog | 7 +++++++ lisp/org-html.el | 45 ++++++++++++++++++++++++++++++++++++++------- 2 files changed, 45 insertions(+), 7 deletions(-) diff --git a/lisp/ChangeLog b/lisp/ChangeLog index ca4e57e95..37cbd2132 100755 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,3 +1,10 @@ +2009-06-18 Carsten Dominik + + * org-html.el (org-export-table-row-tags): New option. + (org-format-org-table-html): Rename `nlines' to `nline', use new + option. + + 2009-06-17 Carsten Dominik * org-exp-blocks.el: Declare functions and variables. diff --git a/lisp/org-html.el b/lisp/org-html.el index 77f820ebc..c02c70ffa 100644 --- a/lisp/org-html.el +++ b/lisp/org-html.el @@ -283,6 +283,35 @@ This is customizable so that alignment options can be specified." :group 'org-export-tables :type '(cons (string :tag "Opening tag") (string :tag "Closing tag"))) +(defcustom org-export-table-row-tags '("" . "") + "The opening tag for table data fields. +This is customizable so that alignment options can be specified. +Instead of strings, these ca be Lisp forms that will be evaluated +for each row in order to construct the table row tags. During evaluation, +the variable `head' will be true when this is a header line, nil when this +is a body line. And the variable `nline' will contain the line number, +starting from 1 in the first header line. For example + + (setq org-export-table-row-tags + (cons '(if head + \"\" + (if (= (mod nline 2) 1) + \"\" + \"\")) + \"\")) + +will give even lines the class \"tr-even\" and odd lines the class \"tr-odd\"." + :group 'org-export-tables + :type '(cons + (choice :tag "Opening tag" + (string :tag "Specify") + (sexp)) + (choice :tag "Closing tag" + (string :tag "Specify") + (sexp)))) + + + (defcustom org-export-html-table-use-header-tags-for-first-column nil "Non-nil means, format column one in tables with header tags. When nil, also column one will use data tags." @@ -1506,8 +1535,8 @@ lang=\"%s\" xml:lang=\"%s\"> (lambda (x) (string-match "^[ \t]*|-" x)) (cdr lines))))) - (nlines 0) fnum i - tbopen line fields html gr colgropen) + (nline 0) fnum i + tbopen line fields html gr colgropen rowstart rowend) (if splice (setq head nil)) (unless splice (push (if head "" "") html)) (setq tbopen t) @@ -1524,12 +1553,14 @@ lang=\"%s\" xml:lang=\"%s\"> ;; Break the line into fields (setq fields (org-split-string line "[ \t]*|[ \t]*")) (unless fnum (setq fnum (make-vector (length fields) 0))) - (setq nlines (1+ nlines) i -1) - (push (concat "" + (setq nline (1+ nline) i -1 + rowstart (eval (car org-export-table-row-tags)) + rowend (eval (cdr org-export-table-row-tags))) + (push (concat rowstart (mapconcat (lambda (x) (setq i (1+ i)) - (if (and (< i nlines) + (if (and (< i nline) (string-match org-table-number-regexp x)) (incf (aref fnum i))) (cond @@ -1547,7 +1578,7 @@ lang=\"%s\" xml:lang=\"%s\"> (concat (car org-export-table-data-tags) x (cdr org-export-table-data-tags))))) fields "") - "") + rowend) html))) (unless splice (if tbopen (push "" html))) (unless splice (push "\n" html)) @@ -1560,7 +1591,7 @@ lang=\"%s\" xml:lang=\"%s\"> (lambda (x) (setq gr (pop org-table-colgroup-info)) (format "" - (if (> (/ (float x) nlines) org-table-number-fraction) + (if (> (/ (float x) nline) org-table-number-fraction) "right" "left"))) fnum "") "")