forked from mirrors/org-mode
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 <tr>, such as: > > <table class="sample"> > <tr class="d0"><td>One</td><td>Fish</td></tr> > <tr class="d1"><td>Two</td><td>Fish</td></tr> > > <tr class="d0"><td>Red</td><td>Fish</td></tr> > <tr class="d1"><td>Blue</td><td>Fish</td></tr> > </table> > > So, that in the CSS file, it'll be easier to implement the color: > > > <style type="text/css"> > table.sample { > border: 6px inset #8B8378; > -moz-border-radius: 6px; > } > table.sample td { > border: 1px solid black; > padding: 0.2em 2ex 0.2em 2ex; > > color: black; > } > table.sample tr.d0 td { > background-color: #FCF6CF; > } > table.sample tr.d1 td { > background-color: #FEFEF2; > } > </style> 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 "<tr>" (if (= (mod nline 2) 1) "<tr class=\"d1\">" "<tr class=\"d0\">")) "</tr>"))
This commit is contained in:
parent
5406183319
commit
8e34ea7b48
|
@ -1,3 +1,10 @@
|
||||||
|
2009-06-18 Carsten Dominik <carsten.dominik@gmail.com>
|
||||||
|
|
||||||
|
* 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 <carsten.dominik@gmail.com>
|
2009-06-17 Carsten Dominik <carsten.dominik@gmail.com>
|
||||||
|
|
||||||
* org-exp-blocks.el: Declare functions and variables.
|
* org-exp-blocks.el: Declare functions and variables.
|
||||||
|
|
|
@ -283,6 +283,35 @@ This is customizable so that alignment options can be specified."
|
||||||
:group 'org-export-tables
|
:group 'org-export-tables
|
||||||
:type '(cons (string :tag "Opening tag") (string :tag "Closing tag")))
|
:type '(cons (string :tag "Opening tag") (string :tag "Closing tag")))
|
||||||
|
|
||||||
|
(defcustom org-export-table-row-tags '("<tr>" . "</tr>")
|
||||||
|
"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
|
||||||
|
\"<tr>\"
|
||||||
|
(if (= (mod nline 2) 1)
|
||||||
|
\"<tr class=\\\"tr-odd\\\">\"
|
||||||
|
\"<tr class=\\\"tr-even\\\">\"))
|
||||||
|
\"</tr>\"))
|
||||||
|
|
||||||
|
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
|
(defcustom org-export-html-table-use-header-tags-for-first-column nil
|
||||||
"Non-nil means, format column one in tables with header tags.
|
"Non-nil means, format column one in tables with header tags.
|
||||||
When nil, also column one will use data 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))
|
(lambda (x) (string-match "^[ \t]*|-" x))
|
||||||
(cdr lines)))))
|
(cdr lines)))))
|
||||||
|
|
||||||
(nlines 0) fnum i
|
(nline 0) fnum i
|
||||||
tbopen line fields html gr colgropen)
|
tbopen line fields html gr colgropen rowstart rowend)
|
||||||
(if splice (setq head nil))
|
(if splice (setq head nil))
|
||||||
(unless splice (push (if head "<thead>" "<tbody>") html))
|
(unless splice (push (if head "<thead>" "<tbody>") html))
|
||||||
(setq tbopen t)
|
(setq tbopen t)
|
||||||
|
@ -1524,12 +1553,14 @@ lang=\"%s\" xml:lang=\"%s\">
|
||||||
;; Break the line into fields
|
;; Break the line into fields
|
||||||
(setq fields (org-split-string line "[ \t]*|[ \t]*"))
|
(setq fields (org-split-string line "[ \t]*|[ \t]*"))
|
||||||
(unless fnum (setq fnum (make-vector (length fields) 0)))
|
(unless fnum (setq fnum (make-vector (length fields) 0)))
|
||||||
(setq nlines (1+ nlines) i -1)
|
(setq nline (1+ nline) i -1
|
||||||
(push (concat "<tr>"
|
rowstart (eval (car org-export-table-row-tags))
|
||||||
|
rowend (eval (cdr org-export-table-row-tags)))
|
||||||
|
(push (concat rowstart
|
||||||
(mapconcat
|
(mapconcat
|
||||||
(lambda (x)
|
(lambda (x)
|
||||||
(setq i (1+ i))
|
(setq i (1+ i))
|
||||||
(if (and (< i nlines)
|
(if (and (< i nline)
|
||||||
(string-match org-table-number-regexp x))
|
(string-match org-table-number-regexp x))
|
||||||
(incf (aref fnum i)))
|
(incf (aref fnum i)))
|
||||||
(cond
|
(cond
|
||||||
|
@ -1547,7 +1578,7 @@ lang=\"%s\" xml:lang=\"%s\">
|
||||||
(concat (car org-export-table-data-tags) x
|
(concat (car org-export-table-data-tags) x
|
||||||
(cdr org-export-table-data-tags)))))
|
(cdr org-export-table-data-tags)))))
|
||||||
fields "")
|
fields "")
|
||||||
"</tr>")
|
rowend)
|
||||||
html)))
|
html)))
|
||||||
(unless splice (if tbopen (push "</tbody>" html)))
|
(unless splice (if tbopen (push "</tbody>" html)))
|
||||||
(unless splice (push "</table>\n" html))
|
(unless splice (push "</table>\n" html))
|
||||||
|
@ -1560,7 +1591,7 @@ lang=\"%s\" xml:lang=\"%s\">
|
||||||
(lambda (x)
|
(lambda (x)
|
||||||
(setq gr (pop org-table-colgroup-info))
|
(setq gr (pop org-table-colgroup-info))
|
||||||
(format "<col align=\"%s\" />"
|
(format "<col align=\"%s\" />"
|
||||||
(if (> (/ (float x) nlines) org-table-number-fraction)
|
(if (> (/ (float x) nline) org-table-number-fraction)
|
||||||
"right" "left")))
|
"right" "left")))
|
||||||
fnum "")
|
fnum "")
|
||||||
"</colgroup>")
|
"</colgroup>")
|
||||||
|
|
Loading…
Reference in New Issue