contrib/lisp/org-export: Extract more properties from tables

* contrib/lisp/org-export.el (org-export-table-format-info): Extract
column width and and row groups.
This commit is contained in:
Nicolas Goaziou 2011-12-07 17:39:51 +01:00
parent 92d305092a
commit b377e54c6a
1 changed files with 26 additions and 14 deletions

View File

@ -2466,23 +2466,31 @@ Return new code as a string."
"Extract info from TABLE. "Extract info from TABLE.
Return a plist whose properties and values are: Return a plist whose properties and values are:
`:alignment' vector of strings among \"r\", \"l\" and \"c\", `:alignment' vector of strings among \"r\", \"l\" and \"c\",
`:column-groups' vector of symbols among `start', `end', `startend', `:column-groups' vector of symbols among `start', `end', `start-end',
`:special-column-p' boolean." `:row-groups' list of integers representing row groups.
`:special-column-p' non-nil if table has a special column.
`:width' vector of integers representing desired width of
current column, or nil."
(with-temp-buffer (with-temp-buffer
(insert table) (insert table)
(goto-char 1) (goto-char 1)
(org-table-align) (org-table-align)
(let ((align (vconcat (mapcar (lambda (c) (if c "r" "l")) (let ((align (vconcat (mapcar (lambda (c) (if c "r" "l"))
org-table-last-alignment))) org-table-last-alignment)))
(width (make-vector (length org-table-last-alignment) nil))
(colgroups (make-vector (length org-table-last-alignment) nil)) (colgroups (make-vector (length org-table-last-alignment) nil))
(row-group 0)
(rowgroups)
(special-column-p 'empty)) (special-column-p 'empty))
(mapc (lambda (row) (mapc (lambda (row)
(if (string-match "^[ \t]*|[-+]+|[ \t]*$" row)
(incf row-group)
(push row-group rowgroups)
;; Determine if a special column is present by looking ;; Determine if a special column is present by looking
;; for special markers in the first column. More ;; for special markers in the first column. More
;; accurately, the first column is considered special if ;; accurately, the first column is considered special
;; it only contains special markers and, maybe, empty ;; if it only contains special markers and, maybe,
;; cells. ;; empty cells.
(unless (string-match "^[ \t]*|[-+]+|[ \t]*$" row)
(setq special-column-p (setq special-column-p
(cond (cond
((not special-column-p) nil) ((not special-column-p) nil)
@ -2490,13 +2498,15 @@ Return a plist whose properties and values are:
row) 'special) row) 'special)
((string-match "^[ \t]*| +|" row) special-column-p)))) ((string-match "^[ \t]*| +|" row) special-column-p))))
(cond (cond
;; Read forced alignment and width information, if any,
;; and determine final alignment for the table.
((org-table-cookie-line-p row) ((org-table-cookie-line-p row)
;; Read forced alignment information, if any, and
;; determine final alignment for the table.
(let ((col 0)) (let ((col 0))
(mapc (lambda (field) (mapc (lambda (field)
(when (string-match "<\\([lrc]\\)[0-9]*>" field) (when (string-match "<\\([lrc]\\)\\([0-9]+\\)?>" field)
(aset align col (match-string 1 field))) (aset align col (match-string 1 field))
(aset width col (let ((w (match-string 2 field)))
(and w (string-to-number w)))))
(incf col)) (incf col))
(org-split-string row "[ \t]*|[ \t]*")))) (org-split-string row "[ \t]*|[ \t]*"))))
;; Read column groups information. ;; Read column groups information.
@ -2513,7 +2523,9 @@ Return a plist whose properties and values are:
;; Return plist. ;; Return plist.
(list :alignment align (list :alignment align
:column-groups colgroups :column-groups colgroups
:special-column-p (eq special-column-p 'special))))) :row-groups (reverse rowgroups)
:special-column-p (eq special-column-p 'special)
:width width))))
(defun org-export-clean-table (table specialp) (defun org-export-clean-table (table specialp)
"Clean string TABLE from its formatting elements. "Clean string TABLE from its formatting elements.