Browse Source

HTML export: Use forced alignment like <l> or <r> in tables

* lisp/org-table.el (org-table-cookie-line-p): Fix indentation.
* lisp/org-exp.el (org-store-forced-table-alignment): New function.
(org-export-preprocess-string): Call `org-store-forced-table-alignment'.
* lisp/org-html.el (org-format-org-table-html): Use stored
alignment information.
Carsten Dominik 10 years ago
parent
commit
7712d78ab4
3 changed files with 47 additions and 10 deletions
  1. 25 2
      lisp/org-exp.el
  2. 13 4
      lisp/org-html.el
  3. 9 4
      lisp/org-table.el

+ 25 - 2
lisp/org-exp.el

@@ -1168,7 +1168,8 @@ on this string to produce the exported version."
       (when (plist-get parameters :emph-multiline)
 	(org-export-concatenate-multiline-emphasis))
 
-      ;; Remove special table lines
+      ;; Remove special table lines, and store alignment information
+      (org-store-forced-table-alignment)
       (when org-export-table-remove-special-lines
 	(org-export-remove-special-table-lines))
 
@@ -1773,8 +1774,30 @@ When it is nil, all comments will be removed."
 	  (org-if-unprotected
 	   (replace-match "\\1[[\\2]]")))))))
 
+(defun org-store-forced-table-alignment ()
+  "Find table lines which force alignment, store the results in properties."
+  (let (line)
+    (goto-char (point-min))
+    (while (re-search-forward "|[ \t]*<[rl][0-9]*>[ \t]*|" nil t)
+      ;; OK, this looks like a table line with an alignment cookie
+      (org-if-unprotected
+       (setq line (buffer-substring (point-at-bol) (point-at-eol)))
+       (when (and (org-at-table-p)
+		  (org-table-cookie-line-p line))
+	 (setq cnt 0 aligns nil)
+	 (mapcar
+	  (lambda (x)
+	    (setq cnt (1+ cnt))
+	    (if (string-match "\\`<\\([lr]\\)" x)
+		(push (cons cnt (downcase (match-string 1 x))) aligns)))
+	  (org-split-string line "[ \t]*|[ \t]*"))
+	 (add-text-properties (org-table-begin) (org-table-end)
+			      (list 'org-forced-aligns aligns))))
+      (goto-char (point-at-eol)))))
+
 (defun org-export-remove-special-table-lines ()
-  "Remove tables lines that are used for internal purposes."
+  "Remove tables lines that are used for internal purposes.
+Also, store forcedalignment information found in such lines."
   (goto-char (point-min))
   (while (re-search-forward "^[ \t]*|" nil t)
     (org-if-unprotected-at (1- (point))

+ 13 - 4
lisp/org-html.el

@@ -1859,6 +1859,8 @@ lang=\"%s\" xml:lang=\"%s\">
 
   (let* ((caption (org-find-text-property-in-string 'org-caption (car lines)))
 	 (label (org-find-text-property-in-string 'org-label (car lines)))
+	 (forced-aligns (org-find-text-property-in-string 'org-forced-aligns
+							  (car lines)))
 	 (attributes (org-find-text-property-in-string 'org-attributes
 						       (car lines)))
 	 (html-table-tag (org-export-splice-attributes
@@ -1868,9 +1870,12 @@ lang=\"%s\" xml:lang=\"%s\">
 			       (lambda (x) (string-match "^[ \t]*|-" x))
 			       (cdr lines)))))
 
-	 (nline 0) fnum nfields i
+	 (nline 0) fnum nfields i (cnt 0)
 	 tbopen line fields html gr colgropen rowstart rowend)
     (setq caption (and caption (org-html-do-expand caption)))
+    (when (and forced-aligns org-table-clean-did-remove-column)
+    (setq forced-aligns
+	  (mapcar (lambda (x) (cons (1- (car x)) (cdr x))) forced-aligns)))
     (if splice (setq head nil))
     (unless splice (push (if head "<thead>" "<tbody>") html))
     (setq tbopen t)
@@ -1923,17 +1928,21 @@ lang=\"%s\" xml:lang=\"%s\">
       (unless (car org-table-colgroup-info)
 	(setq org-table-colgroup-info
 	      (cons :start (cdr org-table-colgroup-info))))
+      (setq i 0)
       (push (mapconcat
 	     (lambda (x)
-	       (setq gr (pop org-table-colgroup-info))
+	       (setq gr (pop org-table-colgroup-info)
+		     i (1+ i))
 	       (format "%s<col align=\"%s\" />%s"
 		       (if (memq gr '(:start :startend))
 			   (prog1
 			       (if colgropen "</colgroup>\n<colgroup>" "<colgroup>")
 			     (setq colgropen t))
 			 "")
-		       (if (> (/ (float x) nline) org-table-number-fraction)
-			   "right" "left")
+		       (if (assoc i forced-aligns)
+			   (cdr (assoc (cdr (assoc i forced-aligns)) '(("l" . "left") ("r" . "right"))))
+			 (if (> (/ (float x) nline) org-table-number-fraction)
+			     "right" "left"))
 		       (if (memq gr '(:end :startend))
 			   (progn (setq colgropen nil) "</colgroup>")
 			 "")))

+ 9 - 4
lisp/org-table.el

@@ -345,14 +345,19 @@ available parameters."
 
   (save-match-data
     (and (string-match "[<>]\\|&[lg]t;" line)
-	 (or (string-match "\\`[ \t]*|[ \t]*/[ \t]*\\(|[ \t<>0-9|lgt&;]+\\)\\'" line)
+	 (or (string-match
+	      "\\`[ \t]*|[ \t]*/[ \t]*\\(|[ \t<>0-9|lgt&;]+\\)\\'" line)
 	     (string-match "\\(\\`[ \t<>lr0-9|gt&;]+\\'\\)" line))
 	 (not (delq nil (mapcar
 			 (lambda (s)
 			   (not (or (equal s "")
-				    (string-match "\\`<\\([lr]?[0-9]+\\|[lr]\\)>\\'" s)
-				    (string-match "\\`&lt;\\([lr]?[0-9]+\\|[lr]\\)&gt;\\'" s))))
-			 (org-split-string (match-string 1 line) "[ \t]*|[ \t]*")))))))
+				    (string-match
+				     "\\`<\\([lr]?[0-9]+\\|[lr]\\)>\\'" s)
+				    (string-match
+				     "\\`&lt;\\([lr]?[0-9]+\\|[lr]\\)&gt;\\'"
+				     s))))
+			 (org-split-string (match-string 1 line)
+					   "[ \t]*|[ \t]*")))))))
 
 (defconst org-table-translate-regexp
   (concat "\\(" "@[-0-9I$]+" "\\|" "[a-zA-Z]\\{1,2\\}\\([0-9]+\\|&\\)" "\\)")