From d9a03c553a1b9ee72afc5f0c35428b96e55a5e1c Mon Sep 17 00:00:00 2001 From: Carsten Dominik Date: Tue, 31 Mar 2009 13:00:34 +0200 Subject: [PATCH] HTML export: Allow modification of table attributes. The #+ATTR_HTML line can now be used to set attributes for the following table. --- doc/org.texi | 21 +++++++++++++++++++-- lisp/ChangeLog | 6 ++++++ lisp/org-exp.el | 47 +++++++++++++++++++++++++++++++++++------------ lisp/org.el | 9 ++++++++- 4 files changed, 68 insertions(+), 15 deletions(-) diff --git a/doc/org.texi b/doc/org.texi index 42f2b7ca0..1f3381f4a 100644 --- a/doc/org.texi +++ b/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 diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 4ce7c8791..c21e64aea 100755 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,3 +1,9 @@ +2009-03-31 Carsten Dominik + + * org.el (org-extract-attributes-from-string): New function. + + * org-exp.el (org-export-splice-attributes): New function. + 2009-03-30 Carsten Dominik * org-mouse.el: XEmacs compatibility fixes diff --git a/lisp/org-exp.el b/lisp/org-exp.el index df0cab210..d2775f9b9 100644 --- a/lisp/org-exp.el +++ b/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 "" "") 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." diff --git a/lisp/org.el b/lisp/org.el index 2671dff2c..efdb7d294 100644 --- a/lisp/org.el +++ b/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) -- 2.11.4.GIT