Browse Source

HTML export: Allow modification of table attributes.

The #+ATTR_HTML line can now be used to set attributes for the
following table.
Carsten Dominik 16 years ago
parent
commit
d9a03c553a
4 changed files with 68 additions and 15 deletions
  1. 19 2
      doc/org.texi
  2. 6 0
      lisp/ChangeLog
  3. 35 12
      lisp/org-exp.el
  4. 8 1
      lisp/org.el

+ 19 - 2
doc/org.texi

@@ -323,6 +323,7 @@ HTML export
 * HTML Export commands::        How to invoke HTML export
 * Quoting HTML tags::           Using direct HTML in Org mode
 * Links::                       Transformation of links for HTML
+* Tables in HTML export::       How to modify the formatting of tables
 * Images in HTML export::       How to insert figures into HTML output
 * Text areas in HTML export::   An alternative way to show an example
 * CSS support::                 Changing the appearance of the output
@@ -8314,6 +8315,7 @@ language, but with additional support for tables.
 * HTML Export commands::        How to invoke HTML export
 * Quoting HTML tags::           Using direct HTML in Org mode
 * Links::                       Transformation of links for HTML
+* Tables in HTML export::       How to modify the formatting of tables
 * Images in HTML export::       How to insert figures into HTML output
 * Text areas in HTML export::   An alternative way to show an example
 * CSS support::                 Changing the appearance of the output
@@ -8403,7 +8405,7 @@ All lines between these markers are exported literally
 @end example
 
 
-@node Links, Images in HTML export, Quoting HTML tags, HTML export
+@node Links, Tables in HTML export, Quoting HTML tags, HTML export
 @subsection Links
 
 @cindex links, in HTML export
@@ -8429,7 +8431,22 @@ and @code{style} attributes for a link:
 [[http://orgmode.org]]
 @end example
 
-@node Images in HTML export, Text areas in HTML export, Links, HTML export
+@node Tables in HTML export, Images in HTML export, Links, HTML export
+@subsection Tables
+@cindex tables, in HTML
+@vindex org-export-html-table-tag
+
+Org-mode tables are exported to HTML using the table tag defined in
+@code{org-export-html-table-tag}.  The default setting makes tables without
+cell borders and frame.  If you would like to change this for individual
+tables, place somthing like the following before the table:
+
+@example
+#+CAPTION: This is a table with lines around and between cells
+#+ATTR_HTML: border="2" rules="all" frame="all"
+@end example
+
+@node Images in HTML export, Text areas in HTML export, Tables in HTML export, HTML export
 @subsection Images
 
 @cindex images, inline in HTML

+ 6 - 0
lisp/ChangeLog

@@ -1,3 +1,9 @@
+2009-03-31  Carsten Dominik  <carsten.dominik@gmail.com>
+
+	* org.el (org-extract-attributes-from-string): New function.
+
+	* org-exp.el (org-export-splice-attributes): New function.
+
 2009-03-30  Carsten Dominik  <carsten.dominik@gmail.com>
 
 	* org-mouse.el: XEmacs compatibility fixes

+ 35 - 12
lisp/org-exp.el

@@ -4403,18 +4403,25 @@ lang=\"%s\" xml:lang=\"%s\">
     ;; column and the special lines
     (setq lines (org-table-clean-before-export lines)))
 
-  (let ((caption (or (get-text-property 0 'org-caption (car lines))
-		     (get-text-property (or (next-single-property-change
-					     0 'org-caption (car lines))
-					    0)
-					'org-caption (car lines))))
-	(head (and org-export-highlight-first-table-line
-		   (delq nil (mapcar
-			      (lambda (x) (string-match "^[ \t]*|-" x))
-			      (cdr lines)))))
-
-	(nlines 0) fnum i
-	tbopen line fields html gr colgropen)
+  (let* ((caption (or (get-text-property 0 'org-caption (car lines))
+		      (get-text-property (or (next-single-property-change
+					      0 'org-caption (car lines))
+					     0)
+					 'org-caption (car lines))))
+	 (attributes (or (get-text-property 0 'org-attributes (car lines))
+			 (get-text-property (or (next-single-property-change
+						 0 'org-attributes (car lines))
+						0)
+					    'org-attributes (car lines))))
+	 (html-table-tag (org-export-splice-attributes
+			  html-table-tag attributes))
+	 (head (and org-export-highlight-first-table-line
+		    (delq nil (mapcar
+			       (lambda (x) (string-match "^[ \t]*|-" x))
+			       (cdr lines)))))
+	 
+	 (nlines 0) fnum i
+	 tbopen line fields html gr colgropen)
     (if splice (setq head nil))
     (unless splice (push (if head "<thead>" "<tbody>") html))
     (setq tbopen t)
@@ -4476,6 +4483,22 @@ lang=\"%s\" xml:lang=\"%s\">
       (push html-table-tag html))
     (concat (mapconcat 'identity html "\n") "\n")))
 
+(defun org-export-splice-attributes (tag attributes)
+  "Read attributes in string ATTRIBUTES, add and replace in HTML tag TAG."
+  (if (not attributes)
+      tag
+    (let (oldatt newatt)
+      (setq oldatt (org-extract-attributes-from-string tag)
+	    tag (pop oldatt)
+	    newatt (cdr (org-extract-attributes-from-string attributes)))
+      (while newatt
+	(setq oldatt (plist-put oldatt (pop newatt) (pop newatt))))
+      (if (string-match ">" tag)
+	  (setq tag
+		(replace-match (concat (org-attributes-to-string oldatt) ">")
+			       t t tag)))
+      tag)))
+
 (defun org-table-clean-before-export (lines &optional maybe-quoted)
   "Check if the table has a marking column.
 If yes remove the column and the special lines."

+ 8 - 1
lisp/org.el

@@ -7293,7 +7293,6 @@ used as the link location instead of reading one interactively."
 	       (cddr args)))
     (apply 'completing-read args)))
 
-
 (defun org-extract-attributes (s)
   "Extract the attributes cookie from a string and set as text property."
   (let (a attr (start 0) key value)
@@ -7307,6 +7306,14 @@ used as the link location instead of reading one interactively."
       (org-add-props s nil 'org-attr attr))
     s))
 
+(defun org-extract-attributes-from-string (tag)
+  (let (key value attr)
+    (while (string-match "\\([a-zA-Z]+\\)=\"\\([^\"]*\\)\"\\s-?" tag)
+      (setq key (match-string 1 tag) value (match-string 2 tag)
+	    tag (replace-match "" t t tag)
+	    attr (plist-put attr (intern key) value)))
+    (cons tag attr)))
+
 (defun org-attributes-to-string (plist)
   "Format a property list into an HTML attribute list."
   (let ((s "") key value)