Improve export tables. fix #7
This commit is contained in:
76
ox-rst.el
76
ox-rst.el
@@ -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.
|
||||||
@@ -1518,21 +1525,46 @@ a communication channel."
|
|||||||
CONTENTS is the row contents. INFO is a plist used as
|
CONTENTS is the row contents. INFO is a plist used as
|
||||||
a communication channel."
|
a communication channel."
|
||||||
(let ((borders (org-export-table-cell-borders
|
(let ((borders (org-export-table-cell-borders
|
||||||
(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
|
||||||
(concat
|
((not (= 1 rowgroup-number))
|
||||||
(when (and (memq 'top borders) (memq 'above borders))
|
?-)
|
||||||
(concat "+" hline "+\n"))
|
((org-export-table-has-header-p
|
||||||
"|" contents "|"
|
(org-export-get-parent-table table-row) info)
|
||||||
(when (memq 'below borders)
|
?=)
|
||||||
(concat "\n+" hline "+"))))
|
(t ?-)))
|
||||||
nil
|
(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
|
||||||
|
(when (= 0 row-number)
|
||||||
|
(concat (funcall makeline contents ?-) "\n"))
|
||||||
|
"|" contents "|\n" hline))
|
||||||
|
nil
|
||||||
|
)))
|
||||||
|
|
||||||
|
|
||||||
;;;; Target
|
;;;; Target
|
||||||
|
|||||||
Reference in New Issue
Block a user