]> code.delx.au - gnu-emacs/blobdiff - lisp/org/ox-odt.el
Update copyright year to 2015
[gnu-emacs] / lisp / org / ox-odt.el
index d5d03e49b5092668b10d516e9bb6c98abe163475..29bc87875a1525edce367f32dd7d2bf281995d93 100644 (file)
@@ -1,6 +1,6 @@
 ;;; ox-odt.el --- OpenDocument Text Exporter for Org Mode
 
-;; Copyright (C) 2010-2013 Free Software Foundation, Inc.
+;; Copyright (C) 2010-2015 Free Software Foundation, Inc.
 
 ;; Author: Jambunathan K <kjambunathan at gmail dot com>
 ;; Keywords: outlines, hypermedia, calendar, wp
@@ -449,7 +449,7 @@ under `org-odt-styles-dir' is used."
   :type '(choice (const nil)
                 (file))
   :group 'org-export-odt
-  :version "24.1")
+  :version "24.3")
 
 (defcustom org-odt-styles-file nil
   "Default styles file for use with ODT export.
@@ -498,7 +498,8 @@ a per-file basis.  For example,
 (defcustom org-odt-display-outline-level 2
   "Outline levels considered for enumerating captioned entities."
   :group 'org-export-odt
-  :version "24.2"
+  :version "24.4"
+  :package-version '(Org . "8.0")
   :type 'integer)
 
 ;;;; Document conversion
@@ -645,7 +646,8 @@ values.  See Info node `(emacs) File Variables'."
 
 ;;;; Drawers
 
-(defcustom org-odt-format-drawer-function nil
+(defcustom org-odt-format-drawer-function
+  (lambda (name contents) contents)
   "Function called to format a drawer in ODT code.
 
 The function must accept two parameters:
@@ -654,21 +656,16 @@ The function must accept two parameters:
 
 The function should return the string to be exported.
 
-For example, the variable could be set to the following function
-in order to mimic default behaviour:
-
-\(defun org-odt-format-drawer-default \(name contents\)
-  \"Format a drawer element for ODT export.\"
-  contents\)"
+The default value simply returns the value of CONTENTS."
   :group 'org-export-odt
   :version "24.4"
-  :package-version '(Org . "8.0")
+  :package-version '(Org . "8.3")
   :type 'function)
 
 
 ;;;; Headline
 
-(defcustom org-odt-format-headline-function nil
+(defcustom org-odt-format-headline-function 'ignore
   "Function to format headline text.
 
 This function will be called with 5 arguments:
@@ -687,7 +684,7 @@ The function result will be used as headline text."
 
 ;;;; Inlinetasks
 
-(defcustom org-odt-format-inlinetask-function nil
+(defcustom org-odt-format-inlinetask-function 'ignore
   "Function called to format an inlinetask in ODT code.
 
 The function must accept six parameters:
@@ -746,6 +743,8 @@ A rule consists in an association whose key is the type of link
 to consider, and value is a regexp that will be matched against
 link's path."
   :group 'org-export-odt
+  :version "24.4"
+  :package-version '(Org . "8.0")
   :type '(alist :key-type (string :tag "Type")
                :value-type (regexp :tag "Path")))
 
@@ -757,6 +756,8 @@ A rule consists in an association whose key is the type of link
 to consider, and value is a regexp that will be matched against
 link's path."
   :group 'org-export-odt
+  :version "24.4"
+  :package-version '(Org . "8.0")
   :type '(alist :key-type (string :tag "Type")
                :value-type (regexp :tag "Path")))
 
@@ -929,6 +930,8 @@ the application UI or through a custom styles file.
 
 See `org-odt--build-date-styles' for implementation details."
   :group 'org-export-odt
+  :version "24.4"
+  :package-version '(Org . "8.0")
   :type 'boolean)
 
 
@@ -995,7 +998,9 @@ See `org-odt--build-date-styles' for implementation details."
          (if width (format " svg:width=\"%0.2fcm\"" width) "")
          (if height (format " svg:height=\"%0.2fcm\"" height) "")
          extra
-         (format " text:anchor-type=\"%s\"" (or anchor-type "paragraph")))))
+         (format " text:anchor-type=\"%s\"" (or anchor-type "paragraph"))
+         (format " draw:name=\"%s\""
+                 (car (org-odt-add-automatic-style "Frame"))))))
     (format
      "\n<draw:frame draw:style-name=\"%s\"%s>\n%s\n</draw:frame>"
      style frame-attrs
@@ -1497,7 +1502,7 @@ original parsed data.  INFO is a plist holding export options."
              (email (and (plist-get info :with-email) email)))
         (concat
          ;; Title.
-         (when title
+         (when (org-string-nw-p title)
            (concat
             (format "\n<text:p text:style-name=\"%s\">%s</text:p>"
                     "OrgTitle" (format "\n<text:title>%s</text:title>" title))
@@ -1619,12 +1624,8 @@ channel."
 CONTENTS holds the contents of the block.  INFO is a plist
 holding contextual information."
   (let* ((name (org-element-property :drawer-name drawer))
-        (output (if (functionp org-odt-format-drawer-function)
-                    (funcall org-odt-format-drawer-function
-                             name contents)
-                  ;; If there's no user defined function: simply
-                  ;; display contents of the drawer.
-                  contents)))
+        (output (funcall org-odt-format-drawer-function
+                         name contents)))
     output))
 
 
@@ -1740,7 +1741,8 @@ CONTENTS is nil.  INFO is a plist holding contextual information."
                               :transcoders
                               '((paragraph . (lambda (p c i)
                                                (org-odt--format-paragraph
-                                                p c "Footnote"
+                                                p c i
+                                                "Footnote"
                                                 "OrgFootnoteCenter"
                                                 "OrgFootnoteQuotations")))))
                              info))))
@@ -1805,10 +1807,10 @@ INFO is a plist holding contextual information."
                                                   headline-number "-")))
         (format-function (cond
                           ((functionp format-function) format-function)
-                          ((functionp org-odt-format-headline-function)
+                          ((not (eq org-odt-format-headline-function 'ignore))
                            (function*
                             (lambda (todo todo-type priority text tags
-                                     &allow-other-keys)
+                                          &allow-other-keys)
                               (funcall org-odt-format-headline-function
                                        todo todo-type priority text tags))))
                           (t 'org-odt-format-headline))))
@@ -1931,9 +1933,9 @@ contextual information."
 CONTENTS holds the contents of the block.  INFO is a plist
 holding contextual information."
   (cond
-   ;; If `org-odt-format-inlinetask-function' is provided, call it
+   ;; If `org-odt-format-inlinetask-function' is not 'ignore, call it
    ;; with appropriate arguments.
-   ((functionp org-odt-format-inlinetask-function)
+   ((not (eq org-odt-format-inlinetask-function 'ignore))
     (let ((format-function
           (function*
            (lambda (todo todo-type priority text tags
@@ -2121,45 +2123,9 @@ SHORT-CAPTION are strings."
         ;; Get label and caption.
         (label (org-element-property :name caption-from))
         (caption (org-export-get-caption caption-from))
-        (short-caption (org-export-get-caption caption-from t))
-        ;; Transcode captions.
         (caption (and caption (org-export-data caption info)))
-        ;; Currently short caption are sneaked in as object names.
-        ;;
-        ;; The advantages are:
-        ;;
-        ;; - Table Of Contents: Currently, there is no support for
-        ;;   building TOC for figures, listings and tables.  See
-        ;;   `org-odt-keyword'.  User instead has to rely on
-        ;;   external application for building such indices.  Within
-        ;;   LibreOffice, building an "Illustration Index" or "Index
-        ;;   of Tables" will create a table with long captions (only)
-        ;;   and building a table with "Object names" will create a
-        ;;   table with short captions.
-        ;;
-        ;; - Easy navigation: In LibreOffice, object names are
-        ;;   offered via the navigation bar.  This way one can
-        ;;   quickly locate and jump to object of his choice in the
-        ;;   exported document.
-        ;;
-        ;; The main disadvantage is that there cannot be any markups
-        ;; within object names i.e., one cannot embolden, italicize
-        ;; or underline text within short caption.  So suppress
-        ;; generation of <text:span >...</text:span> and other
-        ;; markups by overriding the default translators.  We
-        ;; probably shouldn't be suppressing translators for all
-        ;; elements in `org-element-all-objects', but for now this
-        ;; will do.
-        (short-caption
-         (let ((short-caption (or short-caption caption))
-               (backend (org-export-create-backend
-                         :parent (org-export-backend-name
-                                  (plist-get info :back-end))
-                         :transcoders
-                         (mapcar (lambda (type) (cons type (lambda (o c i) c)))
-                                 org-element-all-objects))))
-           (when short-caption
-             (org-export-data-with-backend short-caption backend info)))))
+        ;; FIXME: We don't use short-caption for now
+        (short-caption nil))
     (when (or label caption)
       (let* ((default-category
               (case (org-element-type element)
@@ -2748,10 +2714,8 @@ INFO is a plist holding contextual information.  See
         (path (cond
                ((member type '("http" "https" "ftp" "mailto"))
                 (concat type ":" raw-path))
-               ((string= type "file")
-                (if (file-name-absolute-p raw-path)
-                    (concat "file://" (expand-file-name raw-path))
-                  (concat "file://" raw-path)))
+               ((and (string= type "file") (file-name-absolute-p raw-path))
+                (concat "file:" raw-path))
                (t raw-path)))
         ;; Convert & to &amp; for correct XML representation
         (path (replace-regexp-in-string "&" "&amp;" path))
@@ -2769,12 +2733,12 @@ INFO is a plist holding contextual information.  See
      ;; link's description.
      ((string= type "radio")
       (let ((destination (org-export-resolve-radio-link link info)))
-       (when destination
-         (let ((desc (org-export-data (org-element-contents destination) info))
-               (href (org-export-solidify-link-text path)))
-           (format
-            "<text:bookmark-ref text:reference-format=\"text\" text:ref-name=\"OrgXref.%s\">%s</text:bookmark-ref>"
-            href desc)))))
+       (if (not destination) desc
+         (format
+          "<text:bookmark-ref text:reference-format=\"text\" text:ref-name=\"OrgXref.%s\">%s</text:bookmark-ref>"
+          (org-export-solidify-link-text
+           (org-element-property :value destination))
+          desc))))
      ;; Links pointing to a headline: Find destination and build
      ;; appropriate referencing command.
      ((member type '("custom-id" "fuzzy" "id"))
@@ -2869,33 +2833,44 @@ INFO is a plist holding contextual information.  See
 
 ;;;; Paragraph
 
-(defun org-odt--format-paragraph (paragraph contents default center quote)
+(defun org-odt--paragraph-style (paragraph)
+  "Return style of PARAGRAPH.
+Style is a symbol among `quoted', `centered' and nil."
+  (let ((up paragraph))
+    (while (and (setq up (org-element-property :parent up))
+               (not (memq (org-element-type up)
+                          '(center-block quote-block section)))))
+    (case (org-element-type up)
+      (center-block 'centered)
+      (quote-block 'quoted))))
+
+(defun org-odt--format-paragraph (paragraph contents info default center quote)
   "Format paragraph according to given styles.
 PARAGRAPH is a paragraph type element.  CONTENTS is the
-transcoded contents of that paragraph, as a string.  DEFAULT,
-CENTER and QUOTE are, respectively, style to use when paragraph
-belongs to no special environment, a center block, or a quote
-block."
-  (let* ((parent (org-export-get-parent paragraph))
-        (parent-type (org-element-type parent))
-        (style (case parent-type
-                 (quote-block quote)
-                 (center-block center)
-                 (t default))))
-    ;; If this paragraph is a leading paragraph in an item and the
-    ;; item has a checkbox, splice the checkbox and paragraph contents
-    ;; together.
-    (when (and (eq (org-element-type parent) 'item)
-              (eq paragraph (car (org-element-contents parent))))
-      (setq contents (concat (org-odt--checkbox parent) contents)))
-    (format "\n<text:p text:style-name=\"%s\">%s</text:p>" style contents)))
+transcoded contents of that paragraph, as a string.  INFO is
+a plist used as a communication channel.  DEFAULT, CENTER and
+QUOTE are, respectively, style to use when paragraph belongs to
+no special environment, a center block, or a quote block."
+  (format "\n<text:p text:style-name=\"%s\">%s</text:p>"
+         (case (org-odt--paragraph-style paragraph)
+           (quoted quote)
+           (centered center)
+           (otherwise default))
+         ;; If PARAGRAPH is a leading paragraph in an item that has
+         ;; a checkbox, splice checkbox and paragraph contents
+         ;; together.
+         (concat (let ((parent (org-element-property :parent paragraph)))
+                   (and (eq (org-element-type parent) 'item)
+                        (not (org-export-get-previous-element paragraph info))
+                        (org-odt--checkbox parent)))
+                 contents)))
 
 (defun org-odt-paragraph (paragraph contents info)
   "Transcode a PARAGRAPH element from Org to ODT.
 CONTENTS is the contents of the paragraph, as a string.  INFO is
 the plist used as a communication channel."
   (org-odt--format-paragraph
-   paragraph contents
+   paragraph contents info
    (or (org-element-property :style paragraph) "Text_20_body")
    "OrgCenter"
    "Quotations"))
@@ -3164,7 +3139,7 @@ and prefix with \"OrgSrc\".  For example,
                 (with-temp-buffer
                   (insert code)
                   (funcall lang-mode)
-                  (font-lock-fontify-buffer)
+                  (org-font-lock-ensure)
                   (buffer-string))))
         (fontifier (if use-htmlfontify-p 'org-odt-htmlfontify-string
                      'org-odt--encode-plain-text))