Improve export tables. fix #7

This commit is contained in:
IGARASHI Masanao
2015-01-12 22:35:10 +09:00
parent 236f6f256f
commit 9af076436c

View File

@@ -1466,6 +1466,18 @@ contextual information."
;;;; Table ;;;; Table
(defun org-rst-table-first-row-data-cells (table info)
"Transcode the first row of TABLE.
INFO is a plist used as a communication channel."
(let ((table-row
(org-element-map table 'table-row
(lambda (row)
(unless (eq (org-element-property :type row) 'rule) row))
info 'first-match))
(special-column-p (org-export-table-has-special-column-p table)))
(if (not special-column-p) (org-element-contents table-row)
(cdr (org-element-contents table-row)))))
(defun org-rst-table (table contents info) (defun org-rst-table (table contents info)
"Transcode a TABLE element from Org to reStructuredText. "Transcode a TABLE element from Org to reStructuredText.
CONTENTS is the contents of the table. INFO is a plist holding CONTENTS is the contents of the table. INFO is a plist holding
@@ -1487,23 +1499,18 @@ contextual information."
;;;; Table Cell ;;;; Table Cell
(defun org-rst-table-cell (table-cell contents info) (defun org-rst-table-cell (table-cell contents info)
"Transcode a TABLE-CELL object from Org to reStructuredText. "Transcode a TABLE-CELL object from Org to reStructuredText.
CONTENTS is the cell contents. INFO is a plist used as CONTENTS is the cell contents. INFO is a plist used as
a communication channel." a communication channel."
(let ((width (org-ascii--table-cell-width table-cell info))) (let ((width (org-ascii--table-cell-width table-cell info)))
;; When contents are too large, truncate them.
(unless (or org-ascii-table-widen-columns
(<= (string-width contents) width))
(setq contents (concat (substring contents 0 (- width 2)) "=>")))
;; Align contents correctly within the cell. ;; Align contents correctly within the cell.
(let* ((indent-tabs-mode nil) (let* ((indent-tabs-mode nil)
(data (data
(when contents (if contents
(org-ascii--justify-lines (org-ascii--justify-lines
contents width contents width
(org-export-table-cell-alignment table-cell info))))) (org-export-table-cell-alignment table-cell info)) "\\")))
(setq contents (concat data (setq contents (concat data
(make-string (- width (string-width data)) ? )))) (make-string (- width (string-width data)) ? ))))
;; Return cell. ;; Return cell.
@@ -1521,16 +1528,41 @@ a communication channel."
(org-element-map table-row 'table-cell 'identity info t) (org-element-map table-row 'table-cell 'identity info t)
info))) info)))
(if (not (and (memq 'bottom borders) (memq 'top borders))) (if (not (and (memq 'bottom borders) (memq 'top borders)))
(let ((hline (let* ((rowgroup-number (org-export-table-row-group table-row info))
(replace-regexp-in-string "|" "+" (row-number (org-export-table-row-number table-row info))
(replace-regexp-in-string (line-bit
"[^|]" "-" contents)))) (cond
((not (= 1 rowgroup-number))
?-)
((org-export-table-has-header-p
(org-export-get-parent-table table-row) info)
?=)
(t ?-)))
(makeline
(function
(lambda (rowcontents linebit)
(format "+%s+"
(mapconcat
'identity
(mapcar
(lambda (table-cell)
(make-string (string-width table-cell)
linebit))
(split-string contents "|"))
"+")))))
(hline (format "+%s+"
(mapconcat
'identity
(mapcar
(lambda (table-cell)
(make-string (string-width table-cell)
line-bit))
(split-string contents "|"))
"+"))))
(concat (concat
(when (and (memq 'top borders) (memq 'above borders)) (when (= 0 row-number)
(concat "+" hline "+\n")) (concat (funcall makeline contents ?-) "\n"))
"|" contents "|" "|" contents "|\n" hline))
(when (memq 'below borders)
(concat "\n+" hline "+"))))
nil nil
))) )))