>From 58598cfd3909ae5a06b583e764f71d15147efe86 Mon Sep 17 00:00:00 2001 From: Jambunathan K Date: Sat, 24 Aug 2013 15:30:13 +0530 Subject: [PATCH 2/4] ox-odt.el: Fix handling of ODT attributes * lisp/ox-odt.el (org-odt--read-attribute): New. (org-odt-template, org-odt-link--inline-image, org-odt-src-block) (org-odt-table-style-spec, org-odt-table-cell) (org-odt--translate-list-tables): Use it. ---------------------------------------------------------------- To the extent possible under law, the author(s) have dedicated all copyright and related and neighboring rights to this software to the public domain worldwide. This software is distributed without any warranty. You should have received a copy of the CC0 Public Domain Dedication along with this software. If not, see . ---------------------------------------------------------------- --- lisp/ox-odt.el | 46 +++++++++++++++++++++++++--------------------- 1 files changed, 25 insertions(+), 21 deletions(-) diff --git a/lisp/ox-odt.el b/lisp/ox-odt.el index 5dcf9ec..f5458a5 100644 --- a/lisp/ox-odt.el +++ b/lisp/ox-odt.el @@ -1026,7 +1026,7 @@ (defun org-odt--frame (text width height style &optional extra (org-odt--encode-plain-text desc t))))))))) -;;;; Library wrappers +;;;; Library wrappers :: Arc Mode (defun org-odt--zip-extract (archive members target) (when (atom members) (setq members (list members))) @@ -1054,6 +1054,15 @@ (defun org-odt--zip-extract (archive members target) (error "Extraction failed")))) members)) + +;;;; Library wrappers :: Ox + +(defun org-odt--read-attribute (element property) + (let* ((attrs (org-export-read-attribute :attr_odt element)) + (value (plist-get attrs property))) + (and value (ignore-errors (read value))))) + + ;;;; Target (defun org-odt--target (text id) @@ -1472,7 +1481,8 @@ (defun org-odt-template (contents info) ;; - Dump automatic table styles. (loop for (style-name props) in (plist-get org-odt-automatic-styles 'Table) do - (when (setq props (or (plist-get props :rel-width) 96)) + (when (setq props (or (let ((value (plist-get props :rel-width))) + (and value (ignore-errors (read value)))) 96)) (insert (format org-odt-table-style-format style-name props)))) ;; - Dump date-styles. (when org-odt-use-date-fields @@ -2349,16 +2359,14 @@ (defun org-odt-link--inline-image (element info) (attr-from (case (org-element-type element) (link (org-export-get-parent-element element)) (t element))) - ;; Convert attributes to a plist. - (attr-plist (org-export-read-attribute :attr_odt attr-from)) ;; Handle `:anchor', `:style' and `:attributes' properties. (user-frame-anchor - (car (assoc-string (plist-get attr-plist :anchor) + (car (assoc-string (org-odt--read-attribute attr-from :anchor) '(("as-char") ("paragraph") ("page")) t))) (user-frame-style - (and user-frame-anchor (plist-get attr-plist :style))) + (and user-frame-anchor (org-odt--read-attribute attr-from :style))) (user-frame-attrs - (and user-frame-anchor (plist-get attr-plist :attributes))) + (and user-frame-anchor (org-odt--read-attribute attr-from :attributes))) (user-frame-params (list user-frame-style user-frame-attrs user-frame-anchor)) ;; (embed-as (or embed-as user-frame-anchor "paragraph")) @@ -2368,12 +2376,9 @@ (defun org-odt-link--inline-image (element info) ;; them as numbers since we need them for computations. (size (org-odt--image-size src-expanded - (let ((width (plist-get attr-plist :width))) - (and width (read width))) - (let ((length (plist-get attr-plist :length))) - (and length (read length))) - (let ((scale (plist-get attr-plist :scale))) - (and scale (read scale))) + (org-odt--read-attribute attr-from :width) + (org-odt--read-attribute attr-from :height) + (org-odt--read-attribute attr-from :scale) nil ; embed-as "paragraph" ; FIXME )) @@ -3241,7 +3246,6 @@ (defun org-odt-src-block (src-block contents info) CONTENTS holds the contents of the item. INFO is a plist holding contextual information." (let* ((lang (org-element-property :language src-block)) - (attributes (org-export-read-attribute :attr_odt src-block)) (captions (org-odt-format-label src-block info 'definition)) (caption (car captions)) (short-caption (cdr captions))) (concat @@ -3249,7 +3253,9 @@ (defun org-odt-src-block (src-block contents info) (format "\n%s" "Listing" caption)) (let ((--src-block (org-odt-format-code src-block info))) - (if (not (plist-get attributes :textbox)) --src-block + ;; Is `:textbox' property non-nil? + (if (not (org-odt--read-attribute src-block :textbox)) --src-block + ;; Yes. Enclose it in a Text Box. (format "\n%s" "Text_20_body" (org-odt--textbox --src-block nil nil nil))))))) @@ -3299,8 +3305,7 @@ (defun org-odt-superscript (superscript contents info) (defun org-odt-table-style-spec (element info) (let* ((table (org-export-get-parent-table element)) - (table-attributes (org-export-read-attribute :attr_odt table)) - (table-style (plist-get table-attributes :style))) + (table-style (org-odt--read-attribute table :style))) (assoc table-style org-odt-table-styles))) (defun org-odt-get-table-cell-styles (table-cell info) @@ -3385,9 +3390,8 @@ (defun org-odt-table-cell (table-cell contents info) (org-export-get-parent-table table-row) info)) "OrgTableHeading") ((let* ((table (org-export-get-parent-table table-cell)) - (table-attrs (org-export-read-attribute :attr_odt table)) (table-header-columns - (let ((cols (plist-get table-attrs :header-columns))) + (let ((cols (org-odt--read-attribute table :header-columns))) (and cols (read cols))))) (<= c (cond ((wholenump table-header-columns) (- table-header-columns 1)) @@ -4033,7 +4037,7 @@ (defun org-odt--translate-description-lists/latex (tree backend info) ;; Consider an example. The following list table ;; -;; #+attr_odt :list-table t +;; #+ATTR_ODT: :list-table t ;; - Row 1 ;; - 1.1 ;; - 1.2 @@ -4069,7 +4073,7 @@ (defun org-odt--translate-description-lists/latex (tree backend info) (defun org-odt--translate-list-tables (tree backend info) (org-element-map tree 'plain-list (lambda (l1-list) - (when (org-export-read-attribute :attr_odt l1-list :list-table) + (when (org-odt--read-attribute l1-list :list-table) ;; Replace list with table. (org-element-set-element l1-list -- 1.7.2.5