;;; 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
: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.
(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
;;;; 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:
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:
;;;; 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:
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")))
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")))
See `org-odt--build-date-styles' for implementation details."
:group 'org-export-odt
+ :version "24.4"
+ :package-version '(Org . "8.0")
:type 'boolean)
(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
(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))
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))
:transcoders
'((paragraph . (lambda (p c i)
(org-odt--format-paragraph
- p c "Footnote"
+ p c i
+ "Footnote"
"OrgFootnoteCenter"
"OrgFootnoteQuotations")))))
info))))
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))))
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
;; 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)
(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 & for correct XML representation
(path (replace-regexp-in-string "&" "&" path))
;; 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"))
;;;; 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"))
(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))