Function: org-export-table-cell-borders

org-export-table-cell-borders is a byte-compiled function defined in ox.el.gz.

Signature

(org-export-table-cell-borders TABLE-CELL INFO)

Documentation

Return TABLE-CELL borders.

INFO is a plist used as a communication channel.

Return value is a list of symbols, or nil. Possible values are: top, bottom, above, below, left and right. Note: top (resp. bottom) only happen for a cell in the first row (resp. last row) of the table, ignoring table rules, if any.

Returned borders ignore special rows.

Source Code

;; Defined in /usr/src/emacs/lisp/org/ox.el.gz
(defun org-export-table-cell-borders (table-cell info)
  "Return TABLE-CELL borders.

INFO is a plist used as a communication channel.

Return value is a list of symbols, or nil.  Possible values are:
`top', `bottom', `above', `below', `left' and `right'.  Note:
`top' (resp. `bottom') only happen for a cell in the first
row (resp. last row) of the table, ignoring table rules, if any.

Returned borders ignore special rows."
  (let* ((row (org-element-parent table-cell))
	 (table (org-element-lineage table-cell 'table))
	 borders)
    ;; Top/above border?  TABLE-CELL has a border above when a rule
    ;; used to demarcate row groups can be found above.  Hence,
    ;; finding a rule isn't sufficient to push `above' in BORDERS:
    ;; another regular row has to be found above that rule.
    (let (rule-flag)
      (catch 'exit
	;; Look at every row before the current one.
	(dolist (row (cdr (memq row (reverse (org-element-contents table)))))
	  (cond ((eq (org-element-property :type row) 'rule)
		 (setq rule-flag t))
		((not (org-export-table-row-is-special-p row info))
		 (if rule-flag (throw 'exit (push 'above borders))
		   (throw 'exit nil)))))
	;; No rule above, or rule found starts the table (ignoring any
	;; special row): TABLE-CELL is at the top of the table.
	(when rule-flag (push 'above borders))
	(push 'top borders)))
    ;; Bottom/below border? TABLE-CELL has a border below when next
    ;; non-regular row below is a rule.
    (let (rule-flag)
      (catch 'exit
	;; Look at every row after the current one.
	(dolist (row (cdr (memq row (org-element-contents table))))
	  (cond ((eq (org-element-property :type row) 'rule)
		 (setq rule-flag t))
		((not (org-export-table-row-is-special-p row info))
		 (if rule-flag (throw 'exit (push 'below borders))
		   (throw 'exit nil)))))
	;; No rule below, or rule found ends the table (modulo some
	;; special row): TABLE-CELL is at the bottom of the table.
	(when rule-flag (push 'below borders))
	(push 'bottom borders)))
    ;; Right/left borders?  They can only be specified by column
    ;; groups.  Column groups are defined in a row starting with "/".
    ;; Also a column groups row only contains "<", "<>", ">" or blank
    ;; cells.
    (catch 'exit
      (let ((column (let ((cells (org-element-contents row)))
		      (- (length cells) (length (memq table-cell cells))))))
	;; Table rows are read in reverse order so last column groups
	;; row has precedence over any previous one.
	(dolist (row (reverse (org-element-contents table)))
	  (unless (eq (org-element-property :type row) 'rule)
	    (when (equal (org-element-contents
			  (car (org-element-contents row)))
			 '("/"))
	      (let ((column-groups
		     (mapcar
		      (lambda (cell)
			(let ((value (org-element-contents cell)))
			  (when (member value '(("<") ("<>") (">") nil))
			    (car value))))
		      (org-element-contents row))))
		;; There's a left border when previous cell, if
		;; any, ends a group, or current one starts one.
		(when (or (and (not (zerop column))
			       (member (elt column-groups (1- column))
				       '(">" "<>")))
			  (member (elt column-groups column) '("<" "<>")))
		  (push 'left borders))
		;; There's a right border when next cell, if any,
		;; starts a group, or current one ends one.
		(when (or (and (/= (1+ column) (length column-groups))
			       (member (elt column-groups (1+ column))
				       '("<" "<>")))
			  (member (elt column-groups column) '(">" "<>")))
		  (push 'right borders))
		(throw 'exit nil)))))))
    ;; Return value.
    borders))