From 84137f67ed184b6b70c3c353a2868dde41de346a Mon Sep 17 00:00:00 2001 From: Jambunathan K Date: Mon, 25 Apr 2011 23:31:18 +0530 Subject: [PATCH] org-html.el: Handle org-table-export and org-export-as-docbook. * lisp/org-html.el (org-parse-format-table) (org-parse-format-org-table, org-parse-format-table-table) (org-parse-format-table-table-using-table-generate-source) (org-parse-do-format-org-table) (org-parse-do-format-table-table) : New. Genericized versions of table export routines factored out from existing html-specific routines. (org-format-table-html, org-format-org-table-html) (org-format-table-table-html): Bind parser callbacks to html-specific callback routines and call the generic counterparts. (no-css): Renamed to org-html-format-table-no-css (org-html-format-table-no-css): See above. (org-html-end-table): Replace no-css with org-html-format-table-no-css. (org-do-export): Use org-parse-format-table --- contrib/odt/files/test.org | 5 ++- lisp/org-html.el | 97 +++++++++++++++++++++++++++++++++------------- 2 files changed, 74 insertions(+), 28 deletions(-) diff --git a/contrib/odt/files/test.org b/contrib/odt/files/test.org index 18203b8b5..fed054ef1 100644 --- a/contrib/odt/files/test.org +++ b/contrib/odt/files/test.org @@ -514,6 +514,7 @@ |------------+-------------+---------------+--------------| | R5 | R5C1 | R5C2 | R5C3 | | R6 | R6C1 | R6C2 | R6C3 | + | R7 | R7C1 | R7C2 | R7C3 | |------------+-------------+---------------+--------------| *** Table.el Table with no Spanning @@ -535,7 +536,7 @@ |Whole | | +---------------+---------------+ -*** Table.el Table with Spanning :noexport: +*** Table.el Table with Spanning +----------+---------------------+----------+ |Name |cmd calls |Percentage| @@ -547,7 +548,7 @@ |total |203 118 |100% | +----------+---------------------+----------+ -*** Another Table.el Table with Spanning :noexport: +*** Another Table.el Table with Spanning +-----------+----------+ | R1C1 | R1C2 | diff --git a/lisp/org-html.el b/lisp/org-html.el index 2ac730550..e4891eb01 100644 --- a/lisp/org-html.el +++ b/lisp/org-html.el @@ -1489,7 +1489,7 @@ PUB-DIR is set, use this as the publishing directory." table-buffer (nreverse table-buffer) table-orig-buffer (nreverse table-orig-buffer)) (org-parse-end-paragraph) - (insert (org-format-table-html table-buffer table-orig-buffer)))) + (insert (org-parse-format-table table-buffer table-orig-buffer)))) ;; Normal lines @@ -1654,23 +1654,35 @@ PUB-DIR is set, use this as the publishing directory." ;; Following variable is defined for native tables i.e., when ;; `org-table-is-styled' evals to t. -(defvar no-css) +(defvar org-html-format-table-no-css) (defvar org-table-number-regexp) ; defined in org-table.el -(defun org-format-table-html (lines olines &optional no-css) - "Find out which HTML converter to use and return the HTML code. -NO-CSS is passed to the exporter." +(defun org-parse-format-table (lines olines) + "Retuns backend-specific code for org-type and table-type +tables." (if (stringp lines) (setq lines (org-split-string lines "\n"))) (if (string-match "^[ \t]*|" (car lines)) ;; A normal org table - (org-format-org-table-html lines nil no-css) - ;; Table made by table.el - (or (org-format-table-table-html-using-table-generate-source - olines (not org-export-prefer-native-exporter-for-tables)) + (org-parse-format-org-table lines nil) + ;; Table made by table.el + (or (org-parse-format-table-table-using-table-generate-source + org-export-current-backend olines + (not org-export-prefer-native-exporter-for-tables)) ;; We are here only when table.el table has NO col or row ;; spanning and the user prefers using org's own converter for ;; exporting of such simple table.el tables. - (org-format-table-table-html lines)))) + (org-parse-format-table-table lines)))) + +(defun org-format-table-html (lines olines &optional no-css) + "Find out which HTML converter to use and return the HTML code. +NO-CSS is passed to the exporter." + (let* ((org-parse-get-callback 'org-html-get) + (org-parse-entity-control-callbacks-alist + (org-parse-get 'ENTITY-CONTROL)) + (org-parse-entity-format-callbacks-alist + (org-parse-get 'ENTITY-FORMAT)) + (org-html-format-table-no-css no-css)) + (org-parse-format-table lines olines))) (defun org-table-get-colalign-info (lines) (let ((forced-aligns (org-find-text-property-in-string @@ -1691,8 +1703,8 @@ NO-CSS is passed to the exporter." (defvar org-table-colalign-info) (defvar org-table-colalign-vector) (defvar org-table-number-fraction) ; defined in org-table.el -(defun org-do-format-org-table-html (lines &optional splice no-css) - "Format a table into HTML. +(defun org-parse-do-format-org-table (lines &optional splice) + "Format a org-type table into backend-specific code. LINES is a list of lines. Optional argument SPLICE means, do not insert header and surrounding tags, just format the lines. Optional argument NO-CSS means use XHTML attributes instead of CSS @@ -1753,8 +1765,21 @@ for formatting. This is required for the DocBook exporter." (org-parse-end-table))))) (defun org-format-org-table-html (lines &optional splice no-css) + ;; This routine might get called outside of org-export-as-html. For + ;; example, this could happen as part of org-table-export or as part + ;; of org-export-as-docbook. Explicitly bind the parser callback to + ;; the html ones for the duration of the call. + (let* ((org-parse-get-callback 'org-html-get) + (org-parse-entity-control-callbacks-alist + (org-parse-get 'ENTITY-CONTROL)) + (org-parse-entity-format-callbacks-alist + (org-parse-get 'ENTITY-FORMAT)) + (org-html-format-table-no-css no-css)) + (org-parse-format-org-table lines splice))) + +(defun org-parse-format-org-table (lines &optional splice) (with-temp-buffer - (org-do-format-org-table-html lines splice no-css) + (org-parse-do-format-org-table lines splice) (buffer-substring-no-properties (point-min) (point-max)))) (defun org-export-splice-attributes (tag attributes) @@ -1773,8 +1798,8 @@ for formatting. This is required for the DocBook exporter." t t tag))) tag))) -(defun org-do-format-table-table-html (lines) - "Format a table generated by table.el into HTML. +(defun org-parse-do-format-table-table (lines) + "Format a table generated by table.el into backend-specific code. This conversion does *not* use `table-generate-source' from table.el. This has the advantage that Org-mode's HTML conversions can be used. But it has the disadvantage, that no cell- or row-spanning is allowed." @@ -1810,15 +1835,24 @@ But it has the disadvantage, that no cell- or row-spanning is allowed." (setq field-buffer fields))))) (org-parse-end-table))) -(defun org-format-table-table-html (lines) +(defun org-parse-format-table-table (lines) (with-temp-buffer - (org-do-format-table-table-html lines) + (org-parse-do-format-table-table lines) (buffer-substring-no-properties (point-min) (point-max)))) -(defun org-format-table-table-html-using-table-generate-source (lines - &optional - spanned-only) - "Format a table into html, using `table-generate-source' from table.el. +(defun org-format-table-table-html (lines) + (let* ((org-parse-get-callback 'org-html-get) + (org-parse-entity-control-callbacks-alist + (org-parse-get 'ENTITY-CONTROL)) + (org-parse-entity-format-callbacks-alist + (org-parse-get 'ENTITY-FORMAT))) + (org-parse-format-table-table lines))) + +(defun org-parse-format-table-table-using-table-generate-source (backend + lines + &optional + spanned-only) + "Format a table into BACKEND, using `table-generate-source' from table.el. Use SPANNED-ONLY to suppress exporting of simple table.el tables. When SPANNED-ONLY is nil, all table.el tables are exported. When @@ -1842,9 +1876,18 @@ for further information." (c (nth 4 dim)) (r (nth 5 dim)) (cells (nth 6 dim))) (not (= (* c r) cells)))) (with-current-buffer (get-buffer-create " org-tmp2 ") (erase-buffer)) - (table-generate-source 'html " org-tmp2 ") - (set-buffer " org-tmp2 ") - (buffer-substring (point-min) (point-max))))) + (cond + ((member backend table-source-languages) + (table-generate-source backend " org-tmp2 ") + (set-buffer " org-tmp2 ") + (buffer-substring (point-min) (point-max))) + (t + ;; table.el doesn't support the given backend. Currently this + ;; happens in case of odt export. Strip the table from the + ;; generated document. A better alternative would be to embed + ;; the table as ascii text in the output document. + (org-odt-warn "Don't know how to export table.el table!") + ""))))) (defun org-export-splice-style (style extra) "Splice EXTRA into STYLE, just before \"\"." @@ -2952,7 +2995,8 @@ When TITLE is nil, just close all open levels." "") (let* ((align (aref org-table-colalign-vector c)) - (alignspec (if no-css " align=\"%s\"" " class=\"%s\"")) + (alignspec (if org-html-format-table-no-css + " align=\"%s\"" " class=\"%s\"")) (extra (format alignspec align))) (format "" extra)) @@ -2968,7 +3012,8 @@ When TITLE is nil, just close all open levels." (let ((c (string-to-number (match-string 1)))) (replace-match (if org-export-html-table-align-individual-fields - (format (if no-css " align=\"%s\"" " class=\"%s\"") + (format (if org-html-format-table-no-css " align=\"%s\"" + " class=\"%s\"") (or (aref org-table-colalign-vector c) "left")) "") t t))) (goto-char (point-max))) -- 2.11.4.GIT