summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarsten Dominik <carsten.dominik@gmail.com>2010-10-21 16:28:06 +0200
committerCarsten Dominik <carsten.dominik@gmail.com>2010-10-21 16:28:06 +0200
commit7712d78ab4f37e238d3c85c8eedf889954fdae25 (patch)
tree1491bb4ab407d77182c4d92b74cfbeeeec9f7215
parente290e9e2f4716acbe6ef011f3e5574c6c926aa8b (diff)
downloadorg-mode-7712d78ab4f37e238d3c85c8eedf889954fdae25.tar.gz
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.
-rw-r--r--lisp/org-exp.el27
-rw-r--r--lisp/org-html.el17
-rw-r--r--lisp/org-table.el13
3 files changed, 47 insertions, 10 deletions
diff --git a/lisp/org-exp.el b/lisp/org-exp.el
index 9b455b1..6ee56a8 100644
--- a/lisp/org-exp.el
+++ b/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))
diff --git a/lisp/org-html.el b/lisp/org-html.el
index 3fd7b72..adc9fa7 100644
--- a/lisp/org-html.el
+++ b/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>")
"")))
diff --git a/lisp/org-table.el b/lisp/org-table.el
index c02f4e5..8cc76c6 100644
--- a/lisp/org-table.el
+++ b/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]+\\|&\\)" "\\)")