1 ;;; org-e-odt.el --- OpenDocument Text exporter for Org-mode
3 ;; Copyright (C) 2010-2012 Free Software Foundation, Inc.
5 ;; Author: Jambunathan K <kjambunathan at gmail dot com>
6 ;; Keywords: outlines, hypermedia, calendar, wp
7 ;; Homepage: http://orgmode.org
9 ;; This file is not part of GNU Emacs.
11 ;; GNU Emacs is free software: you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation, either version 3 of the License, or
14 ;; (at your option) any later version.
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
31 (require 'format-spec
)
36 (org-export-define-backend e-odt
37 ((bold . org-e-odt-bold
)
38 (center-block . org-e-odt-center-block
)
39 (clock . org-e-odt-clock
)
40 (code . org-e-odt-code
)
41 (drawer . org-e-odt-drawer
)
42 (dynamic-block . org-e-odt-dynamic-block
)
43 (entity . org-e-odt-entity
)
44 (example-block . org-e-odt-example-block
)
45 (export-block . org-e-odt-export-block
)
46 (export-snippet . org-e-odt-export-snippet
)
47 (fixed-width . org-e-odt-fixed-width
)
48 (footnote-definition . org-e-odt-footnote-definition
)
49 (footnote-reference . org-e-odt-footnote-reference
)
50 (headline . org-e-odt-headline
)
51 (horizontal-rule . org-e-odt-horizontal-rule
)
52 (inline-src-block . org-e-odt-inline-src-block
)
53 (inlinetask . org-e-odt-inlinetask
)
54 (italic . org-e-odt-italic
)
55 (item . org-e-odt-item
)
56 (keyword . org-e-odt-keyword
)
57 (latex-environment . org-e-odt-latex-environment
)
58 (latex-fragment . org-e-odt-latex-fragment
)
59 (line-break . org-e-odt-line-break
)
60 (link . org-e-odt-link
)
61 (paragraph . org-e-odt-paragraph
)
62 (plain-list . org-e-odt-plain-list
)
63 (plain-text . org-e-odt-plain-text
)
64 (planning . org-e-odt-planning
)
65 (property-drawer . org-e-odt-property-drawer
)
66 (quote-block . org-e-odt-quote-block
)
67 (quote-section . org-e-odt-quote-section
)
68 (radio-target . org-e-odt-radio-target
)
69 (section . org-e-odt-section
)
70 (special-block . org-e-odt-special-block
)
71 (src-block . org-e-odt-src-block
)
72 (statistics-cookie . org-e-odt-statistics-cookie
)
73 (strike-through . org-e-odt-strike-through
)
74 (subscript . org-e-odt-subscript
)
75 (superscript . org-e-odt-superscript
)
76 (table . org-e-odt-table
)
77 (table-cell . org-e-odt-table-cell
)
78 (table-row . org-e-odt-table-row
)
79 (target . org-e-odt-target
)
80 (template . org-e-odt-template
)
81 (timestamp . org-e-odt-timestamp
)
82 (underline . org-e-odt-underline
)
83 (verbatim . org-e-odt-verbatim
)
84 (verse-block . org-e-odt-verse-block
))
86 :filters-alist
((:filter-parse-tree . org-e-odt--translate-description-lists
))
88 ((:odt-styles-file
"ODT_STYLES_FILE" nil nil t
)
89 (:LaTeX-fragments nil
"LaTeX" org-export-with-LaTeX-fragments
)))
96 ;;; Function Declarations
98 (declare-function org-id-find-id-file
"org-id" (id))
99 (declare-function hfy-face-to-style
"htmlfontify" (fn))
100 (declare-function hfy-face-or-def-to-name
"htmlfontify" (fn))
101 (declare-function archive-zip-extract
"arc-mode.el" (archive name
))
102 (declare-function org-create-math-formula
"org" (latex-frag &optional
104 (declare-function browse-url-file-url
"browse-url" (file))
108 ;;; Internal Variables
110 (defconst org-e-odt-lib-dir
111 (file-name-directory load-file-name
)
112 "Location of ODT exporter.
113 Use this to infer values of `org-e-odt-styles-dir' and
114 `org-e-odt-schema-dir'.")
116 (defvar org-e-odt-data-dir
117 (expand-file-name "../../etc/" org-e-odt-lib-dir
)
118 "Data directory for ODT exporter.
119 Use this to infer values of `org-e-odt-styles-dir' and
120 `org-e-odt-schema-dir'.")
122 (defconst org-e-odt-special-string-regexps
123 '(("\\\\-" .
"­\\1") ; shy
124 ("---\\([^-]\\)" .
"—\\1") ; mdash
125 ("--\\([^-]\\)" .
"–\\1") ; ndash
126 ("\\.\\.\\." .
"…")) ; hellip
127 "Regular expressions for special string conversion.")
129 (defconst org-e-odt-schema-dir-list
131 (and org-e-odt-data-dir
132 (expand-file-name "./schema/" org-e-odt-data-dir
)) ; bail out
134 (and (boundp 'org-e-odt-data-dir
) org-e-odt-data-dir
; see make install
135 (expand-file-name "./schema/" org-e-odt-data-dir
))))
136 "List of directories to search for OpenDocument schema files.
137 Use this list to set the default value of
138 `org-e-odt-schema-dir'. The entries in this list are
139 populated heuristically based on the values of `org-e-odt-lib-dir'
140 and `org-e-odt-data-dir'.")
142 (defconst org-e-odt-styles-dir-list
144 (and org-e-odt-data-dir
145 (expand-file-name "./styles/" org-e-odt-data-dir
)) ; bail out
147 (and (boundp 'org-e-odt-data-dir
) org-e-odt-data-dir
; see make install
148 (expand-file-name "./styles/" org-e-odt-data-dir
)))
149 (expand-file-name "../../etc/styles/" org-e-odt-lib-dir
) ; git
150 (expand-file-name "./etc/styles/" org-e-odt-lib-dir
) ; elpa
151 (expand-file-name "./org/" data-directory
) ; system
153 "List of directories to search for OpenDocument styles files.
154 See `org-e-odt-styles-dir'. The entries in this list are populated
155 heuristically based on the values of `org-e-odt-lib-dir' and
156 `org-e-odt-data-dir'.")
158 (defconst org-e-odt-styles-dir
161 (message "Debug (org-e-odt): Searching for OpenDocument styles files...")
162 (mapc (lambda (styles-dir)
164 (message "Debug (org-e-odt): Trying %s..." styles-dir
)
165 (when (and (file-readable-p
167 "OrgOdtContentTemplate.xml" styles-dir
))
170 "OrgOdtStyles.xml" styles-dir
)))
171 (message "Debug (org-e-odt): Using styles under %s"
173 (throw 'styles-dir styles-dir
))))
174 org-e-odt-styles-dir-list
)
177 (error "Error (org-e-odt): Cannot find factory styles files. Aborting."))
179 "Directory that holds auxiliary XML files used by the ODT exporter.
181 This directory contains the following XML files -
182 \"OrgOdtStyles.xml\" and \"OrgOdtContentTemplate.xml\". These
183 XML files are used as the default values of
184 `org-e-odt-styles-file' and
185 `org-e-odt-content-template-file'.
187 The default value of this variable varies depending on the
188 version of org in use and is initialized from
189 `org-e-odt-styles-dir-list'. Note that the user could be using org
190 from one of: org's own private git repository, GNU ELPA tar or
193 (defconst org-e-odt-bookmark-prefix
"OrgXref.")
195 (defconst org-e-odt-manifest-file-entry-tag
196 "\n<manifest:file-entry manifest:media-type=\"%s\" manifest:full-path=\"%s\"%s/>")
198 (defconst org-e-odt-file-extensions
199 '(("odt" .
"OpenDocument Text")
200 ("ott" .
"OpenDocument Text Template")
201 ("odm" .
"OpenDocument Master Document")
202 ("ods" .
"OpenDocument Spreadsheet")
203 ("ots" .
"OpenDocument Spreadsheet Template")
204 ("odg" .
"OpenDocument Drawing (Graphics)")
205 ("otg" .
"OpenDocument Drawing Template")
206 ("odp" .
"OpenDocument Presentation")
207 ("otp" .
"OpenDocument Presentation Template")
208 ("odi" .
"OpenDocument Image")
209 ("odf" .
"OpenDocument Formula")
210 ("odc" .
"OpenDocument Chart")))
212 (defvar org-e-odt-table-style-format
214 <style:style style:name=\"%s\" style:family=\"table\">
215 <style:table-properties style:rel-width=\"%d%%\" fo:margin-top=\"0cm\" fo:margin-bottom=\"0.20cm\" table:align=\"center\"/>
218 "Template for auto-generated Table styles.")
220 (defvar org-e-odt-automatic-styles
'()
221 "Registry of automatic styles for various OBJECT-TYPEs.
222 The variable has the following form:
224 \(\(OBJECT-NAME-A.1 OBJECT-PROPS-A.1\)
225 \(OBJECT-NAME-A.2 OBJECT-PROPS-A.2\) ...\)\)
227 \(\(OBJECT-NAME-B.1 OBJECT-PROPS-B.1\)
228 \(OBJECT-NAME-B.2 OBJECT-PROPS-B.2\) ...\)\)
231 OBJECT-TYPEs could be \"Section\", \"Table\", \"Figure\" etc.
232 OBJECT-PROPS is (typically) a plist created by passing
233 \"#+ATTR_ODT: \" option to `org-e-odt-parse-block-attributes'.
235 Use `org-e-odt-add-automatic-style' to add update this variable.'")
237 (defvar org-e-odt-object-counters nil
238 "Running counters for various OBJECT-TYPEs.
239 Use this to generate automatic names and style-names. See
240 `org-e-odt-add-automatic-style'.")
242 (defvar org-e-odt-src-block-paragraph-format
243 "<style:style style:name=\"OrgSrcBlock\" style:family=\"paragraph\" style:parent-style-name=\"Preformatted_20_Text\">
244 <style:paragraph-properties fo:background-color=\"%s\" fo:padding=\"0.049cm\" fo:border=\"0.51pt solid #000000\" style:shadow=\"none\">
245 <style:background-image/>
246 </style:paragraph-properties>
247 <style:text-properties fo:color=\"%s\"/>
249 "Custom paragraph style for colorized source and example blocks.
250 This style is much the same as that of \"OrgFixedWidthBlock\"
251 except that the foreground and background colors are set
252 according to the default face identified by the `htmlfontify'.")
254 (defvar hfy-optimisations
)
255 (defvar org-e-odt-embedded-formulas-count
0)
256 (defvar org-e-odt-entity-frame-styles
257 '(("As-CharImage" "__Figure__" ("OrgInlineImage" nil
"as-char"))
258 ("ParagraphImage" "__Figure__" ("OrgDisplayImage" nil
"paragraph"))
259 ("PageImage" "__Figure__" ("OrgPageImage" nil
"page"))
260 ("CaptionedAs-CharImage" "__Figure__"
262 " style:rel-width=\"100%\" style:rel-height=\"scale\"" "paragraph")
263 ("OrgInlineImage" nil
"as-char"))
264 ("CaptionedParagraphImage" "__Figure__"
266 " style:rel-width=\"100%\" style:rel-height=\"scale\"" "paragraph")
267 ("OrgImageCaptionFrame" nil
"paragraph"))
268 ("CaptionedPageImage" "__Figure__"
270 " style:rel-width=\"100%\" style:rel-height=\"scale\"" "paragraph")
271 ("OrgPageImageCaptionFrame" nil
"page"))
272 ("InlineFormula" "__MathFormula__" ("OrgInlineFormula" nil
"as-char"))
273 ("DisplayFormula" "__MathFormula__" ("OrgDisplayFormula" nil
"as-char"))
274 ("CaptionedDisplayFormula" "__MathFormula__"
275 ("OrgCaptionedFormula" nil
"paragraph")
276 ("OrgFormulaCaptionFrame" nil
"as-char"))))
278 (defvar org-e-odt-embedded-images-count
0)
279 (defvar org-e-odt-image-size-probe-method
280 (append (and (executable-find "identify") '(imagemagick)) ; See Bug#10675
282 "Ordered list of methods for determining image sizes.")
284 (defvar org-e-odt-default-image-sizes-alist
285 '(("as-char" .
(5 .
0.4))
286 ("paragraph" .
(5 .
5)))
287 "Hardcoded image dimensions one for each of the anchor
290 ;; A4 page size is 21.0 by 29.7 cms
291 ;; The default page settings has 2cm margin on each of the sides. So
292 ;; the effective text area is 17.0 by 25.7 cm
293 (defvar org-e-odt-max-image-size
'(17.0 .
20.0)
294 "Limiting dimensions for an embedded image.")
296 (defvar org-e-odt-label-styles
297 '(("math-formula" "%c" "text" "(%n)")
298 ("math-label" "(%n)" "text" "(%n)")
299 ("category-and-value" "%e %n: %c" "category-and-value" "%e %n")
300 ("value" "%e %n: %c" "value" "%n"))
301 "Specify how labels are applied and referenced.
302 This is an alist where each element is of the
303 form (LABEL-STYLE-NAME LABEL-ATTACH-FMT LABEL-REF-MODE
306 LABEL-ATTACH-FMT controls how labels and captions are attached to
307 an entity. It may contain following specifiers - %e, %n and %c.
308 %e is replaced with the CATEGORY-NAME. %n is replaced with
309 \"<text:sequence ...> SEQNO </text:sequence>\". %c is replaced
310 with CAPTION. See `org-e-odt-format-label-definition'.
312 LABEL-REF-MODE and LABEL-REF-FMT controls how label references
313 are generated. The following XML is generated for a label
314 reference - \"<text:sequence-ref
315 text:reference-format=\"LABEL-REF-MODE\" ...> LABEL-REF-FMT
316 </text:sequence-ref>\". LABEL-REF-FMT may contain following
317 specifiers - %e and %n. %e is replaced with the CATEGORY-NAME.
318 %n is replaced with SEQNO. See
319 `org-e-odt-format-label-reference'.")
321 (defvar org-e-odt-category-map-alist
322 '(("__Table__" "Table" "value" "Table")
323 ("__Figure__" "Illustration" "value" "Figure")
324 ("__MathFormula__" "Text" "math-formula" "Equation")
325 ("__DvipngImage__" "Equation" "value" "Equation")
326 ("__Listing__" "Listing" "value" "Listing")
327 ;; ("__Table__" "Table" "category-and-value")
328 ;; ("__Figure__" "Figure" "category-and-value")
329 ;; ("__DvipngImage__" "Equation" "category-and-value")
331 "Map a CATEGORY-HANDLE to OD-VARIABLE and LABEL-STYLE.
332 This is a list where each entry is of the form \\(CATEGORY-HANDLE
333 OD-VARIABLE LABEL-STYLE CATEGORY-NAME\\). CATEGORY_HANDLE
334 identifies the captionable entity in question. OD-VARIABLE is
335 the OpenDocument sequence counter associated with the entity.
336 These counters are declared within
337 \"<text:sequence-decls>...</text:sequence-decls>\" block of
338 `org-e-odt-content-template-file'. LABEL-STYLE is a key into
339 `org-e-odt-label-styles' and specifies how a given entity should
340 be captioned and referenced. CATEGORY-NAME is used for
341 qualifying captions on export. You can modify the CATEGORY-NAME
342 used in the exported document by modifying
343 `org-export-dictionary'. For example, an embedded image in an
344 English document is captioned as \"Figure 1: Orgmode Logo\", by
345 default. If you want the image to be captioned as \"Illustration
346 1: Orgmode Logo\" instead, install an entry in
347 `org-export-dictionary' which translates \"Figure\" to
348 \"Illustration\" when the language is \"en\" and encoding is
351 (defvar org-e-odt-manifest-file-entries nil
)
352 (defvar hfy-user-sheet-assoc
)
354 (defvar org-e-odt-zip-dir nil
355 "Temporary work directory for OpenDocument exporter.")
359 ;;; User Configuration Variables
361 (defgroup org-export-e-odt nil
362 "Options for exporting Org mode files to ODT."
363 :tag
"Org Export ODT"
369 (defcustom org-e-odt-prettify-xml nil
370 "Specify whether or not the xml output should be prettified.
371 When this option is turned on, `indent-region' is run on all
372 component xml buffers before they are saved. Turn this off for
373 regular use. Turn this on if you need to examine the xml
375 :group
'org-export-e-odt
382 (defcustom org-e-odt-schema-dir
385 (message "Debug (org-e-odt): Searching for OpenDocument schema files...")
389 (message "Debug (org-e-odt): Trying %s..." schema-dir
)
390 (when (and (file-readable-p
391 (expand-file-name "od-manifest-schema-v1.2-cs01.rnc"
394 (expand-file-name "od-schema-v1.2-cs01.rnc"
397 (expand-file-name "schemas.xml" schema-dir
)))
398 (message "Debug (org-e-odt): Using schema files under %s"
400 (throw 'schema-dir schema-dir
))))
401 org-e-odt-schema-dir-list
)
402 (message "Debug (org-e-odt): No OpenDocument schema files installed")
405 "Directory that contains OpenDocument schema files.
407 This directory contains:
408 1. rnc files for OpenDocument schema
409 2. a \"schemas.xml\" file that specifies locating rules needed
410 for auto validation of OpenDocument XML files.
412 Use the customize interface to set this variable. This ensures
413 that `rng-schema-locating-files' is updated and auto-validation
414 of OpenDocument XML takes place based on the value
415 `rng-nxml-auto-validate-flag'.
417 The default value of this variable varies depending on the
418 version of org in use and is initialized from
419 `org-e-odt-schema-dir-list'. The OASIS schema files are available
420 only in the org's private git repository. It is *not* bundled
421 with GNU ELPA tar or standard Emacs distribution."
423 (const :tag
"Not set" nil
)
424 (directory :tag
"Schema directory"))
425 :group
'org-export-e-odt
429 "Set `org-e-odt-schema-dir'.
430 Also add it to `rng-schema-locating-files'."
431 (let ((schema-dir value
))
435 (expand-file-name "od-manifest-schema-v1.2-cs01.rnc" schema-dir
))
437 (expand-file-name "od-schema-v1.2-cs01.rnc" schema-dir
))
439 (expand-file-name "schemas.xml" schema-dir
)))
442 (message "Error (org-e-odt): %s has no OpenDocument schema files"
445 (when org-e-odt-schema-dir
446 (eval-after-load 'rng-loc
447 '(add-to-list 'rng-schema-locating-files
448 (expand-file-name "schemas.xml"
449 org-e-odt-schema-dir
))))))
454 (defcustom org-e-odt-content-template-file nil
455 "Template file for \"content.xml\".
456 The exporter embeds the exported content just before
457 \"</office:text>\" element.
459 If unspecified, the file named \"OrgOdtContentTemplate.xml\"
460 under `org-e-odt-styles-dir' is used."
462 :group
'org-export-e-odt
465 (defcustom org-e-odt-styles-file nil
466 "Default styles file for use with ODT export.
467 Valid values are one of:
469 2. path to a styles.xml file
470 3. path to a *.odt or a *.ott file
471 4. list of the form (ODT-OR-OTT-FILE (FILE-MEMBER-1 FILE-MEMBER-2
474 In case of option 1, an in-built styles.xml is used. See
475 `org-e-odt-styles-dir' for more information.
477 In case of option 3, the specified file is unzipped and the
478 styles.xml embedded therein is used.
480 In case of option 4, the specified ODT-OR-OTT-FILE is unzipped
481 and FILE-MEMBER-1, FILE-MEMBER-2 etc are copied in to the
482 generated odt file. Use relative path for specifying the
483 FILE-MEMBERS. styles.xml must be specified as one of the
486 Use options 1, 2 or 3 only if styles.xml alone suffices for
487 achieving the desired formatting. Use option 4, if the styles.xml
488 references additional files like header and footer images for
489 achieving the desired formatting.
491 Use \"#+ODT_STYLES_FILE: ...\" directive to set this variable on
492 a per-file basis. For example,
494 #+ODT_STYLES_FILE: \"/path/to/styles.xml\" or
495 #+ODT_STYLES_FILE: (\"/path/to/file.ott\" (\"styles.xml\" \"image/hdr.png\"))."
496 :group
'org-export-e-odt
500 (const :tag
"Factory settings" nil
)
501 (file :must-match t
:tag
"styles.xml")
502 (file :must-match t
:tag
"ODT or OTT file")
503 (list :tag
"ODT or OTT file + Members"
504 (file :must-match t
:tag
"ODF Text or Text Template file")
506 (file :tag
" Member" "styles.xml")
507 (repeat (file :tag
"Member"))))))
509 (defcustom org-e-odt-display-outline-level
2
510 "Outline levels considered for enumerating captioned entities."
511 :group
'org-export-e-odt
515 ;;;; Document conversion
517 (defcustom org-e-odt-convert-processes
519 "soffice --headless --convert-to %f%x --outdir %d %i")
521 "unoconv -f %f -o %d %i"))
522 "Specify a list of document converters and their usage.
523 The converters in this list are offered as choices while
524 customizing `org-e-odt-convert-process'.
526 This variable is a list where each element is of the
527 form (CONVERTER-NAME CONVERTER-CMD). CONVERTER-NAME is the name
528 of the converter. CONVERTER-CMD is the shell command for the
529 converter and can contain format specifiers. These format
530 specifiers are interpreted as below:
532 %i input file name in full
533 %I input file name as a URL
534 %f format of the output file
535 %o output file name in full
536 %O output file name as a URL
537 %d output dir in full
538 %D output dir as a URL.
539 %x extra options as set in `org-e-odt-convert-capabilities'."
540 :group
'org-export-e-odt
544 (const :tag
"None" nil
)
545 (alist :tag
"Converters"
546 :key-type
(string :tag
"Converter Name")
547 :value-type
(group (string :tag
"Command line")))))
549 (defcustom org-e-odt-convert-process
"LibreOffice"
550 "Use this converter to convert from \"odt\" format to other formats.
551 During customization, the list of converter names are populated
552 from `org-e-odt-convert-processes'."
553 :group
'org-export-e-odt
555 :type
'(choice :convert-widget
557 (apply 'widget-convert
(widget-type w
)
558 (eval (car (widget-get w
:args
)))))
559 `((const :tag
"None" nil
)
560 ,@(mapcar (lambda (c)
561 `(const :tag
,(car c
) ,(car c
)))
562 org-e-odt-convert-processes
))))
564 (defcustom org-e-odt-convert-capabilities
566 ("odt" "ott" "doc" "rtf" "docx")
567 (("pdf" "pdf") ("odt" "odt") ("rtf" "rtf") ("ott" "ott")
568 ("doc" "doc" ":\"MS Word 97\"") ("docx" "docx") ("html" "html")))
571 (("pdf" "pdf") ("odt" "odt") ("html" "html")))
573 ("ods" "ots" "xls" "csv" "xlsx")
574 (("pdf" "pdf") ("ots" "ots") ("html" "html") ("csv" "csv") ("ods" "ods")
575 ("xls" "xls") ("xlsx" "xlsx")))
577 ("odp" "otp" "ppt" "pptx")
578 (("pdf" "pdf") ("swf" "swf") ("odp" "odp") ("otp" "otp") ("ppt" "ppt")
579 ("pptx" "pptx") ("odg" "odg"))))
580 "Specify input and output formats of `org-e-odt-convert-process'.
581 More correctly, specify the set of input and output formats that
582 the user is actually interested in.
584 This variable is an alist where each element is of the
585 form (DOCUMENT-CLASS INPUT-FMT-LIST OUTPUT-FMT-ALIST).
586 INPUT-FMT-LIST is a list of INPUT-FMTs. OUTPUT-FMT-ALIST is an
587 alist where each element is of the form (OUTPUT-FMT
588 OUTPUT-FILE-EXTENSION EXTRA-OPTIONS).
590 The variable is interpreted as follows:
591 `org-e-odt-convert-process' can take any document that is in
592 INPUT-FMT-LIST and produce any document that is in the
593 OUTPUT-FMT-LIST. A document converted to OUTPUT-FMT will have
594 OUTPUT-FILE-EXTENSION as the file name extension. OUTPUT-FMT
595 serves dual purposes:
596 - It is used for populating completion candidates during
597 `org-e-odt-convert' commands.
598 - It is used as the value of \"%f\" specifier in
599 `org-e-odt-convert-process'.
601 EXTRA-OPTIONS is used as the value of \"%x\" specifier in
602 `org-e-odt-convert-process'.
604 DOCUMENT-CLASS is used to group a set of file formats in
605 INPUT-FMT-LIST in to a single class.
607 Note that this variable inherently captures how LibreOffice based
608 converters work. LibreOffice maps documents of various formats
609 to classes like Text, Web, Spreadsheet, Presentation etc and
610 allow document of a given class (irrespective of it's source
611 format) to be converted to any of the export formats associated
614 See default setting of this variable for an typical
616 :group
'org-export-e-odt
620 (const :tag
"None" nil
)
621 (alist :tag
"Capabilities"
622 :key-type
(string :tag
"Document Class")
624 (group (repeat :tag
"Input formats" (string :tag
"Input format"))
625 (alist :tag
"Output formats"
626 :key-type
(string :tag
"Output format")
628 (group (string :tag
"Output file extension")
630 (const :tag
"None" nil
)
631 (string :tag
"Extra options"))))))))
633 (defcustom org-e-odt-preferred-output-format nil
634 "Automatically post-process to this format after exporting to \"odt\".
635 Command `org-e-odt-export-to-odt' exports first to \"odt\" format
636 and then uses `org-e-odt-convert-process' to convert the
637 resulting document to this format. During customization of this
638 variable, the list of valid values are populated based on
639 `org-e-odt-convert-capabilities'.
641 You can set this option on per-file basis using file local
642 values. See Info node `(emacs) File Variables'."
643 :group
'org-export-e-odt
645 :type
'(choice :convert-widget
647 (apply 'widget-convert
(widget-type w
)
648 (eval (car (widget-get w
:args
)))))
649 `((const :tag
"None" nil
)
650 ,@(mapcar (lambda (c)
652 (org-e-odt-reachable-formats "odt")))))
654 (put 'org-e-odt-preferred-output-format
'safe-local-variable
'stringp
)
659 (defcustom org-e-odt-format-drawer-function nil
660 "Function called to format a drawer in HTML code.
662 The function must accept two parameters:
663 NAME the drawer name, like \"LOGBOOK\"
664 CONTENTS the contents of the drawer.
666 The function should return the string to be exported.
668 For example, the variable could be set to the following function
669 in order to mimic default behaviour:
671 \(defun org-e-odt-format-drawer-default \(name contents\)
672 \"Format a drawer element for HTML export.\"
674 :group
'org-export-e-odt
680 (defcustom org-e-odt-format-headline-function nil
681 "Function to format headline text.
683 This function will be called with 5 arguments:
684 TODO the todo keyword \(string or nil\).
685 TODO-TYPE the type of todo \(symbol: `todo', `done', nil\)
686 PRIORITY the priority of the headline \(integer or nil\)
687 TEXT the main headline text \(string\).
688 TAGS the tags string, separated with colons \(string or nil\).
690 The function result will be used in the section format string.
692 As an example, one could set the variable to the following, in
693 order to reproduce the default set-up:
695 \(defun org-e-odt-format-headline \(todo todo-type priority text tags\)
696 \"Default format function for an headline.\"
698 \(format \"\\\\textbf{\\\\textsc{\\\\textsf{%s}}} \" todo\)\)
700 \(format \"\\\\framebox{\\\\#%c} \" priority\)\)
702 \(when tags \(format \"\\\\hfill{}\\\\textsc{%s}\" tags\)\)\)\)"
703 :group
'org-export-e-odt
709 (defcustom org-e-odt-format-inlinetask-function nil
710 "Function called to format an inlinetask in HTML code.
712 The function must accept six parameters:
713 TODO the todo keyword, as a string
714 TODO-TYPE the todo type, a symbol among `todo', `done' and nil.
715 PRIORITY the inlinetask priority, as a string
716 NAME the inlinetask name, as a string.
717 TAGS the inlinetask tags, as a string.
718 CONTENTS the contents of the inlinetask, as a string.
720 The function should return the string to be exported.
722 For example, the variable could be set to the following function
723 in order to mimic default behaviour:
725 \(defun org-e-odt-format-inlinetask \(todo type priority name tags contents\)
726 \"Format an inline task element for HTML export.\"
730 \(format \"\\\\textbf{\\\\textsf{\\\\textsc{%s}}} \" todo\)\)
731 \(when priority \(format \"\\\\framebox{\\\\#%c} \" priority\)\)
733 \(when tags \(format \"\\\\hfill{}\\\\textsc{%s}\" tags\)\)\)\)\)
734 \(format \(concat \"\\\\begin{center}\\n\"
736 \"\\\\begin{minipage}[c]{.6\\\\textwidth}\\n\"
738 \"\\\\rule[.8em]{\\\\textwidth}{2pt}\\n\\n\"
740 \"\\\\end{minipage}}\"
741 \"\\\\end{center}\"\)
742 full-title contents\)\)"
743 :group
'org-export-e-odt
749 (defcustom org-e-odt-inline-image-rules
750 '(("file" .
"\\.\\(jpeg\\|jpg\\|png\\|gif\\)\\'"))
751 "Rules characterizing image files that can be inlined into HTML.
753 A rule consists in an association whose key is the type of link
754 to consider, and value is a regexp that will be matched against
757 Note that, by default, the image extension *actually* allowed
758 depend on the way the HTML file is processed. When used with
759 pdflatex, pdf, jpg and png images are OK. When processing
760 through dvi to Postscript, only ps and eps are allowed. The
761 default we use here encompasses both."
762 :group
'org-export-e-odt
763 :type
'(alist :key-type
(string :tag
"Type")
764 :value-type
(regexp :tag
"Path")))
766 (defcustom org-e-odt-pixels-per-inch display-pixels-per-inch
767 "Scaling factor for converting images pixels to inches.
768 Use this for sizing of embedded images. See Info node `(org)
769 Images in ODT export' for more information."
771 :group
'org-export-e-odt
777 (defcustom org-e-odt-quotes
779 ("\\(\\s-\\|[[(]\\|^\\)\"" .
"« ")
780 ("\\(\\S-\\)\"" .
"» ")
781 ("\\(\\s-\\|(\\|^\\)'" .
"'"))
783 ("\\(\\s-\\|[[(]\\|^\\)\"" .
"“")
784 ("\\(\\S-\\)\"" .
"”")
785 ("\\(\\s-\\|(\\|^\\)'" .
"‘")
786 ("\\(\\S-\\)'" .
"’")))
787 "Alist for quotes to use when converting english double-quotes.
789 The CAR of each item in this alist is the language code.
790 The CDR of each item in this alist is a list of three CONS:
791 - the first CONS defines the opening quote;
792 - the second CONS defines the closing quote;
793 - the last CONS defines single quotes.
795 For each item in a CONS, the first string is a regexp
796 for allowed characters before/after the quote, the second
797 string defines the replacement string for this quote."
798 :group
'org-export-e-odt
800 (cons :tag
"Opening quote"
801 (string :tag
"Regexp for char before")
802 (string :tag
"Replacement quote "))
803 (cons :tag
"Closing quote"
804 (string :tag
"Regexp for char after ")
805 (string :tag
"Replacement quote "))
806 (cons :tag
"Single quote"
807 (string :tag
"Regexp for char before")
808 (string :tag
"Replacement quote "))))
813 (defcustom org-e-odt-create-custom-styles-for-srcblocks t
814 "Whether custom styles for colorized source blocks be automatically created.
815 When this option is turned on, the exporter creates custom styles
816 for source blocks based on the advice of `htmlfontify'. Creation
817 of custom styles happen as part of `org-e-odt-hfy-face-to-css'.
819 When this option is turned off exporter does not create such
822 Use the latter option if you do not want the custom styles to be
823 based on your current display settings. It is necessary that the
824 styles.xml already contains needed styles for colorizing to work.
826 This variable is effective only if
827 `org-e-odt-fontify-srcblocks' is turned on."
828 :group
'org-export-e-odt
832 (defcustom org-e-odt-fontify-srcblocks t
833 "Specify whether or not source blocks need to be fontified.
834 Turn this option on if you want to colorize the source code
835 blocks in the exported file. For colorization to work, you need
836 to make available an enhanced version of `htmlfontify' library."
838 :group
'org-export-e-odt
844 (defcustom org-e-odt-table-caption-above t
845 "When non-nil, place caption string at the beginning of the table.
846 Otherwise, place it near the end."
847 :group
'org-export-e-odt
850 (defcustom org-e-odt-table-styles
851 '(("OrgEquation" "OrgEquation"
852 ((use-first-column-styles . t
)
853 (use-last-column-styles . t
))))
854 "Specify how Table Styles should be derived from a Table Template.
855 This is a list where each element is of the
856 form (TABLE-STYLE-NAME TABLE-TEMPLATE-NAME TABLE-CELL-OPTIONS).
858 TABLE-STYLE-NAME is the style associated with the table through
859 \"#+ATTR_ODT: :style TABLE-STYLE-NAME\" line.
861 TABLE-TEMPLATE-NAME is a set of - upto 9 - automatic
862 TABLE-CELL-STYLE-NAMEs and PARAGRAPH-STYLE-NAMEs (as defined
863 below) that is included in
864 `org-e-odt-content-template-file'.
866 TABLE-CELL-STYLE-NAME := TABLE-TEMPLATE-NAME + TABLE-CELL-TYPE +
868 PARAGRAPH-STYLE-NAME := TABLE-TEMPLATE-NAME + TABLE-CELL-TYPE +
870 TABLE-CELL-TYPE := \"FirstRow\" | \"LastColumn\" |
871 \"FirstRow\" | \"LastRow\" |
872 \"EvenRow\" | \"OddRow\" |
873 \"EvenColumn\" | \"OddColumn\" | \"\"
874 where \"+\" above denotes string concatenation.
876 TABLE-CELL-OPTIONS is an alist where each element is of the
877 form (TABLE-CELL-STYLE-SELECTOR . ON-OR-OFF).
878 TABLE-CELL-STYLE-SELECTOR := `use-first-row-styles' |
879 `use-last-row-styles' |
880 `use-first-column-styles' |
881 `use-last-column-styles' |
882 `use-banding-rows-styles' |
883 `use-banding-columns-styles' |
884 `use-first-row-styles'
885 ON-OR-OFF := `t' | `nil'
887 For example, with the following configuration
889 \(setq org-e-odt-table-styles
890 '\(\(\"TableWithHeaderRowsAndColumns\" \"Custom\"
891 \(\(use-first-row-styles . t\)
892 \(use-first-column-styles . t\)\)\)
893 \(\"TableWithHeaderColumns\" \"Custom\"
894 \(\(use-first-column-styles . t\)\)\)\)\)
896 1. A table associated with \"TableWithHeaderRowsAndColumns\"
897 style will use the following table-cell styles -
898 \"CustomFirstRowTableCell\", \"CustomFirstColumnTableCell\",
899 \"CustomTableCell\" and the following paragraph styles
900 \"CustomFirstRowTableParagraph\",
901 \"CustomFirstColumnTableParagraph\", \"CustomTableParagraph\"
904 2. A table associated with \"TableWithHeaderColumns\" style will
905 use the following table-cell styles -
906 \"CustomFirstColumnTableCell\", \"CustomTableCell\" and the
907 following paragraph styles
908 \"CustomFirstColumnTableParagraph\", \"CustomTableParagraph\"
911 Note that TABLE-TEMPLATE-NAME corresponds to the
912 \"<table:table-template>\" elements contained within
913 \"<office:styles>\". The entries (TABLE-STYLE-NAME
914 TABLE-TEMPLATE-NAME TABLE-CELL-OPTIONS) correspond to
915 \"table:template-name\" and \"table:use-first-row-styles\" etc
916 attributes of \"<table:table>\" element. Refer ODF-1.2
917 specification for more information. Also consult the
918 implementation filed under `org-e-odt-get-table-cell-styles'.
920 The TABLE-STYLE-NAME \"OrgEquation\" is used internally for
921 formatting of numbered display equations. Do not delete this
922 style from the list."
923 :group
'org-export-e-odt
926 (const :tag
"None" nil
)
927 (repeat :tag
"Table Styles"
928 (list :tag
"Table Style Specification"
929 (string :tag
"Table Style Name")
930 (string :tag
"Table Template Name")
931 (alist :options
(use-first-row-styles
933 use-first-column-styles
934 use-last-column-styles
935 use-banding-rows-styles
936 use-banding-columns-styles
)
938 :value-type
(const :tag
"True" t
))))))
942 ;;; Internal functions
946 (defun org-e-odt--date (&optional org-ts fmt
)
949 (and (stringp org-ts
)
950 (string-match org-ts-regexp0 org-ts
)
952 (org-fix-decoded-time
953 (org-parse-time-string (match-string 0 org-ts
) t
)))))
956 (fmt (format-time-string fmt time
))
957 (t (setq date
(format-time-string "%Y-%m-%dT%H:%M:%S%z" time
))
958 (format "%s:%s" (substring date
0 -
2) (substring date -
2)))))))
962 (defun org-e-odt--frame (text width height style
&optional extra
966 (if width
(format " svg:width=\"%0.2fcm\"" width
) "")
967 (if height
(format " svg:height=\"%0.2fcm\"" height
) "")
969 (format " text:anchor-type=\"%s\"" (or anchor-type
"paragraph")))))
971 "\n<draw:frame draw:style-name=\"%s\"%s>\n%s\n</draw:frame>"
974 (let ((title (get-text-property 0 :title text
))
975 (desc (get-text-property 0 :description text
)))
977 (format "<svg:title>%s</svg:title>"
978 (org-e-odt-encode-plain-text title t
)))
980 (format "<svg:desc>%s</svg:desc>"
981 (org-e-odt-encode-plain-text desc t
)))))))))
986 (defun org-e-odt--copy-image-file (path)
987 "Returns the internal name of the file"
988 (let* ((image-type (file-name-extension path
))
989 (media-type (format "image/%s" image-type
))
990 (target-dir "Images/")
992 (format "%s%04d.%s" target-dir
993 (incf org-e-odt-embedded-images-count
) image-type
)))
994 (message "Embedding %s as %s ..."
995 (substring-no-properties path
) target-file
)
997 (when (= 1 org-e-odt-embedded-images-count
)
998 (make-directory (concat org-e-odt-zip-dir target-dir
))
999 (org-e-odt-create-manifest-file-entry "" target-dir
))
1001 (copy-file path
(concat org-e-odt-zip-dir target-file
) 'overwrite
)
1002 (org-e-odt-create-manifest-file-entry media-type target-file
)
1005 (defun org-e-odt--image-size (file &optional user-width
1006 user-height scale dpi embed-as
)
1007 (let* ((--pixels-to-cms
1008 (function (lambda (pixels dpi
)
1009 (let ((cms-per-inch 2.54)
1010 (inches (/ pixels dpi
)))
1011 (* cms-per-inch inches
)))))
1014 (lambda (size-in-pixels dpi
)
1016 (cons (funcall --pixels-to-cms
(car size-in-pixels
) dpi
)
1017 (funcall --pixels-to-cms
(cdr size-in-pixels
) dpi
))))))
1018 (dpi (or dpi org-e-odt-pixels-per-inch
))
1019 (anchor-type (or embed-as
"paragraph"))
1020 (user-width (and (not scale
) user-width
))
1021 (user-height (and (not scale
) user-height
))
1024 (not (and user-height user-width
))
1027 (and (executable-find "identify")
1028 (let ((size-in-pixels
1029 (let ((dim (shell-command-to-string
1030 (format "identify -format \"%%w:%%h\" \"%s\""
1032 (when (string-match "\\([0-9]+\\):\\([0-9]+\\)" dim
)
1033 (cons (string-to-number (match-string 1 dim
))
1034 (string-to-number (match-string 2 dim
)))))))
1035 (funcall --size-in-cms size-in-pixels dpi
)))
1037 (let ((size-in-pixels
1038 (ignore-errors ; Emacs could be in batch mode
1040 (image-size (create-image file
) 'pixels
))))
1041 (funcall --size-in-cms size-in-pixels dpi
))
1042 ;; Use hard-coded values.
1043 (cdr (assoc-string anchor-type
1044 org-e-odt-default-image-sizes-alist
))
1046 (error "Cannot determine Image size. Aborting ..."))))
1047 (width (car size
)) (height (cdr size
)))
1050 (setq width
(* width scale
) height
(* height scale
)))
1051 ((and user-height user-width
)
1052 (setq width user-width height user-height
))
1054 (setq width
(* user-height
(/ width height
)) height user-height
))
1056 (setq height
(* user-width
(/ height width
)) width user-width
))
1058 ;; ensure that an embedded image fits comfortably within a page
1059 (let ((max-width (car org-e-odt-max-image-size
))
1060 (max-height (cdr org-e-odt-max-image-size
)))
1061 (when (or (> width max-width
) (> height max-height
))
1062 (let* ((scale1 (/ max-width width
))
1063 (scale2 (/ max-height height
))
1064 (scale (min scale1 scale2
)))
1065 (setq width
(* scale width
) height
(* scale height
)))))
1066 (cons width height
)))
1068 (defun org-e-odt-link--inline-image (element info
)
1069 "Return HTML code for an inline image.
1070 LINK is the link pointing to the inline image. INFO is a plist
1071 used as a communication channel."
1073 ((eq (org-element-type element
) 'link
)
1074 (let* ((type (org-element-property :type element
))
1075 (raw-path (org-element-property :path element
)))
1076 (cond ((member type
'("http" "https"))
1077 (concat type
":" raw-path
))
1078 ((file-name-absolute-p raw-path
)
1079 (expand-file-name raw-path
))
1081 ((member (org-element-type element
)
1082 '(latex-fragment latex-environment
))
1083 (let* ((latex-frag (org-remove-indentation
1084 (org-element-property :value element
)))
1085 (formula-link (org-e-odt-format-latex
1086 latex-frag
'dvipng info
)))
1088 (string-match "file:\\([^]]*\\)" formula-link
)
1089 (match-string 1 formula-link
))))
1090 (t (error "what is this?"))))
1091 (src-expanded (if (file-name-absolute-p src
) src
1092 (expand-file-name src
(file-name-directory
1093 (plist-get info
:input-file
)))))
1095 "\n<draw:image xlink:href=\"%s\" xlink:type=\"simple\" xlink:show=\"embed\" xlink:actuate=\"onLoad\"/>"
1096 (org-e-odt--copy-image-file src-expanded
)))
1097 ;; extract attributes from #+ATTR_ODT line.
1098 (attr-from (case (org-element-type element
)
1099 (link (org-export-get-parent-element element
))
1101 ;; convert attributes to a plist.
1102 (attr-plist (org-export-read-attribute :attr_odt attr-from
))
1103 ;; handle `:anchor', `:style' and `:attributes' properties.
1105 (car (assoc-string (plist-get attr-plist
:anchor
)
1106 '(("as-char") ("paragraph") ("page")) t
)))
1108 (and user-frame-anchor
(plist-get attr-plist
:style
)))
1110 (and user-frame-anchor
(plist-get attr-plist
:attributes
)))
1112 (list user-frame-style user-frame-attrs user-frame-anchor
))
1113 ;; (embed-as (or embed-as user-frame-anchor "paragraph"))
1115 ;; handle `:width', `:height' and `:scale' properties.
1116 (size (org-e-odt--image-size
1117 src-expanded
(plist-get attr-plist
:width
)
1118 (plist-get attr-plist
:height
)
1119 (plist-get attr-plist
:scale
) nil
;; embed-as
1122 (width (car size
)) (height (cdr size
))
1124 (case (org-element-type element
)
1125 ((org-e-odt-standalone-image-p element info
) "paragraph")
1126 (latex-fragment "as-char")
1127 (latex-environment "paragraph")
1129 (captions (org-e-odt-format-label element info
'definition
))
1130 (caption (car captions
)) (short-caption (cdr captions
))
1131 (entity (concat (and caption
"Captioned") embed-as
"Image")))
1132 (org-e-odt-format-entity entity href width height
1133 captions user-frame-params
)))
1135 ;;;; Library wrappers
1137 (defun org-e-odt--zip-extract (archive members target
)
1138 (when (atom members
) (setq members
(list members
)))
1139 (mapc (lambda (archive member target
)
1141 (let* ((--quote-file-name
1142 ;; This is shamelessly stolen from `archive-zip-extract'.
1144 (if (or (not (memq system-type
'(windows-nt ms-dos
)))
1145 (and (boundp 'w32-quote-process-args
)
1146 (null w32-quote-process-args
)))
1147 (shell-quote-argument name
)
1149 (target (funcall --quote-file-name target
))
1150 (archive (expand-file-name archive
))
1151 (archive-zip-extract
1152 (list "unzip" "-qq" "-o" "-d" target
))
1153 exit-code command-output
)
1154 (setq command-output
1156 (setq exit-code
(archive-zip-extract archive member
))
1158 (unless (zerop exit-code
)
1159 (message command-output
)
1160 (error "Extraction failed"))))
1166 (defun org-e-odt--target (text id
)
1169 (format "\n<text:bookmark-start text:name=\"OrgXref.%s\"/>" id
)
1170 (format "\n<text:bookmark text:name=\"%s\"/>" id
) text
1171 (format "\n<text:bookmark-end text:name=\"OrgXref.%s\"/>" id
))))
1175 (defun org-e-odt--textbox (text width height style
&optional
1178 (format "\n<draw:text-box %s>%s\n</draw:text-box>"
1179 (concat (format " fo:min-height=\"%0.2fcm\"" (or height
.2))
1181 (format " fo:min-width=\"%0.2fcm\"" (or width
.2))))
1183 width nil style extra anchor-type
))
1187 ;;;; Table of Contents
1189 (defun org-e-odt-begin-toc (index-title depth
)
1192 <text:table-of-content text:style-name=\"Sect2\" text:protected=\"true\" text:name=\"Table of Contents1\">
1193 <text:table-of-content-source text:outline-level=\"%d\">
1194 <text:index-title-template text:style-name=\"Contents_20_Heading\">%s</text:index-title-template>
1195 " depth index-title
)
1197 (let ((levels (number-sequence 1 10)))
1202 <text:table-of-content-entry-template text:outline-level=\"%d\" text:style-name=\"Contents_20_%d\">
1203 <text:index-entry-link-start text:style-name=\"Internet_20_link\"/>
1204 <text:index-entry-chapter/>
1205 <text:index-entry-text/>
1206 <text:index-entry-link-end/>
1207 </text:table-of-content-entry-template>
1208 " level level
)) levels
""))
1211 </text:table-of-content-source>
1214 <text:index-title text:style-name=\"Sect1\" text:name=\"Table of Contents1_Head\">
1215 <text:p text:style-name=\"Contents_20_Heading\">%s</text:p>
1219 (defun org-e-odt-end-toc ()
1222 </text:table-of-content>
1227 (defun* org-e-odt-format-toc-headline
1228 (todo todo-type priority text tags
1229 &key level section-number headline-label
&allow-other-keys
)
1231 (and org-export-with-section-numbers
1232 (concat section-number
". "))
1237 (format "<text:span text:style-name=\"%s\">%s</text:span>"
1240 (setq text
(format "<text:span text:style-name=\"%s\">%s</text:span>"
1242 (format "<text:a xlink:type=\"simple\" xlink:href=\"#%s\">%s</text:a>"
1243 headline-label text
))
1245 (defun org-e-odt-toc (depth info
)
1246 (assert (wholenump depth
))
1247 (let* ((title (org-export-translate "Table of Contents" :utf-8 info
))
1248 (headlines (org-export-collect-headlines
1249 info
(and (wholenump depth
) depth
))))
1252 (org-e-odt-begin-toc title depth
)
1255 (let* ((entry (org-e-odt-format-headline--wrap
1256 headline info
'org-e-odt-format-toc-headline
))
1257 (level (org-export-get-relative-level headline info
))
1258 (style (format "Contents_20_%d" level
)))
1259 (format "\n<text:p text:style-name=\"%s\">%s</text:p>"
1262 (org-e-odt-end-toc)))))
1265 ;;;; Document styles
1267 (defun org-e-odt-add-automatic-style (object-type &optional object-props
)
1268 "Create an automatic style of type OBJECT-TYPE with param OBJECT-PROPS.
1269 OBJECT-PROPS is (typically) a plist created by passing
1270 \"#+ATTR_ODT: \" option of the object in question to
1271 `org-e-odt-parse-block-attributes'.
1273 Use `org-e-odt-object-counters' to generate an automatic
1274 OBJECT-NAME and STYLE-NAME. If OBJECT-PROPS is non-nil, add a
1275 new entry in `org-e-odt-automatic-styles'. Return (OBJECT-NAME
1277 (assert (stringp object-type
))
1278 (let* ((object (intern object-type
))
1280 (seqno (1+ (or (plist-get org-e-odt-object-counters seqvar
) 0)))
1281 (object-name (format "%s%d" object-type seqno
)) style-name
)
1282 (setq org-e-odt-object-counters
1283 (plist-put org-e-odt-object-counters seqvar seqno
))
1285 (setq style-name
(format "Org%s" object-name
))
1286 (setq org-e-odt-automatic-styles
1287 (plist-put org-e-odt-automatic-styles object
1288 (append (list (list style-name object-props
))
1289 (plist-get org-e-odt-automatic-styles object
)))))
1290 (cons object-name style-name
)))
1293 ;;;; Caption and Labels
1296 (defun org-e-odt--wrap-label (element output
)
1297 "Wrap label associated to ELEMENT around OUTPUT, if appropriate.
1298 This function shouldn't be used for floats. See
1299 `org-e-odt--caption/label-string'."
1300 ;; (let ((label (org-element-property :name element)))
1301 ;; (if (or (not output) (not label) (string= output "") (string= label ""))
1303 ;; (concat (format "\\label{%s}\n" label) output)))
1307 (defun org-e-odt--caption/label-string
(caption label info
)
1308 "Return caption and label HTML string for floats.
1310 CAPTION is a cons cell of secondary strings, the car being the
1311 standard caption and the cdr its short form. LABEL is a string
1312 representing the label. INFO is a plist holding contextual
1315 If there's no caption nor label, return the empty string.
1317 For non-floats, see `org-e-odt--wrap-label'."
1318 (setq label nil
) ;; FIXME
1320 (let ((label-str (if label
(format "\\label{%s}" label
) "")))
1322 ((and (not caption
) (not label
)) "")
1323 ((not caption
) (format "\\label{%s}\n" label
))
1324 ;; Option caption format with short name.
1326 (format "\\caption[%s]{%s%s}\n"
1327 (org-export-data (cdr caption
) info
)
1329 (org-export-data (car caption
) info
)))
1330 ;; Standard caption format.
1331 ;; (t (format "\\caption{%s%s}\n"
1333 ;; (org-export-data (car caption) info)))
1334 (t (org-export-data (car caption
) info
)))))
1338 (defun org-e-odt--checkbox (item)
1339 "Return check-box string associated to ITEM."
1340 (let ((checkbox (org-element-property :checkbox item
)))
1341 (if (not checkbox
) ""
1342 (format "<text:span text:style-name=\"%s\">%s</text:span>"
1343 "OrgCode" (case checkbox
1344 (on "[✓] ") ; CHECK MARK
1350 (defun org-e-odt-template (contents info
)
1351 "Return complete document string after HTML conversion.
1352 CONTENTS is the transcoded contents string. RAW-DATA is the
1353 original parsed data. INFO is a plist holding export options."
1355 (let ((title (org-export-data (plist-get info
:title
) info
))
1356 (author (let ((author (plist-get info
:author
)))
1357 (if (not author
) "" (org-export-data author info
))))
1358 (date (org-e-odt--date
1359 (org-export-data (plist-get info
:date
) info
)))
1360 (email (plist-get info
:email
))
1361 (keywords (plist-get info
:keywords
))
1362 (description (plist-get info
:description
)))
1365 "<?xml version=\"1.0\" encoding=\"UTF-8\"?>
1366 <office:document-meta
1367 xmlns:office=\"urn:oasis:names:tc:opendocument:xmlns:office:1.0\"
1368 xmlns:xlink=\"http://www.w3.org/1999/xlink\"
1369 xmlns:dc=\"http://purl.org/dc/elements/1.1/\"
1370 xmlns:meta=\"urn:oasis:names:tc:opendocument:xmlns:meta:1.0\"
1371 xmlns:ooo=\"http://openoffice.org/2004/office\"
1372 office:version=\"1.2\">
1374 (format "<dc:creator>%s</dc:creator>\n" author
)
1375 (format "<meta:initial-creator>%s</meta:initial-creator>\n" author
)
1376 (format "<dc:date>%s</dc:date>\n" date
)
1377 (format "<meta:creation-date>%s</meta:creation-date>\n" date
)
1378 (format "<meta:generator>%s</meta:generator>\n"
1379 (let ((creator-info (plist-get info
:with-creator
)))
1380 (if (or (not creator-info
) (eq creator-info
'comment
)) ""
1381 (plist-get info
:creator
))))
1382 (format "<meta:keyword>%s</meta:keyword>\n" keywords
)
1383 (format "<dc:subject>%s</dc:subject>\n" description
)
1384 (format "<dc:title>%s</dc:title>\n" title
)
1386 " </office:meta>\n" "</office:document-meta>")
1387 nil
(concat org-e-odt-zip-dir
"meta.xml"))
1388 ;; Add meta.xml in to manifest.
1389 (org-e-odt-create-manifest-file-entry "text/xml" "meta.xml"))
1391 ;; Update styles file.
1392 ;; Copy styles.xml. Also dump htmlfontify styles, if there is any.
1393 ;; Write styles file.
1394 (let* ((styles-file (plist-get info
:odt-styles-file
))
1395 (styles-file (and styles-file
(read (org-trim styles-file
))))
1396 ;; Non-availability of styles.xml is not a critical
1397 ;; error. For now throw an error purely for aesthetic
1399 (styles-file (or styles-file
1400 org-e-odt-styles-file
1401 (expand-file-name "OrgOdtStyles.xml"
1402 org-e-odt-styles-dir
)
1403 (error "org-e-odt: Missing styles file?"))))
1405 ((listp styles-file
)
1406 (let ((archive (nth 0 styles-file
))
1407 (members (nth 1 styles-file
)))
1408 (org-e-odt--zip-extract archive members org-e-odt-zip-dir
)
1411 (when (org-file-image-p member
)
1412 (let* ((image-type (file-name-extension member
))
1413 (media-type (format "image/%s" image-type
)))
1414 (org-e-odt-create-manifest-file-entry media-type member
))))
1416 ((and (stringp styles-file
) (file-exists-p styles-file
))
1417 (let ((styles-file-type (file-name-extension styles-file
)))
1419 ((string= styles-file-type
"xml")
1420 (copy-file styles-file
(concat org-e-odt-zip-dir
"styles.xml") t
))
1421 ((member styles-file-type
'("odt" "ott"))
1422 (org-e-odt--zip-extract styles-file
"styles.xml" org-e-odt-zip-dir
)))))
1424 (error (format "Invalid specification of styles.xml file: %S"
1425 org-e-odt-styles-file
))))
1427 ;; create a manifest entry for styles.xml
1428 (org-e-odt-create-manifest-file-entry "text/xml" "styles.xml")
1430 ;; FIXME: Who is opening an empty styles.xml before this point?
1431 (with-current-buffer
1432 (find-file-noselect (concat org-e-odt-zip-dir
"styles.xml") t
)
1435 ;; Write custom styles for source blocks
1436 ;; Save STYLES used for colorizing of source blocks.
1437 ;; Update styles.xml with styles that were collected as part of
1438 ;; `org-e-odt-hfy-face-to-css' callbacks.
1439 (let ((styles (mapconcat (lambda (style) (format " %s\n" (cddr style
)))
1440 hfy-user-sheet-assoc
"")))
1442 (goto-char (point-min))
1443 (when (re-search-forward "</office:styles>" nil t
)
1444 (goto-char (match-beginning 0))
1445 (insert "\n<!-- Org Htmlfontify Styles -->\n" styles
"\n"))))
1447 ;; Update styles.xml - take care of outline numbering
1449 ;; Don't make automatic backup of styles.xml file. This setting
1450 ;; prevents the backed-up styles.xml file from being zipped in to
1451 ;; odt file. This is more of a hackish fix. Better alternative
1452 ;; would be to fix the zip command so that the output odt file
1453 ;; includes only the needed files and excludes any auto-generated
1454 ;; extra files like backups and auto-saves etc etc. Note that
1455 ;; currently the zip command zips up the entire temp directory so
1456 ;; that any auto-generated files created under the hood ends up in
1457 ;; the resulting odt file.
1458 (set (make-local-variable 'backup-inhibited
) t
)
1460 ;; Outline numbering is retained only upto LEVEL.
1461 ;; To disable outline numbering pass a LEVEL of 0.
1463 (goto-char (point-min))
1465 "<text:outline-level-style\\([^>]*\\)text:level=\"\\([^\"]*\\)\"\\([^>]*\\)>")
1467 "<text:outline-level-style\\1text:level=\"\\2\" style:num-format=\"\">"))
1468 (while (re-search-forward regex nil t
)
1469 (unless (let ((sec-num (plist-get info
:section-numbers
))
1470 (level (string-to-number (match-string 2))))
1471 (if (wholenump sec-num
) (<= level sec-num
) sec-num
))
1472 (replace-match replacement t nil
))))
1474 ;; Update content.xml.
1476 (insert-file-contents
1477 (or org-e-odt-content-template-file
1478 (expand-file-name "OrgOdtContentTemplate.xml"
1479 org-e-odt-styles-dir
)))
1480 ;; Write automatic styles.
1481 ;; - Position the cursor.
1482 (goto-char (point-min))
1483 (re-search-forward " </office:automatic-styles>" nil t
)
1484 (goto-char (match-beginning 0))
1485 ;; - Dump automatic table styles
1486 (loop for
(style-name props
) in
1487 (plist-get org-e-odt-automatic-styles
'Table
) do
1488 (when (setq props
(or (plist-get props
:rel-width
) 96))
1489 (insert (format org-e-odt-table-style-format style-name props
))))
1490 ;; Update display level.
1491 ;; - Remove existing sequence decls. Also position the cursor.
1492 (goto-char (point-min))
1493 (when (re-search-forward "<text:sequence-decls" nil t
)
1494 (delete-region (match-beginning 0)
1495 (re-search-forward "</text:sequence-decls>" nil nil
)))
1496 ;; Update sequence decls according to user preference.
1499 "\n<text:sequence-decls>\n%s\n</text:sequence-decls>"
1503 "<text:sequence-decl text:display-outline-level=\"%d\" text:name=\"%s\"/>"
1504 org-e-odt-display-outline-level
(nth 1 x
)))
1505 org-e-odt-category-map-alist
"\n")))
1506 ;; Position the cursor to document body.
1507 (goto-char (point-min))
1508 (re-search-forward "</office:text>" nil nil
)
1509 (goto-char (match-beginning 0))
1511 ;; Preamble - Title, Author, Date etc.
1513 (let* ((title (org-export-data (plist-get info
:title
) info
))
1514 (author (and (plist-get info
:with-author
)
1515 (let ((auth (plist-get info
:author
)))
1516 (and auth
(org-export-data auth info
)))))
1517 (date (org-export-data (plist-get info
:date
) info
))
1518 (iso-date (org-e-odt--date date
))
1519 (date (org-e-odt--date date
"%d %b %Y"))
1520 (email (plist-get info
:email
))
1521 ;; switch on or off above vars based on user settings
1522 (author (and (plist-get info
:with-author
) (or author email
)))
1523 ;; (date (and (plist-get info :time-stamp-file) date))
1524 (email (and (plist-get info
:with-email
) email
)))
1529 (format "\n<text:p text:style-name=\"%s\">%s</text:p>"
1530 "OrgTitle" (format "\n<text:title>%s</text:title>" title
))
1532 "\n<text:p text:style-name=\"OrgTitle\"/>"))
1534 ((and author
(not email
))
1537 (format "\n<text:p text:style-name=\"%s\">%s</text:p>"
1539 (format "<text:initial-creator>%s</text:initial-creator>" author
))
1541 "\n<text:p text:style-name=\"OrgSubtitle\"/>"))
1546 "\n<text:p text:style-name=\"%s\">%s</text:p>"
1549 "<text:a xlink:type=\"simple\" xlink:href=\"%s\">%s</text:a>"
1550 (concat "mailto:" email
)
1551 (format "<text:initial-creator>%s</text:initial-creator>" author
)))
1553 "\n<text:p text:style-name=\"OrgSubtitle\"/>")))
1558 "\n<text:p text:style-name=\"%s\">%s</text:p>"
1561 "\n<text:date style:data-style-name=\"%s\" text:date-value=\"%s\">%s</text:date>"
1563 "OrgDate" iso-date date
))
1565 "<text:p text:style-name=\"OrgSubtitle\"/>")))))
1566 ;; Table of Contents
1567 (let* ((with-toc (plist-get info
:with-toc
))
1568 (depth (and with-toc
(if (wholenump with-toc
)
1570 (plist-get info
:headline-levels
)))))
1571 (when depth
(insert (or (org-e-odt-toc depth info
) ""))))
1575 (buffer-substring-no-properties (point-min) (point-max))))
1579 ;;; Transcode Functions
1583 (defun org-e-odt-bold (bold contents info
)
1584 "Transcode BOLD from Org to ODT.
1585 CONTENTS is the text with bold markup. INFO is a plist holding
1586 contextual information."
1587 (format "<text:span text:style-name=\"%s\">%s</text:span>"
1593 (defun org-e-odt-center-block (center-block contents info
)
1594 "Transcode a CENTER-BLOCK element from Org to ODT.
1595 CONTENTS holds the contents of the center block. INFO is a plist
1596 holding contextual information."
1597 (org-e-odt--wrap-label center-block contents
))
1602 (defun org-e-odt-clock (clock contents info
)
1603 "Transcode a CLOCK element from Org to ODT.
1604 CONTENTS is nil. INFO is a plist used as a communication
1606 (format "<text:span text:style-name=\"%s\">%s</text:span>"
1607 "OrgTimestampWrapper"
1609 (format "<text:span text:style-name=\"%s\">%s</text:span>"
1610 "OrgTimestampKeyword" org-clock-string
)
1611 (format "<text:span text:style-name=\"%s\">%s</text:span>"
1613 (concat (org-translate-time
1614 (org-element-property :value clock
))
1615 (let ((time (org-element-property :time clock
)))
1616 (and time
(format " (%s)" time
))))))))
1621 (defun org-e-odt-code (code contents info
)
1622 "Transcode a CODE object from Org to ODT.
1623 CONTENTS is nil. INFO is a plist used as a communication
1625 (format "<text:span text:style-name=\"%s\">%s</text:span>"
1626 "OrgCode" (org-element-property :value code
)))
1631 ;; Comments are ignored.
1636 ;; Comment Blocks are ignored.
1641 (defun org-e-odt-drawer (drawer contents info
)
1642 "Transcode a DRAWER element from Org to ODT.
1643 CONTENTS holds the contents of the block. INFO is a plist
1644 holding contextual information."
1645 (let* ((name (org-element-property :drawer-name drawer
))
1646 (output (if (functionp org-e-odt-format-drawer-function
)
1647 (funcall org-e-odt-format-drawer-function
1649 ;; If there's no user defined function: simply
1650 ;; display contents of the drawer.
1652 (org-e-odt--wrap-label drawer output
)))
1657 (defun org-e-odt-dynamic-block (dynamic-block contents info
)
1658 "Transcode a DYNAMIC-BLOCK element from Org to ODT.
1659 CONTENTS holds the contents of the block. INFO is a plist
1660 holding contextual information. See `org-export-data'."
1661 (org-e-odt--wrap-label dynamic-block contents
))
1666 (defun org-e-odt-entity (entity contents info
)
1667 "Transcode an ENTITY object from Org to ODT.
1668 CONTENTS are the definition itself. INFO is a plist holding
1669 contextual information."
1670 ;; (let ((ent (org-element-property :latex entity)))
1671 ;; (if (org-element-property :latex-math-p entity)
1672 ;; (format "$%s$" ent)
1674 (org-element-property :utf-8 entity
))
1679 (defun org-e-odt-example-block (example-block contents info
)
1680 "Transcode a EXAMPLE-BLOCK element from Org to ODT.
1681 CONTENTS is nil. INFO is a plist holding contextual information."
1682 (org-e-odt--wrap-label
1683 example-block
(org-e-odt-format-code example-block info
)))
1688 (defun org-e-odt-export-snippet (export-snippet contents info
)
1689 "Transcode a EXPORT-SNIPPET object from Org to ODT.
1690 CONTENTS is nil. INFO is a plist holding contextual information."
1691 (when (eq (org-export-snippet-backend export-snippet
) 'e-odt
)
1692 (org-element-property :value export-snippet
)))
1697 (defun org-e-odt-export-block (export-block contents info
)
1698 "Transcode a EXPORT-BLOCK element from Org to ODT.
1699 CONTENTS is nil. INFO is a plist holding contextual information."
1700 (when (string= (org-element-property :type export-block
) "ODT")
1701 (org-remove-indentation (org-element-property :value export-block
))))
1706 (defun org-e-odt-fixed-width (fixed-width contents info
)
1707 "Transcode a FIXED-WIDTH element from Org to ODT.
1708 CONTENTS is nil. INFO is a plist holding contextual information."
1709 (org-e-odt--wrap-label
1710 fixed-width
(org-e-odt-do-format-code
1711 (org-element-property :value fixed-width
))))
1714 ;;;; Footnote Definition
1716 ;; Footnote Definitions are ignored.
1719 ;;;; Footnote Reference
1721 (defun org-e-odt-footnote-reference (footnote-reference contents info
)
1722 "Transcode a FOOTNOTE-REFERENCE element from Org to ODT.
1723 CONTENTS is nil. INFO is a plist holding contextual information."
1724 (let ((--format-footnote-definition
1727 (setq n
(format "%d" n
))
1728 (let ((id (concat "fn" n
))
1729 (note-class "footnote")
1730 (par-style "Footnote"))
1732 "<text:note text:id=\"%s\" text:note-class=\"%s\">%s</text:note>"
1735 (format "<text:note-citation>%s</text:note-citation>" n
)
1736 (format "<text:note-body>%s</text:note-body>" def
)))))))
1737 (--format-footnote-reference
1740 (setq n
(format "%d" n
))
1741 (let ((note-class "footnote")
1743 (ref-name (concat "fn" n
)))
1745 "<text:span text:style-name=\"%s\">%s</text:span>"
1747 (format "<text:note-ref text:note-class=\"%s\" text:reference-format=\"%s\" text:ref-name=\"%s\">%s</text:note-ref>"
1748 note-class ref-format ref-name n
)))))))
1750 ;; Insert separator between two footnotes in a row.
1751 (let ((prev (org-export-get-previous-element footnote-reference info
)))
1752 (and (eq (org-element-type prev
) 'footnote-reference
)
1753 (format "<text:span text:style-name=\"%s\">%s</text:span>"
1754 "OrgSuperscript" ",")))
1755 ;; Trancode footnote reference.
1756 (let ((n (org-export-get-footnote-number footnote-reference info
)))
1758 ((not (org-export-footnote-first-reference-p footnote-reference info
))
1759 (funcall --format-footnote-reference n
))
1760 ;; Inline definitions are secondary strings.
1761 ;; Non-inline footnotes definitions are full Org data.
1763 (let* ((raw (org-export-get-footnote-definition footnote-reference
1765 (def (let ((def (org-trim (org-export-data raw info
))))
1766 (if (eq (org-element-type raw
) 'org-data
) def
1767 (format "\n<text:p text:style-name=\"%s\">%s</text:p>"
1769 (funcall --format-footnote-definition n def
))))))))
1774 (defun* org-e-odt-format-headline
1775 (todo todo-type priority text tags
1776 &key level section-number headline-label
&allow-other-keys
)
1781 (let ((style (if (member todo org-done-keywords
) "OrgDone" "OrgTodo")))
1782 (format "<text:span text:style-name=\"%s\">%s</text:span>"
1788 (concat "<text:tab/>"
1789 (format "<text:span text:style-name=\"%s\">%s</text:span>"
1790 "OrgTag" (mapconcat 'org-trim tags
" : "))))))
1792 (defun org-e-odt-format-headline--wrap (headline info
1793 &optional format-function
1795 "Transcode an HEADLINE element from Org to ODT.
1796 CONTENTS holds the contents of the headline. INFO is a plist
1797 holding contextual information."
1798 (let* ((level (+ (org-export-get-relative-level headline info
)))
1799 (headline-number (org-export-get-headline-number headline info
))
1800 (section-number (and (org-export-numbered-headline-p headline info
)
1801 (mapconcat 'number-to-string
1802 headline-number
".")))
1803 (todo (and (plist-get info
:with-todo-keywords
)
1804 (let ((todo (org-element-property :todo-keyword headline
)))
1805 (and todo
(org-export-data todo info
)))))
1806 (todo-type (and todo
(org-element-property :todo-type headline
)))
1807 (priority (and (plist-get info
:with-priority
)
1808 (org-element-property :priority headline
)))
1809 (text (org-export-data (org-element-property :title headline
) info
))
1810 (tags (and (plist-get info
:with-tags
)
1811 (org-export-get-tags headline info
)))
1812 (headline-label (concat "sec-" (mapconcat 'number-to-string
1813 headline-number
"-")))
1814 (format-function (cond
1815 ((functionp format-function
) format-function
)
1816 ((functionp org-e-odt-format-headline-function
)
1818 (lambda (todo todo-type priority text tags
1820 (funcall org-e-odt-format-headline-function
1821 todo todo-type priority text tags
))))
1822 (t 'org-e-odt-format-headline
))))
1823 (apply format-function
1824 todo todo-type priority text tags
1825 :headline-label headline-label
:level level
1826 :section-number section-number extra-keys
)))
1828 (defun org-e-odt-headline (headline contents info
)
1829 "Transcode an HEADLINE element from Org to ODT.
1830 CONTENTS holds the contents of the headline. INFO is a plist
1831 holding contextual information."
1832 ;; Case 1: This is a footnote section: ignore it.
1833 (unless (org-element-property :footnote-section-p headline
)
1834 (let* ((text (org-export-data (org-element-property :title headline
) info
))
1835 ;; Create the headline text.
1836 (full-text (org-e-odt-format-headline--wrap headline info
))
1837 ;; Get level relative to current parsed data.
1838 (level (org-export-get-relative-level headline info
))
1839 ;; Get canonical label for the headline.
1840 (id (concat "sec-" (mapconcat 'number-to-string
1841 (org-export-get-headline-number
1842 headline info
) "-")))
1843 ;; Get user-specified labels for the headline.
1844 (extra-ids (list (org-element-property :custom-id headline
)
1845 (org-element-property :id headline
)))
1848 (mapconcat (lambda (x)
1850 (let ((x (if (org-uuidgen-p x
) (concat "ID-" x
) x
)))
1852 "" (org-export-solidify-link-text x
)))))
1855 (anchored-title (org-e-odt--target full-text id
)))
1857 ;; Case 2. This is a deep sub-tree: export it as a list item.
1858 ;; Also export as items headlines for which no section
1859 ;; format has been found.
1860 ((org-export-low-level-p headline info
)
1861 ;; Build the real contents of the sub-tree.
1863 (and (org-export-first-sibling-p headline info
)
1864 (format "\n<text:list text:style-name=\"%s\" %s>"
1865 ;; Choose style based on list type.
1866 (if (org-export-numbered-headline-p headline info
)
1867 "OrgNumberedList" "OrgBulletedList")
1868 ;; If top-level list, re-start numbering. Otherwise,
1869 ;; continue numbering.
1870 (format "text:continue-numbering=\"%s\""
1871 (let* ((parent (org-export-get-parent-headline
1874 (org-export-low-level-p parent info
))
1876 (let ((headline-has-table-p
1877 (let ((section (assq 'section
(org-element-contents headline
))))
1878 (assq 'table
(and section
(org-element-contents section
))))))
1879 (format "\n<text:list-item>\n%s\n%s"
1881 (format "\n<text:p text:style-name=\"%s\">%s</text:p>"
1883 (concat extra-targets anchored-title
))
1885 (if headline-has-table-p
1886 "</text:list-header>"
1887 "</text:list-item>")))
1888 (and (org-export-last-sibling-p headline info
)
1890 ;; Case 3. Standard headline. Export it as a section.
1894 "\n<text:h text:style-name=\"%s\" text:outline-level=\"%s\">%s</text:h>"
1895 (format "Heading_20_%s" level
)
1897 (concat extra-targets anchored-title
))
1901 ;;;; Horizontal Rule
1903 (defun org-e-odt-horizontal-rule (horizontal-rule contents info
)
1904 "Transcode an HORIZONTAL-RULE object from Org to ODT.
1905 CONTENTS is nil. INFO is a plist holding contextual information."
1906 (org-e-odt--wrap-label
1908 (format "\n<text:p text:style-name=\"%s\">%s</text:p>"
1909 "Horizontal_20_Line" "")))
1912 ;;;; Inline Babel Call
1914 ;; Inline Babel Calls are ignored.
1917 ;;;; Inline Src Block
1919 (defun org-e-odt--find-verb-separator (s)
1920 "Return a character not used in string S.
1921 This is used to choose a separator for constructs like \\verb."
1922 (let ((ll "~,./?;':\"|!@#%^&-_=+abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ<>()[]{}"))
1923 (loop for c across ll
1924 when
(not (string-match (regexp-quote (char-to-string c
)) s
))
1925 return
(char-to-string c
))))
1927 (defun org-e-odt-inline-src-block (inline-src-block contents info
)
1928 "Transcode an INLINE-SRC-BLOCK element from Org to ODT.
1929 CONTENTS holds the contents of the item. INFO is a plist holding
1930 contextual information."
1931 (let* ((org-lang (org-element-property :language inline-src-block
))
1932 (code (org-element-property :value inline-src-block
))
1933 (separator (org-e-odt--find-verb-separator code
)))
1939 (defun org-e-odt-inlinetask (inlinetask contents info
)
1940 "Transcode an INLINETASK element from Org to ODT.
1941 CONTENTS holds the contents of the block. INFO is a plist
1942 holding contextual information."
1944 ;; If `org-e-odt-format-inlinetask-function' is provided, call it
1945 ;; with appropriate arguments.
1946 ((functionp org-e-odt-format-inlinetask-function
)
1947 (let ((format-function
1949 (lambda (todo todo-type priority text tags
1950 &key contents
&allow-other-keys
)
1951 (funcall org-e-odt-format-inlinetask-function
1952 todo todo-type priority text tags contents
)))))
1953 (org-e-odt-format-headline--wrap
1954 inlinetask info format-function
:contents contents
)))
1955 ;; Otherwise, use a default template.
1956 (t (org-e-odt--wrap-label
1958 (format "\n<text:p text:style-name=\"%s\">%s</text:p>"
1962 (format "\n<text:p text:style-name=\"%s\">%s</text:p>"
1963 "OrgInlineTaskHeading"
1964 (org-e-odt-format-headline--wrap
1967 nil nil
"OrgInlineTaskFrame" " style:rel-width=\"100%\""))))))
1971 (defun org-e-odt-italic (italic contents info
)
1972 "Transcode ITALIC from Org to ODT.
1973 CONTENTS is the text with italic markup. INFO is a plist holding
1974 contextual information."
1975 (format "<text:span text:style-name=\"%s\">%s</text:span>"
1976 "Emphasis" contents
))
1981 (defun org-e-odt-item (item contents info
)
1982 "Transcode an ITEM element from Org to ODT.
1983 CONTENTS holds the contents of the item. INFO is a plist holding
1984 contextual information."
1985 (let* ((plain-list (org-export-get-parent item
))
1986 (type (org-element-property :type plain-list
))
1987 (counter (org-element-property :counter item
))
1988 (tag (let ((tag (org-element-property :tag item
)))
1990 (concat (org-e-odt--checkbox item
)
1991 (org-export-data tag info
))))))
1993 ((ordered unordered descriptive-1 descriptive-2
)
1994 (format "\n<text:list-item>\n%s\n%s"
1996 (let* ((--element-has-a-table-p
1998 (lambda (element info
)
1999 (loop for el in
(org-element-contents element
)
2000 thereis
(eq (org-element-type el
) 'table
))))))
2002 ((funcall --element-has-a-table-p item info
)
2003 "</text:list-header>")
2004 (t "</text:list-item>")))))
2005 (t (error "Unknown list type: %S" type
)))))
2009 (defun org-e-odt-keyword (keyword contents info
)
2010 "Transcode a KEYWORD element from Org to ODT.
2011 CONTENTS is nil. INFO is a plist holding contextual information."
2012 (let ((key (org-element-property :key keyword
))
2013 (value (org-element-property :value keyword
)))
2015 ((string= key
"ODT") value
)
2016 ((string= key
"INDEX") (format "\\index{%s}" value
))
2017 ((string= key
"TARGET") nil
; FIXME
2018 ;; (format "\\label{%s}" (org-export-solidify-link-text value))
2020 ((string= key
"toc")
2021 (let ((value (downcase value
)))
2023 ((string-match "\\<headlines\\>" value
)
2024 (let ((depth (or (and (string-match "[0-9]+" value
)
2025 (string-to-number (match-string 0 value
)))
2026 (plist-get info
:with-toc
))))
2027 (when (wholenump depth
) (org-e-odt-toc depth info
))))
2028 ((string= "tables" value
) "FIXME")
2029 ((string= "figures" value
) "FIXME")
2030 ((string= "listings" value
)
2032 ;; At the moment, src blocks with a caption are wrapped
2033 ;; into a figure environment.
2037 ;;;; Latex Environment
2040 (eval-after-load 'org-odt
2041 '(ad-deactivate 'org-format-latex-as-mathml
))
2043 ;; (defadvice org-format-latex-as-mathml ; FIXME
2044 ;; (after org-e-odt-protect-latex-fragment activate)
2045 ;; "Encode LaTeX fragment as XML.
2046 ;; Do this when translation to MathML fails."
2047 ;; (when (or (not (> (length ad-return-value) 0))
2048 ;; (get-text-property 0 'org-protected ad-return-value))
2049 ;; (setq ad-return-value
2050 ;; (org-propertize (org-e-odt-encode-plain-text (ad-get-arg 0))
2051 ;; 'org-protected t))))
2053 (defun org-e-odt-format-latex (latex-frag processing-type info
)
2054 (let* ((prefix (case processing-type
2056 (mathml "ltxmathml/")))
2057 (input-file (plist-get info
:input-file
))
2059 (concat prefix
(file-name-sans-extension
2060 (file-name-nondirectory input-file
))))
2061 (cache-dir (file-name-directory input-file
))
2062 (display-msg (case processing-type
2063 (dvipng "Creating LaTeX Image...")
2064 (mathml "Creating MathML snippet..."))))
2067 (org-format-latex cache-subdir cache-dir nil display-msg
2068 nil nil processing-type
)
2071 (defun org-e-odt-latex-environment (latex-environment contents info
)
2072 "Transcode a LATEX-ENVIRONMENT element from Org to ODT.
2073 CONTENTS is nil. INFO is a plist holding contextual information."
2074 (org-e-odt--wrap-label
2077 (org-remove-indentation
2078 (org-element-property :value latex-environment
)))
2079 (processing-type (plist-get info
:LaTeX-fragments
))
2080 (caption (org-element-property :caption latex-environment
))
2081 (short-caption (and (cdr caption
)
2082 (org-export-data (cdr caption
) info
)))
2083 (caption (and (car caption
) (org-export-data (car caption
) info
)))
2084 (label (org-element-property :name latex-environment
))
2086 (label (org-element-property :name latex-environment
)))
2088 (when (memq processing-type
'(t mathjax
))
2089 (unless (and (fboundp 'org-format-latex-mathml-available-p
)
2090 (org-format-latex-mathml-available-p))
2091 (message "LaTeX to MathML converter not available. Trying dvinpng...")
2092 (setq processing-type
'dvipng
)))
2094 (when (eq processing-type
'dvipng
)
2095 (unless (and (org-check-external-command "latex" "" t
)
2096 (org-check-external-command "dvipng" "" t
))
2097 (message "LaTeX to PNG converter not available. Using verbatim.")
2098 (setq processing-type
'verbatim
)))
2100 (case processing-type
2102 (org-e-odt-format-formula latex-environment info
))
2104 (format "\n<text:p text:style-name=\"%s\">%s</text:p>"
2106 (org-e-odt-link--inline-image latex-environment info
)))
2107 (t (org-e-odt-do-format-code latex-frag
))))))
2113 ;; (when latex-frag ; FIXME
2114 ;; (setq href (org-propertize href :title "LaTeX Fragment"
2115 ;; :description latex-frag)))
2117 ;; provide descriptions
2119 (defun org-e-odt-latex-fragment (latex-fragment contents info
)
2120 "Transcode a LATEX-FRAGMENT object from Org to ODT.
2121 CONTENTS is nil. INFO is a plist holding contextual information."
2122 (let* ((latex-frag (org-element-property :value latex-fragment
))
2123 (processing-type (plist-get info
:LaTeX-fragments
)))
2125 ((member processing-type
'(t mathjax
))
2126 (org-e-odt-format-formula latex-fragment info
))
2127 ((eq processing-type
'dvipng
)
2128 (org-e-odt-link--inline-image latex-fragment info
))
2129 (t (org-e-odt-encode-plain-text latex-frag t
)))))
2134 (defun org-e-odt-line-break (line-break contents info
)
2135 "Transcode a LINE-BREAK object from Org to ODT.
2136 CONTENTS is nil. INFO is a plist holding contextual information."
2137 "<text:line-break/>\n")
2144 ;;;; Links :: Generic
2146 ;; (org-lparse-link-description-is-image
2147 ;; (format "\n<draw:a xlink:type=\"simple\" xlink:href=\"%s\">\n%s\n</draw:a>"
2150 ;;;; Links :: Label references
2152 (defun org-e-odt-enumerate-element (element info
&optional predicate n
)
2153 (let* ((--numbered-parent-headline-at-<=-n
2155 (lambda (element n info
)
2156 (loop for x in
(org-export-get-genealogy element
)
2157 thereis
(and (eq (org-element-type x
) 'headline
)
2158 (<= (org-export-get-relative-level x info
) n
)
2159 (org-export-numbered-headline-p x info
)
2163 (lambda (element scope info
&optional predicate
)
2166 (or scope
(plist-get info
:parse-tree
))
2167 (org-element-type element
)
2169 (and (or (not predicate
) (funcall predicate el info
))
2173 info
'first-match
)))))
2174 (scope (funcall --numbered-parent-headline-at-
<=-n
2175 element
(or n org-e-odt-display-outline-level
) info
))
2176 (ordinal (funcall --enumerate element scope info predicate
))
2181 (mapconcat 'number-to-string
2182 (org-export-get-headline-number scope info
) "."))
2186 (number-to-string ordinal
))))
2189 (defun org-e-odt-format-label (element info op
)
2190 (let* ((caption-from
2191 (case (org-element-type element
)
2192 (link (org-export-get-parent-element element
))
2194 ;; get label and caption.
2195 (label (org-element-property :name caption-from
))
2196 (caption (org-element-property :caption caption-from
))
2197 (short-caption (cdr caption
))
2198 ;; transcode captions.
2199 (caption (and (car caption
) (org-export-data (car caption
) info
)))
2200 (short-caption (and short-caption
2201 (org-export-data short-caption info
))))
2202 (when (or label caption
)
2203 (let* ((default-category
2205 ((eq (org-element-type element
) 'table
)
2207 ((org-e-odt-standalone-image-p element info
)
2209 ((member (org-element-type element
)
2210 '(latex-environment latex-fragment
))
2211 (let ((processing-type (plist-get info
:LaTeX-fragments
)))
2213 ((eq processing-type
'dvipng
) "__DvipngImage__")
2214 ((eq processing-type
'mathjax
) "__MathFormula__")
2215 ((eq processing-type
't
) "__MathFormula__")
2216 (t (error "Handle LaTeX:verbatim")))))
2217 ((eq (org-element-type element
) 'src-block
)
2219 (t (error "Handle enumeration of %S" element
))))
2222 ((member (org-element-type element
)
2223 '(table latex-environment src-block
))
2225 ((org-e-odt-standalone-image-p element info
)
2226 'org-e-odt-standalone-image-p
)
2227 (t (error "Handle enumeration of %S" element
))))
2228 (seqno (org-e-odt-enumerate-element
2229 element info predicate
)) ; FIXME
2230 ;; handle label props.
2231 (label-props (assoc default-category org-e-odt-category-map-alist
))
2232 ;; identify opendocument counter
2233 (counter (nth 1 label-props
))
2234 ;; identify label style
2235 (label-style (nth 2 label-props
))
2236 ;; retrieve localized category sting
2237 (category (org-export-translate (nth 3 label-props
) :utf-8 info
)))
2240 ;; assign an internal label, if user has not provided one
2241 (setq label
(or label
(format "%s-%s" default-category seqno
)))
2242 (setq label
(org-export-solidify-link-text label
))
2246 (cadr (assoc-string label-style org-e-odt-label-styles t
))
2249 "<text:sequence text:ref-name=\"%s\" text:name=\"%s\" text:formula=\"ooow:%s+1\" style:num-format=\"1\">%s</text:sequence>"
2250 label counter counter seqno
))
2251 (?c .
,(or caption
""))))
2255 (setq label
(org-export-solidify-link-text label
))
2256 (let* ((fmt (cddr (assoc-string label-style org-e-odt-label-styles t
)))
2259 (format "<text:sequence-ref text:reference-format=\"%s\" text:ref-name=\"%s\">%s</text:sequence-ref>"
2260 fmt1 label
(format-spec fmt2
`((?e .
,category
)
2262 (t (error "Unknow %S on label" op
)))))))
2264 ;;;; Links :: Math formula
2266 (defun org-e-odt-format-formula (element info
)
2268 ((eq (org-element-type element
) 'link
) ; FIXME
2269 (let* ((type (org-element-property :type element
))
2270 (raw-path (org-element-property :path element
)))
2272 ((file-name-absolute-p raw-path
)
2273 (expand-file-name raw-path
))
2275 ((member (org-element-type element
)
2276 '(latex-fragment latex-environment
))
2277 (let* ((latex-frag (org-remove-indentation
2278 (org-element-property :value element
)))
2279 (formula-link (org-e-odt-format-latex
2280 latex-frag
'mathml info
)))
2282 (string-match "file:\\([^]]*\\)" formula-link
)
2283 (match-string 1 formula-link
))))
2284 (t (error "what is this?"))))
2285 (full-src (if (file-name-absolute-p src
) src
2286 (expand-file-name src
(file-name-directory
2287 (plist-get info
:input-file
)))))
2289 (case (org-element-type element
)
2290 (link (org-export-get-parent-element element
))
2292 (captions (org-e-odt-format-label caption-from info
'definition
))
2293 (caption (car captions
))
2295 (format "\n<draw:object %s xlink:href=\"%s\" xlink:type=\"simple\"/>"
2296 " xlink:show=\"embed\" xlink:actuate=\"onLoad\""
2297 (file-name-directory (org-e-odt-copy-formula-file full-src
))))
2298 (embed-as (if caption
'paragraph
'character
))
2301 ((eq embed-as
'character
)
2302 (org-e-odt-format-entity "InlineFormula" href width height
))
2304 (let* ((equation (org-e-odt-format-entity
2305 "CaptionedDisplayFormula" href width height captions
))
2307 (let* ((org-e-odt-category-map-alist
2308 '(("__Table__" "Table" "value")
2309 ("__Figure__" "Illustration" "value")
2310 ("__MathFormula__" "Text" "math-label")
2311 ("__DvipngImage__" "Equation" "value")
2312 ("__Listing__" "Listing" "value"))))
2313 (car (org-e-odt-format-label caption-from info
'definition
))))
2315 (org-element-adopt-elements
2316 (list 'table
'(:type org
:attr_odt
(":style \"OrgEquation\"")))
2317 (org-element-adopt-elements
2318 (list 'table-row
'(:type standard
))
2319 (list 'table-cell nil
"<c8>") (list 'table-cell nil
"<c1>"))
2320 (org-element-adopt-elements
2321 (list 'table-row
'(:type standard
))
2322 (org-element-adopt-elements
2323 (list 'table-cell nil
)
2324 (list 'export-block
(list :type
"ODT" :value equation
)))
2325 (org-element-adopt-elements
2326 (list 'table-cell nil
)
2327 (list 'export-block
(list :type
"ODT" :value label
))))))
2329 (org-export-collect-tree-properties
2330 formula-tree
(org-export-get-environment 'e-odt
))))
2331 (org-export-data formula-tree formula-info
))))))
2333 (defun org-e-odt-copy-formula-file (src-file)
2334 "Returns the internal name of the file"
2335 (let* ((target-dir (format "Formula-%04d/"
2336 (incf org-e-odt-embedded-formulas-count
)))
2337 (target-file (concat target-dir
"content.xml")))
2338 ;; Create a directory for holding formula file. Also enter it in
2340 (make-directory (concat org-e-odt-zip-dir target-dir
))
2341 (org-e-odt-create-manifest-file-entry
2342 "application/vnd.oasis.opendocument.formula" target-dir
"1.2")
2343 ;; Copy over the formula file from user directory to zip
2345 (message "Embedding %s as %s ..." src-file target-file
)
2346 (let ((case-fold-search nil
))
2349 ((string-match "\\.\\(mathml\\|mml\\)\\'" src-file
)
2350 (copy-file src-file
(concat org-e-odt-zip-dir target-file
) 'overwrite
))
2351 ;; Case 2: OpenDocument formula.
2352 ((string-match "\\.odf\\'" src-file
)
2353 (org-e-odt--zip-extract src-file
"content.xml"
2354 (concat org-e-odt-zip-dir target-dir
)))
2355 (t (error "%s is not a formula file" src-file
))))
2356 ;; Enter the formula file in to manifest.
2357 (org-e-odt-create-manifest-file-entry "text/xml" target-file
)
2362 (defun org-e-odt-format-entity (entity href width height
&optional
2363 captions user-frame-params
)
2364 (let* ((caption (car captions
)) (short-caption (cdr captions
))
2365 (entity-style (assoc-string entity org-e-odt-entity-frame-styles t
))
2366 default-frame-params frame-params
2367 (--merge-frame-params
2369 (lambda (default-frame-params user-frame-params
)
2370 (if (not user-frame-params
) default-frame-params
2371 (assert (= (length default-frame-params
) 3))
2372 (assert (= (length user-frame-params
) 3))
2373 (loop for user-frame-param in user-frame-params
2374 for default-frame-param in default-frame-params
2375 collect
(or user-frame-param default-frame-param
)))))))
2378 (setq default-frame-params
(nth 2 entity-style
))
2379 (setq frame-params
(funcall --merge-frame-params
2380 default-frame-params user-frame-params
))
2381 (apply 'org-e-odt--frame href width height frame-params
))
2383 (setq default-frame-params
(nth 3 entity-style
))
2384 (setq frame-params
(funcall --merge-frame-params
2385 default-frame-params user-frame-params
))
2386 (apply 'org-e-odt--textbox
2387 (format "\n<text:p text:style-name=\"%s\">%s</text:p>"
2390 (apply 'org-e-odt--frame href width height
2391 (let ((entity-style-1 (copy-sequence
2392 (nth 2 entity-style
))))
2393 (setcar (cdr entity-style-1
)
2395 (cadr entity-style-1
)
2397 (format " draw:name=\"%s\" "
2401 width height frame-params
)))))
2403 (defun org-e-odt-standalone-image-p (element info
)
2404 "Test if ELEMENT is a standalone image for the purpose ODT export.
2405 INFO is a plist holding contextual information.
2407 Return non-nil, if ELEMENT is of type paragraph and it's sole
2408 content, save for whitespaces, is a link that qualifies as an
2411 Return non-nil, if ELEMENT is of type link and it's containing
2412 paragraph has no other content save for leading and trailing
2415 Return nil, otherwise.
2417 Bind `org-e-odt-standalone-image-predicate' to constrain
2418 paragraph further. For example, to check for only captioned
2419 standalone images, do the following.
2421 \(setq org-e-odt-standalone-image-predicate
2422 \(lambda \(paragraph\)
2423 \(org-element-property :caption paragraph\)\)\)
2425 (let ((--standalone-image-predicate
2426 (function (lambda (paragraph)
2427 (or (org-element-property :caption paragraph
)
2428 (org-element-property :name paragraph
)))))
2429 (paragraph (case (org-element-type element
)
2431 (link (and (org-export-inline-image-p
2432 element org-e-odt-inline-image-rules
)
2433 (org-export-get-parent element
)))
2436 (assert (eq (org-element-type paragraph
) 'paragraph
))
2437 (when (funcall --standalone-image-predicate paragraph
)
2438 (let ((contents (org-element-contents paragraph
)))
2439 (loop for x in contents
2440 with inline-image-count
= 0
2442 ((eq (org-element-type x
) 'plain-text
)
2443 (not (org-string-nw-p x
)))
2444 ((eq (org-element-type x
) 'link
)
2445 (when (org-export-inline-image-p
2446 x org-e-odt-inline-image-rules
)
2447 (= (incf inline-image-count
) 1)))
2451 (defun org-e-odt-get-previous-elements (blob info
)
2452 (let ((parent (org-export-get-parent blob
)))
2453 (cdr (memq blob
(reverse (org-element-contents parent
))))))
2455 (defun org-e-odt-resolve-numbered-paragraph (element info
)
2456 (when (eq (org-element-type element
) 'item
)
2457 (let ((el element
) ordinal
)
2458 (while (eq (org-element-type el
) 'item
)
2459 (push (1+ (length (org-e-odt-get-previous-elements el info
))) ordinal
)
2460 (setq el
(org-export-get-parent (org-export-get-parent el
))))
2464 (defun org-e-odt-link (link desc info
)
2465 "Transcode a LINK object from Org to ODT.
2467 DESC is the description part of the link, or the empty string.
2468 INFO is a plist holding contextual information. See
2470 (let* ((type (org-element-property :type link
))
2471 (raw-path (org-element-property :path link
))
2472 ;; Ensure DESC really exists, or set it to nil.
2473 (desc (and (not (string= desc
"")) desc
))
2474 (imagep (org-export-inline-image-p
2475 link org-e-odt-inline-image-rules
))
2477 ((member type
'("http" "https" "ftp" "mailto"))
2478 (concat type
":" raw-path
))
2479 ((string= type
"file")
2480 (if (file-name-absolute-p raw-path
)
2481 (concat "file://" (expand-file-name raw-path
))
2482 (concat "file://" raw-path
)))
2487 ((and (not desc
) (org-export-inline-image-p
2488 link org-e-odt-inline-image-rules
))
2489 (org-e-odt-link--inline-image link info
))
2490 ;; Radio target: Transcode target's contents and use them as
2491 ;; link's description.
2492 ((string= type
"radio")
2493 (let ((destination (org-export-resolve-radio-link link info
)))
2495 (let ((desc (org-export-data (org-element-contents destination
) info
))
2496 (href (org-export-solidify-link-text path
)))
2498 "<text:bookmark-ref text:reference-format=\"text\" text:ref-name=\"OrgXref.%s\">%s</text:bookmark-ref>"
2500 ;; Links pointing to an headline: Find destination and build
2501 ;; appropriate referencing command.
2502 ((member type
'("custom-id" "fuzzy" "id"))
2503 (let ((destination (if (string= type
"fuzzy")
2504 (org-export-resolve-fuzzy-link link info
)
2505 (org-export-resolve-id-link link info
))))
2506 (case (org-element-type destination
)
2507 ;; Fuzzy link points nowhere.
2509 (format "<text:span text:style-name=\"%s\">%s</text:span>"
2510 "Emphasis" (or desc
(org-export-data
2511 (org-element-property
2512 :raw-link link
) info
))))
2513 ;; Fuzzy link points to an invisible target.
2515 ;; LINK points to an headline. Check if LINK should display
2518 (let* ((headline-no (org-export-get-headline-number destination info
))
2519 (label (format "sec-%s" (mapconcat 'number-to-string
2522 ;; Case 1: Headline is numbered and LINK has no
2523 ;; description or LINK's description matches headline's
2524 ;; title. Display section number.
2525 ((and (org-export-numbered-headline-p destination info
)
2526 (or (not desc
) (string= desc
(org-element-property
2527 :raw-value destination
))))
2529 "<text:bookmark-ref text:reference-format=\"chapter\" text:ref-name=\"OrgXref.%s\">%s</text:bookmark-ref>"
2530 label
(mapconcat 'number-to-string headline-no
".")))
2531 ;; Case 2: Either the headline is un-numbered or
2532 ;; LINK has a custom description. Display LINK's
2533 ;; description or headline's title.
2535 (let ((desc (or desc
(org-export-data
2536 (org-element-property :title destination
)
2539 "<text:bookmark-ref text:reference-format=\"text\" text:ref-name=\"OrgXref.%s\">%s</text:bookmark-ref>"
2541 ;; Fuzzy link points to a target. Do as above.
2543 ;; Identify nearest meaningful container
2545 (loop for parent in
(org-export-get-genealogy destination
)
2548 (org-element-type parent
)
2549 '(footnote-definition footnote-reference headline item
2552 ;; There is a meaningful container
2554 (case (org-element-type container
)
2555 ;; Container is item
2558 "<text:bookmark-ref text:reference-format=\"number-all-superior\" text:ref-name=\"OrgXref.%s\">%s</text:bookmark-ref>"
2559 (org-solidify-link-text path
)
2561 (mapconcat 'number-to-string
2562 (org-e-odt-resolve-numbered-paragraph
2563 container info
) ".")))))))
2566 ;; (setq number (cond
2567 ;; ((org-e-odt-standalone-image-p destination info)
2568 ;; (org-export-get-ordinal
2569 ;; (assoc 'link (org-element-contents destination))
2570 ;; info 'link 'org-e-odt-standalone-image-p))
2571 ;; (t (org-export-get-ordinal destination info))))
2572 ;; (setq desc (when number
2573 ;; (if (atom number) (number-to-string number)
2574 ;; (mapconcat 'number-to-string number ".")))))
2576 (let ((label-reference
2577 (org-e-odt-format-label destination info
'reference
)))
2578 (assert label-reference
)
2579 label-reference
)))))
2580 ;; Coderef: replace link with the reference name or the
2581 ;; equivalent line number.
2582 ((string= type
"coderef")
2583 (let* ((line-no (format "%d" (org-export-resolve-coderef path info
)))
2584 (href (concat "coderef-" path
)))
2586 (org-export-get-coderef-format path desc
)
2588 "<text:bookmark-ref text:reference-format=\"number\" text:ref-name=\"OrgXref.%s\">%s</text:bookmark-ref>"
2590 ;; Link type is handled by a special function.
2591 ((functionp (setq protocol
(nth 2 (assoc type org-link-protocols
))))
2592 (funcall protocol
(org-link-unescape path
) desc
'odt
))
2593 ;; External link with a description part.
2595 (format "<text:a xlink:type=\"simple\" xlink:href=\"%s\">%s</text:a>"
2597 ;; External link without a description part.
2599 (format "<text:a xlink:type=\"simple\" xlink:href=\"%s\">%s</text:a>"
2601 ;; No path, only description. Try to do something useful.
2602 (t (format "<text:span text:style-name=\"%s\">%s</text:span>"
2603 "Emphasis" desc
)))))
2608 (defun org-e-odt-paragraph (paragraph contents info
)
2609 "Transcode a PARAGRAPH element from Org to ODT.
2610 CONTENTS is the contents of the paragraph, as a string. INFO is
2611 the plist used as a communication channel."
2612 (let* ((parent (org-export-get-parent paragraph
))
2613 (parent-type (org-element-type parent
))
2614 (style (case parent-type
2615 (quote-block "Quotations")
2616 (center-block "OrgCenter")
2617 (footnote-definition "Footnote")
2618 (t (or (org-element-property :style paragraph
)
2620 ;; If this paragraph is a leading paragraph in an item and the
2621 ;; item has a checkbox, splice the checkbox and paragraph contents
2623 (when (and (eq (org-element-type parent
) 'item
)
2624 (eq paragraph
(car (org-element-contents parent
))))
2625 (setq contents
(concat (org-e-odt--checkbox parent
) contents
)))
2627 (format "\n<text:p text:style-name=\"%s\">%s</text:p>" style contents
)))
2632 (defun org-e-odt-plain-list (plain-list contents info
)
2633 "Transcode a PLAIN-LIST element from Org to ODT.
2634 CONTENTS is the contents of the list. INFO is a plist holding
2635 contextual information."
2636 (org-e-odt--wrap-label
2638 (format "\n<text:list text:style-name=\"%s\" %s>\n%s</text:list>"
2639 ;; Choose style based on list type.
2640 (case (org-element-property :type plain-list
)
2641 (ordered "OrgNumberedList")
2642 (unordered "OrgBulletedList")
2643 (descriptive-1 "OrgDescriptionList")
2644 (descriptive-2 "OrgDescriptionList"))
2645 ;; If top-level list, re-start numbering. Otherwise,
2646 ;; continue numbering.
2647 (format "text:continue-numbering=\"%s\""
2648 (let* ((parent (org-export-get-parent plain-list
)))
2649 (if (and parent
(eq (org-element-type parent
) 'item
))
2655 (defun org-e-odt-fill-tabs-and-spaces (line)
2656 (replace-regexp-in-string
2657 "\\([\t]\\|\\([ ]+\\)\\)"
2660 ((string= s
"\t") "<text:tab/>")
2661 (t (let ((n (length s
)))
2664 ((> n
1) (concat " " (format "<text:s text:c=\"%d\"/>" (1- n
))))
2668 (defun org-e-odt-encode-plain-text (text &optional no-whitespace-filling
)
2671 (setq text
(replace-regexp-in-string (car pair
) (cdr pair
) text t t
)))
2672 '(("&" .
"&") ("<" .
"<") (">" .
">")))
2673 (if no-whitespace-filling text
2674 (org-e-odt-fill-tabs-and-spaces text
)))
2676 (defun org-e-odt--quotation-marks (text info
)
2677 "Export quotation marks depending on language conventions.
2678 TEXT is a string containing quotation marks to be replaced. INFO
2679 is a plist used as a communication channel."
2682 (while (setq start
(string-match (car l
) text start
))
2683 (let ((new-quote (concat (match-string 1 text
) (cdr l
))))
2684 (setq text
(replace-match new-quote t t text
))))))
2685 (cdr (or (assoc (plist-get info
:language
) org-e-odt-quotes
)
2686 ;; Falls back on English.
2687 (assoc "en" org-e-odt-quotes
))))
2690 (defun org-e-odt-plain-text (text info
)
2691 "Transcode a TEXT string from Org to ODT.
2692 TEXT is the string to transcode. INFO is a plist holding
2693 contextual information."
2694 ;; Protect &, < and >.
2695 (setq text
(org-e-odt-encode-plain-text text t
))
2696 ;; Handle quotation marks
2697 (setq text
(org-e-odt--quotation-marks text info
))
2698 ;; Convert special strings.
2699 (when (plist-get info
:with-special-strings
)
2702 (setq text
(replace-regexp-in-string (car pair
) (cdr pair
) text t nil
)))
2703 org-e-odt-special-string-regexps
))
2704 ;; Handle break preservation if required.
2705 (when (plist-get info
:preserve-breaks
)
2706 (setq text
(replace-regexp-in-string
2707 "\\(\\\\\\\\\\)?[ \t]*\n" "<text:line-break/>\n" text t
)))
2714 (defun org-e-odt-planning (planning contents info
)
2715 "Transcode a PLANNING element from Org to ODT.
2716 CONTENTS is nil. INFO is a plist used as a communication
2718 (format "<text:span text:style-name=\"%s\">%s</text:span>"
2719 "OrgTimestampWrapper"
2721 (let ((closed (org-element-property :closed planning
)))
2724 (format "<text:span text:style-name=\"%s\">%s</text:span>"
2725 "OrgTimestampKeyword" org-closed-string
)
2726 (format "<text:span text:style-name=\"%s\">%s</text:span>"
2727 "OrgTimestamp" (org-translate-time closed
)))))
2728 (let ((deadline (org-element-property :deadline planning
)))
2731 (format "<text:span text:style-name=\"%s\">%s</text:span>"
2732 "OrgTimestampKeyword" org-deadline-string
)
2733 (format "<text:span text:style-name=\"%s\">%s</text:span>"
2734 "OrgTimestamp" (org-translate-time deadline
)))))
2735 (let ((scheduled (org-element-property :scheduled planning
)))
2738 (format "<text:span text:style-name=\"%s\">%s</text:span>"
2739 "OrgTimestampKeyword" org-scheduled-string
)
2740 (format "<text:span text:style-name=\"%s\">%s</text:span>"
2741 "OrgTimestamp" (org-translate-time scheduled
))))))))
2744 ;;;; Property Drawer
2746 (defun org-e-odt-property-drawer (property-drawer contents info
)
2747 "Transcode a PROPERTY-DRAWER element from Org to ODT.
2748 CONTENTS is nil. INFO is a plist holding contextual
2750 ;; The property drawer isn't exported but we want separating blank
2751 ;; lines nonetheless.
2757 (defun org-e-odt-quote-block (quote-block contents info
)
2758 "Transcode a QUOTE-BLOCK element from Org to ODT.
2759 CONTENTS holds the contents of the block. INFO is a plist
2760 holding contextual information."
2761 (org-e-odt--wrap-label quote-block contents
))
2766 (defun org-e-odt-quote-section (quote-section contents info
)
2767 "Transcode a QUOTE-SECTION element from Org to ODT.
2768 CONTENTS is nil. INFO is a plist holding contextual information."
2769 (let ((value (org-remove-indentation
2770 (org-element-property :value quote-section
))))
2771 (when value
(org-e-odt-do-format-code value
))))
2776 (defun org-e-odt-format-section (text style
&optional name
)
2777 (let ((default-name (car (org-e-odt-add-automatic-style "Section"))))
2778 (format "\n<text:section text:style-name=\"%s\" %s>\n%s\n</text:section>"
2780 (format "text:name=\"%s\"" (or name default-name
))
2784 (defun org-e-odt-section (section contents info
) ; FIXME
2785 "Transcode a SECTION element from Org to ODT.
2786 CONTENTS holds the contents of the section. INFO is a plist
2787 holding contextual information."
2792 (defun org-e-odt-radio-target (radio-target text info
)
2793 "Transcode a RADIO-TARGET object from Org to ODT.
2794 TEXT is the text of the target. INFO is a plist holding
2795 contextual information."
2797 text
(org-export-solidify-link-text
2798 (org-element-property :value radio-target
))))
2803 (defun org-e-odt-special-block (special-block contents info
)
2804 "Transcode a SPECIAL-BLOCK element from Org to ODT.
2805 CONTENTS holds the contents of the block. INFO is a plist
2806 holding contextual information."
2807 (let ((type (downcase (org-element-property :type special-block
)))
2808 (attributes (org-export-read-attribute :attr_odt special-block
)))
2809 (org-e-odt--wrap-label
2813 ((string= type
"annotation")
2814 (let ((author (or (plist-get attributes
:author
)
2815 (let ((author (plist-get info
:author
)))
2816 (and author
(org-export-data author info
)))))
2817 (date (or (plist-get attributes
:date
)
2818 (plist-get info
:date
))))
2820 (format "\n<text:p text:style-name=\"%s\">%s</text:p>"
2822 (format "<office:annotation>\n%s\n</office:annotation>"
2825 (format "<dc:creator>%s</dc:creator>" author
))
2827 (format "<dc:date>%s</dc:date>"
2828 (org-e-odt--date date
)))
2831 ((string= type
"textbox")
2832 (let ((width (plist-get attributes
:width
))
2833 (height (plist-get attributes
:height
))
2834 (style (plist-get attributes
:style
))
2835 (extra (plist-get attributes
:extra
))
2836 (anchor (plist-get attributes
:anchor
)))
2837 (format "\n<text:p text:style-name=\"%s\">%s</text:p>"
2838 "Text_20_body" (org-e-odt--textbox contents width height
2839 style extra anchor
))))
2845 (defun org-e-odt-hfy-face-to-css (fn)
2846 "Create custom style for face FN.
2847 When FN is the default face, use it's foreground and background
2848 properties to create \"OrgSrcBlock\" paragraph style. Otherwise
2849 use it's color attribute to create a character style whose name
2850 is obtained from FN. Currently all attributes of FN other than
2853 The style name for a face FN is derived using the following
2854 operations on the face name in that order - de-dash, CamelCase
2855 and prefix with \"OrgSrc\". For example,
2856 `font-lock-function-name-face' is associated with
2857 \"OrgSrcFontLockFunctionNameFace\"."
2858 (let* ((css-list (hfy-face-to-style fn
))
2859 (style-name ((lambda (fn)
2862 'capitalize
(split-string
2863 (hfy-face-or-def-to-name fn
) "-")
2865 (color-val (cdr (assoc "color" css-list
)))
2866 (background-color-val (cdr (assoc "background" css-list
)))
2867 (style (and org-e-odt-create-custom-styles-for-srcblocks
2870 (format org-e-odt-src-block-paragraph-format
2871 background-color-val color-val
))
2875 <style:style style:name=\"%s\" style:family=\"text\">
2876 <style:text-properties fo:color=\"%s\"/>
2877 </style:style>" style-name color-val
))))))
2878 (cons style-name style
)))
2880 (defun org-e-odt-htmlfontify-string (line)
2881 (let* ((hfy-html-quote-regex "\\([<\"&> ]\\)")
2882 (hfy-html-quote-map '(("\"" """)
2887 (" " "<text:tab/>")))
2888 (hfy-face-to-css 'org-e-odt-hfy-face-to-css
)
2889 (hfy-optimisations-1 (copy-seq hfy-optimisations
))
2890 (hfy-optimisations (add-to-list 'hfy-optimisations-1
2892 (hfy-begin-span-handler
2893 (lambda (style text-block text-id text-begins-block-p
)
2894 (insert (format "<text:span text:style-name=\"%s\">" style
))))
2895 (hfy-end-span-handler (lambda nil
(insert "</text:span>"))))
2896 (with-no-warnings (htmlfontify-string line
))))
2898 (defun org-e-odt-do-format-code
2899 (code &optional lang refs retain-labels num-start
)
2900 (let* ((lang (or (assoc-default lang org-src-lang-modes
) lang
))
2901 (lang-mode (and lang
(intern (format "%s-mode" lang
))))
2902 (code-lines (org-split-string code
"\n"))
2903 (code-length (length code-lines
))
2904 (use-htmlfontify-p (and (functionp lang-mode
)
2905 org-e-odt-fontify-srcblocks
2906 (require 'htmlfontify nil t
)
2907 (fboundp 'htmlfontify-string
)))
2908 (code (if (not use-htmlfontify-p
) code
2912 (font-lock-fontify-buffer)
2914 (fontifier (if use-htmlfontify-p
'org-e-odt-htmlfontify-string
2915 'org-e-odt-encode-plain-text
))
2916 (par-style (if use-htmlfontify-p
"OrgSrcBlock"
2917 "OrgFixedWidthBlock"))
2919 (assert (= code-length
(length (org-split-string code
"\n"))))
2921 (org-export-format-code
2923 (lambda (loc line-num ref
)
2925 (concat par-style
(and (= (incf i
) code-length
) "LastLine")))
2927 (setq loc
(concat loc
(and ref retain-labels
(format " (%s)" ref
))))
2928 (setq loc
(funcall fontifier loc
))
2930 (setq loc
(org-e-odt--target loc
(concat "coderef-" ref
))))
2932 (setq loc
(format "\n<text:p text:style-name=\"%s\">%s</text:p>"
2934 (if (not line-num
) loc
2935 (format "\n<text:list-item>%s\n</text:list-item>" loc
)))
2938 ((not num-start
) code
)
2941 "\n<text:list text:style-name=\"OrgSrcBlockNumberedLine\"%s>%s</text:list>"
2942 " text:continue-numbering=\"false\"" code
))
2945 "\n<text:list text:style-name=\"OrgSrcBlockNumberedLine\"%s>%s</text:list>"
2946 " text:continue-numbering=\"true\"" code
)))))
2948 (defun org-e-odt-format-code (element info
)
2949 (let* ((lang (org-element-property :language element
))
2950 ;; Extract code and references.
2951 (code-info (org-export-unravel-code element
))
2952 (code (car code-info
))
2953 (refs (cdr code-info
))
2954 ;; Does the src block contain labels?
2955 (retain-labels (org-element-property :retain-labels element
))
2956 ;; Does it have line numbers?
2957 (num-start (case (org-element-property :number-lines element
)
2958 (continued (org-export-get-loc element info
))
2960 (org-e-odt-do-format-code code lang refs retain-labels num-start
)))
2962 (defun org-e-odt-src-block (src-block contents info
)
2963 "Transcode a SRC-BLOCK element from Org to ODT.
2964 CONTENTS holds the contents of the item. INFO is a plist holding
2965 contextual information."
2966 (let* ((lang (org-element-property :language src-block
))
2967 (caption (org-element-property :caption src-block
))
2968 (short-caption (and (cdr caption
)
2969 (org-export-data (cdr caption
) info
)))
2970 (caption (and (car caption
) (org-export-data (car caption
) info
)))
2971 (label (org-element-property :name src-block
))
2972 (attributes (org-export-read-attribute :attr_odt src-block
)))
2973 ;; FIXME: Handle caption
2974 ;; caption-str (when caption)
2975 ;; (main (org-export-data (car caption) info))
2976 ;; (secondary (org-export-data (cdr caption) info))
2977 ;; (caption-str (org-e-odt--caption/label-string caption label info))
2978 (let* ((captions (org-e-odt-format-label src-block info
'definition
))
2979 (caption (car captions
)) (short-caption (cdr captions
)))
2982 (format "\n<text:p text:style-name=\"%s\">%s</text:p>"
2984 (let ((--src-block (org-e-odt-format-code src-block info
)))
2985 (if (not (plist-get attributes
:textbox
)) --src-block
2986 (format "\n<text:p text:style-name=\"%s\">%s</text:p>"
2988 (org-e-odt--textbox --src-block nil nil nil
))))))))
2991 ;;;; Statistics Cookie
2993 (defun org-e-odt-statistics-cookie (statistics-cookie contents info
)
2994 "Transcode a STATISTICS-COOKIE object from Org to ODT.
2995 CONTENTS is nil. INFO is a plist holding contextual information."
2996 (let ((cookie-value (org-element-property :value statistics-cookie
)))
2997 (format "<text:span text:style-name=\"%s\">%s</text:span>"
2998 "OrgCode" cookie-value
)))
3003 (defun org-e-odt-strike-through (strike-through contents info
)
3004 "Transcode STRIKE-THROUGH from Org to ODT.
3005 CONTENTS is the text with strike-through markup. INFO is a plist
3006 holding contextual information."
3007 (format "<text:span text:style-name=\"%s\">%s</text:span>"
3008 "Strikethrough" contents
))
3013 (defun org-e-odt-subscript (subscript contents info
)
3014 "Transcode a SUBSCRIPT object from Org to ODT.
3015 CONTENTS is the contents of the object. INFO is a plist holding
3016 contextual information."
3017 (format "<text:span text:style-name=\"%s\">%s</text:span>"
3018 "OrgSubscript" contents
))
3023 (defun org-e-odt-superscript (superscript contents info
)
3024 "Transcode a SUPERSCRIPT object from Org to ODT.
3025 CONTENTS is the contents of the object. INFO is a plist holding
3026 contextual information."
3027 (format "<text:span text:style-name=\"%s\">%s</text:span>"
3028 "OrgSuperscript" contents
))
3033 (defun org-e-odt-table-style-spec (element info
)
3034 (let* ((table (org-export-get-parent-table element
))
3035 (table-attributes (org-export-read-attribute :attr_odt table
))
3036 (table-style (plist-get table-attributes
:style
)))
3037 (assoc table-style org-e-odt-table-styles
)))
3039 (defun org-e-odt-get-table-cell-styles (table-cell info
)
3040 "Retrieve styles applicable to a table cell.
3041 R and C are (zero-based) row and column numbers of the table
3042 cell. STYLE-SPEC is an entry in `org-e-odt-table-styles'
3043 applicable to the current table. It is `nil' if the table is not
3044 associated with any style attributes.
3046 Return a cons of (TABLE-CELL-STYLE-NAME . PARAGRAPH-STYLE-NAME).
3048 When STYLE-SPEC is nil, style the table cell the conventional way
3049 - choose cell borders based on row and column groupings and
3050 choose paragraph alignment based on `org-col-cookies' text
3052 `org-e-odt-get-paragraph-style-cookie-for-table-cell'.
3054 When STYLE-SPEC is non-nil, ignore the above cookie and return
3055 styles congruent with the ODF-1.2 specification."
3056 (let* ((table-cell-address (org-export-table-cell-address table-cell info
))
3057 (r (car table-cell-address
)) (c (cdr table-cell-address
))
3058 (style-spec (org-e-odt-table-style-spec table-cell info
))
3059 (table-dimensions (org-export-table-dimensions
3060 (org-export-get-parent-table table-cell
)
3063 ;; LibreOffice - particularly the Writer - honors neither table
3064 ;; templates nor custom table-cell styles. Inorder to retain
3065 ;; inter-operability with LibreOffice, only automatic styles are
3066 ;; used for styling of table-cells. The current implementation is
3067 ;; congruent with ODF-1.2 specification and hence is
3068 ;; future-compatible.
3070 ;; Additional Note: LibreOffice's AutoFormat facility for tables -
3071 ;; which recognizes as many as 16 different cell types - is much
3072 ;; richer. Unfortunately it is NOT amenable to easy configuration
3074 (let* ((template-name (nth 1 style-spec
))
3075 (cell-style-selectors (nth 2 style-spec
))
3078 ((and (cdr (assoc 'use-first-column-styles cell-style-selectors
))
3079 (= c
0)) "FirstColumn")
3080 ((and (cdr (assoc 'use-last-column-styles cell-style-selectors
))
3081 (= (1+ c
) (cdr table-dimensions
)))
3083 ((and (cdr (assoc 'use-first-row-styles cell-style-selectors
))
3084 (= r
0)) "FirstRow")
3085 ((and (cdr (assoc 'use-last-row-styles cell-style-selectors
))
3086 (= (1+ r
) (car table-dimensions
)))
3088 ((and (cdr (assoc 'use-banding-rows-styles cell-style-selectors
))
3089 (= (% r
2) 1)) "EvenRow")
3090 ((and (cdr (assoc 'use-banding-rows-styles cell-style-selectors
))
3091 (= (% r
2) 0)) "OddRow")
3092 ((and (cdr (assoc 'use-banding-columns-styles cell-style-selectors
))
3093 (= (% c
2) 1)) "EvenColumn")
3094 ((and (cdr (assoc 'use-banding-columns-styles cell-style-selectors
))
3095 (= (% c
2) 0)) "OddColumn")
3097 (concat template-name cell-type
)))))
3099 (defun org-e-odt-table-cell (table-cell contents info
)
3100 "Transcode a TABLE-CELL element from Org to ODT.
3101 CONTENTS is nil. INFO is a plist used as a communication
3103 (let* ((table-cell-address (org-export-table-cell-address table-cell info
))
3104 (r (car table-cell-address
))
3105 (c (cdr table-cell-address
))
3106 (horiz-span (or (org-export-table-cell-width table-cell info
) 0))
3107 (table-row (org-export-get-parent table-cell
))
3108 (custom-style-prefix (org-e-odt-get-table-cell-styles
3112 (and custom-style-prefix
3113 (format "%sTableParagraph" custom-style-prefix
))
3116 ((and (= 1 (org-export-table-row-group table-row info
))
3117 (org-export-table-has-header-p
3118 (org-export-get-parent-table table-row
) info
))
3120 ((let* ((table (org-export-get-parent-table table-cell
))
3121 (table-attrs (org-export-read-attribute :attr_odt table
))
3122 (table-header-columns (plist-get table-attrs
3124 (<= c
(cond ((wholenump table-header-columns
)
3125 (- table-header-columns
1))
3126 (table-header-columns 0)
3129 (t "OrgTableContents"))
3130 (capitalize (symbol-name (org-export-table-cell-alignment
3131 table-cell info
))))))
3134 (and custom-style-prefix
(format "%sTableCell"
3135 custom-style-prefix
))
3138 (when (or (org-export-table-row-starts-rowgroup-p table-row info
)
3140 (when (org-export-table-row-ends-rowgroup-p table-row info
) "B")
3141 (when (and (org-export-table-cell-starts-colgroup-p table-cell info
)
3142 (not (zerop c
)) ) "L"))))
3145 (format " table:style-name=\"%s\"" cell-style-name
)
3146 (and (> horiz-span
0)
3147 (format " table:number-columns-spanned=\"%d\""
3148 (1+ horiz-span
))))))
3149 (unless contents
(setq contents
""))
3151 (assert paragraph-style
)
3152 (format "\n<table:table-cell%s>\n%s\n</table:table-cell>"
3154 (let ((table-cell-contents (org-element-contents table-cell
)))
3155 (if (memq (org-element-type (car table-cell-contents
))
3156 org-element-all-elements
)
3158 (format "\n<text:p text:style-name=\"%s\">%s</text:p>"
3159 paragraph-style contents
))))
3161 (dotimes (i horiz-span s
)
3162 (setq s
(concat s
"\n<table:covered-table-cell/>"))))
3168 (defun org-e-odt-table-row (table-row contents info
)
3169 "Transcode a TABLE-ROW element from Org to ODT.
3170 CONTENTS is the contents of the row. INFO is a plist used as a
3171 communication channel."
3172 ;; Rules are ignored since table separators are deduced from
3173 ;; borders of the current row.
3174 (when (eq (org-element-property :type table-row
) 'standard
)
3175 (let* ((rowgroup-tags
3176 (if (and (= 1 (org-export-table-row-group table-row info
))
3177 (org-export-table-has-header-p
3178 (org-export-get-parent-table table-row
) info
))
3179 ;; If the row belongs to the first rowgroup and the
3180 ;; table has more than one row groups, then this row
3181 ;; belongs to the header row group.
3182 '("\n<table:table-header-rows>" .
"\n</table:table-header-rows>")
3183 ;; Otherwise, it belongs to non-header row group.
3184 '("\n<table:table-rows>" .
"\n</table:table-rows>"))))
3186 ;; Does this row begin a rowgroup?
3187 (when (org-export-table-row-starts-rowgroup-p table-row info
)
3188 (car rowgroup-tags
))
3190 (format "\n<table:table-row>\n%s\n</table:table-row>" contents
)
3191 ;; Does this row end a rowgroup?
3192 (when (org-export-table-row-ends-rowgroup-p table-row info
)
3193 (cdr rowgroup-tags
))))))
3198 (defun org-e-odt-table-first-row-data-cells (table info
)
3203 (unless (eq (org-element-property :type row
) 'rule
) row
))
3205 (special-column-p (org-export-table-has-special-column-p table
)))
3206 (if (not special-column-p
) (org-element-contents table-row
)
3207 (cdr (org-element-contents table-row
)))))
3209 (defun org-e-odt--table (table contents info
)
3210 "Transcode a TABLE element from Org to ODT.
3211 CONTENTS is the contents of the table. INFO is a plist holding
3212 contextual information."
3213 (case (org-element-property :type table
)
3214 ;; Case 1: table.el doesn't support export to OD format. Strip
3215 ;; such tables from export.
3220 "(org-e-odt): Found table.el-type table in the source Org file."
3221 " table.el doesn't support export to ODT format."
3222 " Stripping the table from export."))))
3223 ;; Case 2: Native Org tables.
3225 (let* ((captions (org-e-odt-format-label table info
'definition
))
3226 (caption (car captions
)) (short-caption (cdr captions
))
3227 (attributes (org-export-read-attribute :attr_odt table
))
3228 (custom-table-style (nth 1 (org-e-odt-table-style-spec table info
)))
3231 (lambda (table info
)
3232 (let* ((table-style (or custom-table-style
"OrgTable"))
3233 (column-style (format "%sColumn" table-style
)))
3235 (lambda (table-cell)
3236 (let ((width (1+ (or (org-export-table-cell-width
3237 table-cell info
) 0)))
3239 "\n<table:table-column table:style-name=\"%s\"/>"
3242 (dotimes (i width out
) (setq out
(concat s out
)))))
3243 (org-e-odt-table-first-row-data-cells table info
) "\n"))))))
3247 (format "\n<text:p text:style-name=\"%s\">%s</text:p>"
3250 (let* ((automatic-name
3251 (org-e-odt-add-automatic-style "Table" attributes
)))
3253 "\n<table:table table:name=\"%s\" table:style-name=\"%s\">"
3254 (or short-caption
(car automatic-name
))
3255 (or custom-table-style
(cdr automatic-name
) "OrgTable")))
3256 ;; column specification.
3257 (funcall table-column-specs table info
)
3261 "</table:table>")))))
3263 (defun org-e-odt-table (table contents info
)
3264 "Transcode a TABLE element from Org to ODT.
3265 CONTENTS is the contents of the table. INFO is a plist holding
3266 contextual information.
3268 Use `org-e-odt--table' to typeset the table. Handle details
3269 pertaining to indentation here."
3270 (let* ((--get-previous-elements
3273 (let ((parent (org-export-get-parent blob
)))
3274 (cdr (memq blob
(reverse (org-element-contents parent
))))))))
3275 (--element-preceded-by-table-p
3277 (lambda (element info
)
3278 (loop for el in
(funcall --get-previous-elements element info
)
3279 thereis
(eq (org-element-type el
) 'table
)))))
3280 (--walk-list-genealogy-and-collect-tags
3282 (lambda (table info
)
3283 (let* ((genealogy (org-export-get-genealogy table
))
3285 (when (eq (org-element-type (car genealogy
)) 'item
)
3286 (loop for el in genealogy
3287 when
(memq (org-element-type el
)
3292 (loop for el in genealogy
3293 when
(and (eq (org-element-type el
) 'headline
)
3294 (org-export-low-level-p el info
))
3298 (org-element-contents
3299 (org-export-get-parent el
)))))))
3302 ;; Handle list genealogy.
3303 (loop for el in list-genealogy collect
3304 (case (org-element-type el
)
3306 (setq parent-list el
)
3307 (cons "</text:list>"
3308 (format "\n<text:list text:style-name=\"%s\" %s>"
3309 (case (org-element-property :type el
)
3310 (ordered "OrgNumberedList")
3311 (unordered "OrgBulletedList")
3312 (descriptive-1 "OrgDescriptionList")
3313 (descriptive-2 "OrgDescriptionList"))
3314 "text:continue-numbering=\"true\"")))
3318 (if (funcall --element-preceded-by-table-p table info
)
3319 '("</text:list-header>" .
"<text:list-header>")
3320 '("</text:list-item>" .
"<text:list-header>")))
3321 ((funcall --element-preceded-by-table-p
3323 '("</text:list-header>" .
"<text:list-header>"))
3324 (t '("</text:list-item>" .
"<text:list-item>"))))))
3325 ;; Handle low-level headlines.
3326 (loop for el in llh-genealogy
3327 with step
= 'item collect
3330 (setq step
'item
) ; Flip-flop
3331 (setq parent-list el
)
3332 (cons "</text:list>"
3333 (format "\n<text:list text:style-name=\"%s\" %s>"
3334 (if (org-export-numbered-headline-p
3338 "text:continue-numbering=\"true\"")))
3340 (setq step
'plain-list
) ; Flip-flop
3343 (if (funcall --element-preceded-by-table-p table info
)
3344 '("</text:list-header>" .
"<text:list-header>")
3345 '("</text:list-item>" .
"<text:list-header>")))
3346 ((let ((section?
(org-export-get-previous-element
3349 (eq (org-element-type section?
) 'section
)
3350 (assq 'table
(org-element-contents section?
))))
3351 '("</text:list-header>" .
"<text:list-header>"))
3353 '("</text:list-item>" .
"<text:list-item>")))))))))))
3354 (close-open-tags (funcall --walk-list-genealogy-and-collect-tags
3356 ;; OpenDocument schema does not permit table to occur within a
3359 ;; One solution - the easiest and lightweight, in terms of
3360 ;; implementation - is to put the table in an indented text box
3361 ;; and make the text box part of the list-item. Unfortunately if
3362 ;; the table is big and spans multiple pages, the text box could
3363 ;; overflow. In this case, the following attribute will come
3366 ;; ,---- From OpenDocument-v1.1.pdf
3367 ;; | 15.27.28 Overflow behavior
3369 ;; | For text boxes contained within text document, the
3370 ;; | style:overflow-behavior property specifies the behavior of text
3371 ;; | boxes where the containing text does not fit into the text
3374 ;; | If the attribute's value is clip, the text that does not fit
3375 ;; | into the text box is not displayed.
3377 ;; | If the attribute value is auto-create-new-frame, a new frame
3378 ;; | will be created on the next page, with the same position and
3379 ;; | dimensions of the original frame.
3381 ;; | If the style:overflow-behavior property's value is
3382 ;; | auto-create-new-frame and the text box has a minimum width or
3383 ;; | height specified, then the text box will grow until the page
3384 ;; | bounds are reached before a new frame is created.
3387 ;; Unfortunately, LibreOffice-3.4.6 doesn't honor
3388 ;; auto-create-new-frame property and always resorts to clipping
3389 ;; the text box. This results in table being truncated.
3391 ;; So we solve the problem the hard (and fun) way using list
3394 ;; The problem only becomes more interesting if you take in to
3395 ;; account the following facts:
3397 ;; - Description lists are simulated as plain lists.
3398 ;; - Low-level headlines can be listified.
3399 ;; - In Org-mode, a table can occur not only as a regular list
3400 ;; item, but also within description lists and low-level
3403 ;; See `org-e-odt-translate-description-lists' and
3404 ;; `org-e-odt-translate-low-level-headlines' for how this is
3408 ;; Discontinue the list.
3409 (mapconcat 'car close-open-tags
"\n")
3410 ;; Put the table in an indented section.
3411 (let* ((table (org-e-odt--table table contents info
))
3412 (level (/ (length (mapcar 'car close-open-tags
)) 2))
3413 (style (format "OrgIndentedSection-Level-%d" level
)))
3414 (when table
(org-e-odt-format-section table style
)))
3415 ;; Continue the list.
3416 (mapconcat 'cdr
(nreverse close-open-tags
) "\n"))))
3421 (defun org-e-odt-target (target contents info
)
3422 "Transcode a TARGET object from Org to ODT.
3423 CONTENTS is nil. INFO is a plist holding contextual
3425 (let ((value (org-element-property :value target
)))
3426 (org-e-odt--target "" (org-export-solidify-link-text value
))))
3431 (defun org-e-odt-timestamp (timestamp contents info
)
3432 "Transcode a TIMESTAMP object from Org to ODT.
3433 CONTENTS is nil. INFO is a plist used as a communication
3435 (let ((timestamp-1 (org-element-property :value timestamp
))
3436 (timestamp-2 (org-element-property :range-end timestamp
)))
3437 (format "<text:span text:style-name=\"%s\">%s</text:span>"
3438 "OrgTimestampWrapper"
3440 (format "<text:span text:style-name=\"%s\">%s</text:span>"
3441 "OrgTimestamp" (org-translate-time timestamp-1
))
3444 (format "<text:span text:style-name=\"%s\">%s</text:span>"
3445 "OrgTimestamp" (org-translate-time timestamp-2
)))))))
3450 (defun org-e-odt-underline (underline contents info
)
3451 "Transcode UNDERLINE from Org to ODT.
3452 CONTENTS is the text with underline markup. INFO is a plist
3453 holding contextual information."
3454 (format "<text:span text:style-name=\"%s\">%s</text:span>"
3455 "Underline" contents
))
3460 (defun org-e-odt-verbatim (verbatim contents info
)
3461 "Transcode a VERBATIM object from Org to ODT.
3462 CONTENTS is nil. INFO is a plist used as a communication
3464 (format "<text:span text:style-name=\"%s\">%s</text:span>"
3465 "OrgCode" (org-element-property :value verbatim
)))
3470 (defun org-e-odt-verse-block (verse-block contents info
)
3471 "Transcode a VERSE-BLOCK element from Org to ODT.
3472 CONTENTS is verse block contents. INFO is a plist holding
3473 contextual information."
3474 ;; Add line breaks to each line of verse.
3475 (setq contents
(replace-regexp-in-string
3476 "\\(<text:line-break/>\\)?[ \t]*\n"
3477 "<text:line-break/>" contents
))
3478 ;; Replace tabs and spaces.
3479 (setq contents
(org-e-odt-fill-tabs-and-spaces contents
))
3480 ;; Surround it in a verse environment.
3481 (org-e-odt--wrap-label
3483 (format "\n<text:p text:style-name=\"%s\">%s</text:p>"
3484 "OrgVerse" contents
)))
3490 ;;;; Description lists
3492 ;; This translator is necessary to handle indented tables in a uniform
3493 ;; manner. See comment in `org-e-odt--table'.
3495 (defun org-e-odt--translate-description-lists (tree backend info
)
3496 ;; OpenDocument has no notion of a description list. So simulate it
3497 ;; using plain lists. Description lists in the exported document
3498 ;; are typeset in the same manner as they are in a typical HTML
3501 ;; Specifically, a description list like this:
3504 ;; | - term-1 :: definition-1
3505 ;; | - term-2 :: definition-2
3508 ;; gets translated in to the following form:
3517 ;; Further effect is achieved by fixing the OD styles as below:
3519 ;; 1. Set the :type property of the simulated lists to
3520 ;; `descriptive-1' and `descriptive-2'. Map these to list-styles
3521 ;; that has *no* bullets whatsoever.
3523 ;; 2. The paragraph containing the definition term is styled to be
3529 (when (equal (org-element-property :type el
) 'descriptive
)
3530 (org-element-set-element
3532 (apply 'org-element-adopt-elements
3533 (list 'plain-list
(list :type
'descriptive-1
))
3536 (org-element-adopt-elements
3537 (list 'item
(list :checkbox
(org-element-property
3539 (list 'paragraph
(list :style
"Text_20_body_20_bold")
3540 (or (org-element-property :tag item
) "(no term)"))
3541 (org-element-adopt-elements
3542 (list 'plain-list
(list :type
'descriptive-2
))
3543 (apply 'org-element-adopt-elements
3545 (org-element-contents item
)))))
3546 (org-element-contents el
)))))
3553 ;; Lists that are marked with attribute `:list-table' are called as
3554 ;; list tables. They will be rendered as a table within the exported
3557 ;; Consider an example. The following list table
3559 ;; #+attr_odt :list-table t
3569 ;; will be exported as though it were an Org table like the one show
3572 ;; | Row 1 | 1.1 | 1.2 | 1.3 |
3573 ;; | Row 2 | 2.1 | 2.2 | 2.3 |
3575 ;; Note that org-tables are NOT multi-line and each line is mapped to
3576 ;; a unique row in the exported document. So if an exported table
3577 ;; needs to contain a single paragraph (with copious text) it needs to
3578 ;; be typed up in a single line. Editing such long lines using the
3579 ;; table editor will be a cumbersome task. Furthermore inclusion of
3580 ;; multi-paragraph text in a table cell is well-nigh impossible.
3582 ;; A LIST-TABLE circumvents above problems.
3584 ;; Note that in the example above the list items could be paragraphs
3585 ;; themselves and the list can be arbitrarily deep.
3587 ;; Inspired by following thread:
3588 ;; https://lists.gnu.org/archive/html/emacs-orgmode/2011-03/msg01101.html
3590 ;; Translate lists to tables
3592 (add-to-list 'org-export-filter-parse-tree-functions
3593 'org-e-odt--translate-list-tables
)
3595 (defun org-e-odt--translate-list-tables (tree backend info
)
3596 (when (eq backend
'e-odt
)
3599 (lambda (plain-list-1)
3600 (when (org-export-read-attribute :attr_odt plain-list-1
:list-table
)
3601 (org-element-set-element
3603 (apply 'org-element-adopt-elements
3608 (lambda (level-1-item)
3609 (apply 'org-element-adopt-elements
3610 (list 'table-row
(list :type
'standard
))
3611 (org-element-adopt-elements
3612 (list 'table-cell nil
)
3613 (car (org-element-contents level-1-item
)))
3614 (let ((plain-list-2 (assq 'plain-list level-1-item
)))
3619 (apply 'org-element-adopt-elements
3620 (list 'table-cell nil
)
3621 (org-element-contents item
)))
3629 ;;; Interactive functions
3631 (defun org-e-odt-create-manifest-file-entry (&rest args
)
3632 (push args org-e-odt-manifest-file-entries
))
3634 (defun org-e-odt-write-manifest-file ()
3635 (make-directory (concat org-e-odt-zip-dir
"META-INF"))
3636 (let ((manifest-file (concat org-e-odt-zip-dir
"META-INF/manifest.xml")))
3637 (with-current-buffer
3638 (let ((nxml-auto-insert-xml-declaration-flag nil
))
3639 (find-file-noselect manifest-file t
))
3641 "<?xml version=\"1.0\" encoding=\"UTF-8\"?>
3642 <manifest:manifest xmlns:manifest=\"urn:oasis:names:tc:opendocument:xmlns:manifest:1.0\" manifest:version=\"1.2\">\n")
3644 (lambda (file-entry)
3645 (let* ((version (nth 2 file-entry
))
3646 (extra (if (not version
) ""
3647 (format " manifest:version=\"%s\"" version
))))
3649 (format org-e-odt-manifest-file-entry-tag
3650 (nth 0 file-entry
) (nth 1 file-entry
) extra
))))
3651 org-e-odt-manifest-file-entries
)
3652 (insert "\n</manifest:manifest>"))))
3654 (defmacro org-e-odt--export-wrap
(out-file &rest body
)
3655 `(let* ((--out-file ,out-file
)
3656 (out-file-type (file-name-extension --out-file
))
3657 (org-e-odt-xml-files '("META-INF/manifest.xml" "content.xml"
3658 "meta.xml" "styles.xml"))
3659 ;; Initialize workarea. All files that end up in the
3660 ;; exported get created here.
3661 (org-e-odt-zip-dir (file-name-as-directory
3662 (make-temp-file (format "%s-" out-file-type
) t
)))
3663 (org-e-odt-manifest-file-entries nil
)
3664 (--cleanup-xml-buffers
3667 ;; Kill all XML buffers.
3668 (mapc (lambda (file)
3669 (let ((buf (get-file-buffer
3670 (concat org-e-odt-zip-dir file
))))
3672 (set-buffer-modified-p nil
)
3673 (kill-buffer buf
))))
3674 org-e-odt-xml-files
)
3675 ;; Delete temporary directory and also other embedded
3676 ;; files that get copied there.
3677 (delete-directory org-e-odt-zip-dir t
)))))
3678 (org-condition-case-unless-debug err
3680 (unless (executable-find "zip")
3681 ;; Not at all OSes ship with zip by default
3682 (error "Executable \"zip\" needed for creating OpenDocument files"))
3683 ;; Do export. This creates a bunch of xml files ready to be
3684 ;; saved and zipped.
3686 ;; Create a manifest entry for content.xml.
3687 (org-e-odt-create-manifest-file-entry "text/xml" "content.xml")
3688 ;; Write mimetype file
3690 '(("odt" .
"application/vnd.oasis.opendocument.text")
3691 ("odf" .
"application/vnd.oasis.opendocument.formula")))
3692 (mimetype (cdr (assoc-string out-file-type mimetypes t
))))
3694 (error "Unknown OpenDocument backend %S" out-file-type
))
3695 (write-region mimetype nil
(concat org-e-odt-zip-dir
"mimetype"))
3696 (org-e-odt-create-manifest-file-entry mimetype
"/" "1.2"))
3697 ;; Write out the manifest entries before zipping
3698 (org-e-odt-write-manifest-file)
3699 ;; Save all XML files.
3700 (mapc (lambda (file)
3701 (let ((buf (get-file-buffer (concat org-e-odt-zip-dir file
))))
3703 (with-current-buffer buf
3704 ;; Prettify output if needed.
3705 (when org-e-odt-prettify-xml
3706 (indent-region (point-min) (point-max)))
3708 org-e-odt-xml-files
)
3710 (let* ((target --out-file
)
3711 (target-name (file-name-nondirectory target
))
3712 (target-dir (file-name-directory target
))
3713 (cmds `(("zip" "-mX0" ,target-name
"mimetype")
3714 ("zip" "-rmTq" ,target-name
"."))))
3715 ;; If a file with same name as the desired output file
3716 ;; exists, remove it.
3717 (when (file-exists-p target
)
3718 (delete-file target
))
3719 ;; Zip up the xml files.
3720 (let ((coding-system-for-write 'no-conversion
) exitcode err-string
)
3721 (message "Creating ODT file...")
3722 ;; Switch temporarily to content.xml. This way Zip
3723 ;; process will inherit `org-e-odt-zip-dir' as the current
3725 (with-current-buffer
3726 (find-file-noselect (concat org-e-odt-zip-dir
"content.xml") t
)
3729 (message "Running %s" (mapconcat 'identity cmd
" "))
3731 (with-output-to-string
3733 (apply 'call-process
(car cmd
)
3734 nil standard-output nil
(cdr cmd
)))))
3735 (or (zerop exitcode
)
3736 (error (concat "Unable to create OpenDocument file."
3737 (format " Zip failed with error (%s)"
3740 ;; Zip file is now in the rightful place.
3741 (rename-file target-name target
)))
3742 (message "Created %s" target
)
3743 ;; Cleanup work directory and work files.
3744 (funcall --cleanup-xml-buffers
)
3745 ;; Open the OpenDocument file in archive-mode for
3747 (find-file-noselect target t
)
3748 ;; Return exported file.
3750 ;; Case 1: Conversion desired on exported file. Run the
3751 ;; converter on the OpenDocument file. Return the
3753 (org-e-odt-preferred-output-format
3754 (or (org-e-odt-convert target org-e-odt-preferred-output-format
)
3756 ;; Case 2: No further conversion. Return exported
3757 ;; OpenDocument file.
3760 ;; Cleanup work directory and work files.
3761 (funcall --cleanup-xml-buffers
)
3762 (message "OpenDocument export failed: %s"
3763 (error-message-string err
))))))
3766 ;;;; Export to OpenDocument formula
3769 (defun org-e-odt-export-as-odf (latex-frag &optional odf-file
)
3770 "Export LATEX-FRAG as OpenDocument formula file ODF-FILE.
3771 Use `org-create-math-formula' to convert LATEX-FRAG first to
3772 MathML. When invoked as an interactive command, use
3773 `org-latex-regexps' to infer LATEX-FRAG from currently active
3774 region. If no LaTeX fragments are found, prompt for it. Push
3775 MathML source to kill ring, if `org-export-copy-to-kill-ring' is
3779 (setq frag
(and (setq frag
(and (region-active-p)
3780 (buffer-substring (region-beginning)
3782 (loop for e in org-latex-regexps
3783 thereis
(when (string-match (nth 1 e
) frag
)
3784 (match-string (nth 2 e
) frag
)))))
3785 (read-string "LaTeX Fragment: " frag nil frag
))
3786 ,(let ((odf-filename (expand-file-name
3788 (file-name-sans-extension
3789 (or (file-name-nondirectory buffer-file-name
)))
3791 (file-name-directory buffer-file-name
))))
3792 (read-file-name "ODF filename: " nil odf-filename nil
3793 (file-name-nondirectory odf-filename
)))))
3794 (let ((filename (or odf-file
3797 (file-name-sans-extension
3798 (or (file-name-nondirectory buffer-file-name
)))
3800 (file-name-directory buffer-file-name
)))))
3801 (org-e-odt--export-wrap
3803 (let* ((buffer (progn
3804 (require 'nxml-mode
)
3805 (let ((nxml-auto-insert-xml-declaration-flag nil
))
3806 (find-file-noselect (concat org-e-odt-zip-dir
3807 "content.xml") t
))))
3808 (coding-system-for-write 'utf-8
)
3809 (save-buffer-coding-system 'utf-8
))
3811 (set-buffer-file-coding-system coding-system-for-write
)
3812 (let ((mathml (org-create-math-formula latex-frag
)))
3813 (unless mathml
(error "No Math formula created"))
3815 ;; Add MathML to kill ring, if needed.
3816 (when org-export-copy-to-kill-ring
3817 (org-kill-new (buffer-string))))))))
3820 (defun org-e-odt-export-as-odf-and-open ()
3821 "Export LaTeX fragment as OpenDocument formula and immediately open it.
3822 Use `org-e-odt-export-as-odf' to read LaTeX fragment and OpenDocument
3825 (org-open-file (call-interactively 'org-e-odt-export-as-odf
) 'system
))
3828 ;;;; Export to OpenDocument Text
3831 (defun org-e-odt-export-to-odt
3832 (&optional subtreep visible-only body-only ext-plist pub-dir
)
3833 "Export current buffer to a HTML file.
3835 If narrowing is active in the current buffer, only export its
3838 If a region is active, export that region.
3840 When optional argument SUBTREEP is non-nil, export the sub-tree
3841 at point, extracting information from the headline properties
3844 When optional argument VISIBLE-ONLY is non-nil, don't export
3845 contents of hidden elements.
3847 When optional argument BODY-ONLY is non-nil, only write code
3848 between \"\\begin{document}\" and \"\\end{document}\".
3850 EXT-PLIST, when provided, is a property list with external
3851 parameters overriding Org default settings, but still inferior to
3852 file-local settings.
3854 When optional argument PUB-DIR is set, use it as the publishing
3857 Return output file's name."
3859 (org-e-odt--export-wrap
3860 (org-export-output-file-name ".odt" subtreep pub-dir
)
3861 (let* ((org-e-odt-embedded-images-count 0)
3862 (org-e-odt-embedded-formulas-count 0)
3863 (org-e-odt-automatic-styles nil
)
3864 (org-e-odt-object-counters nil
)
3865 ;; Let `htmlfontify' know that we are interested in collecting
3867 (hfy-user-sheet-assoc nil
))
3868 ;; Initialize content.xml and kick-off the export process.
3869 (let ((out-buf (progn
3870 (require 'nxml-mode
)
3871 (let ((nxml-auto-insert-xml-declaration-flag nil
))
3873 (concat org-e-odt-zip-dir
"content.xml") t
)))))
3874 (org-export-to-buffer 'e-odt out-buf subtreep visible-only body-only
)))))
3877 ;;;; Convert between OpenDocument and other formats
3879 (defun org-e-odt-reachable-p (in-fmt out-fmt
)
3880 "Return non-nil if IN-FMT can be converted to OUT-FMT."
3882 (let ((reachable-formats (org-e-odt-do-reachable-formats in-fmt
)))
3883 (dolist (e reachable-formats
)
3884 (let ((out-fmt-spec (assoc out-fmt
(cdr e
))))
3886 (throw 'done
(cons (car e
) out-fmt-spec
))))))))
3888 (defun org-e-odt-do-convert (in-file out-fmt
&optional prefix-arg
)
3889 "Workhorse routine for `org-e-odt-convert'."
3890 (require 'browse-url
)
3891 (let* ((in-file (expand-file-name (or in-file buffer-file-name
)))
3892 (dummy (or (file-readable-p in-file
)
3893 (error "Cannot read %s" in-file
)))
3894 (in-fmt (file-name-extension in-file
))
3895 (out-fmt (or out-fmt
(error "Output format unspecified")))
3896 (how (or (org-e-odt-reachable-p in-fmt out-fmt
)
3897 (error "Cannot convert from %s format to %s format?"
3899 (convert-process (car how
))
3900 (out-file (concat (file-name-sans-extension in-file
) "."
3901 (nth 1 (or (cdr how
) out-fmt
))))
3902 (extra-options (or (nth 2 (cdr how
)) ""))
3903 (out-dir (file-name-directory in-file
))
3904 (cmd (format-spec convert-process
3905 `((?i .
,(shell-quote-argument in-file
))
3906 (?I .
,(browse-url-file-url in-file
))
3909 (?O .
,(browse-url-file-url out-file
))
3910 (?d .
, (shell-quote-argument out-dir
))
3911 (?D .
,(browse-url-file-url out-dir
))
3912 (?x .
,extra-options
)))))
3913 (when (file-exists-p out-file
)
3914 (delete-file out-file
))
3916 (message "Executing %s" cmd
)
3917 (let ((cmd-output (shell-command-to-string cmd
)))
3918 (message "%s" cmd-output
))
3921 ((file-exists-p out-file
)
3922 (message "Exported to %s" out-file
)
3924 (message "Opening %s..." out-file
)
3925 (org-open-file out-file
'system
))
3928 (message "Export to %s failed" out-file
)
3931 (defun org-e-odt-do-reachable-formats (in-fmt)
3932 "Return verbose info about formats to which IN-FMT can be converted.
3933 Return a list where each element is of the
3934 form (CONVERTER-PROCESS . OUTPUT-FMT-ALIST). See
3935 `org-e-odt-convert-processes' for CONVERTER-PROCESS and see
3936 `org-e-odt-convert-capabilities' for OUTPUT-FMT-ALIST."
3938 (and org-e-odt-convert-process
3939 (cadr (assoc-string org-e-odt-convert-process
3940 org-e-odt-convert-processes t
))))
3942 (and org-e-odt-convert-process
3943 (cadr (assoc-string org-e-odt-convert-process
3944 org-e-odt-convert-processes t
))
3945 org-e-odt-convert-capabilities
))
3948 (dolist (c capabilities
)
3949 (when (member in-fmt
(nth 1 c
))
3950 (push (cons converter
(nth 2 c
)) reachable-formats
))))
3953 (defun org-e-odt-reachable-formats (in-fmt)
3954 "Return list of formats to which IN-FMT can be converted.
3955 The list of the form (OUTPUT-FMT-1 OUTPUT-FMT-2 ...)."
3957 (mapc (lambda (e) (add-to-list 'l e
))
3958 (apply 'append
(mapcar
3959 (lambda (e) (mapcar 'car
(cdr e
)))
3960 (org-e-odt-do-reachable-formats in-fmt
))))
3963 (defun org-e-odt-convert-read-params ()
3964 "Return IN-FILE and OUT-FMT params for `org-e-odt-do-convert'.
3965 This is a helper routine for interactive use."
3966 (let* ((input (if (featurep 'ido
) 'ido-completing-read
'completing-read
))
3967 (in-file (read-file-name "File to be converted: "
3968 nil buffer-file-name t
))
3969 (in-fmt (file-name-extension in-file
))
3970 (out-fmt-choices (org-e-odt-reachable-formats in-fmt
))
3972 (or (and out-fmt-choices
3973 (funcall input
"Output format: "
3974 out-fmt-choices nil nil nil
))
3976 "No known converter or no known output formats for %s files"
3978 (list in-file out-fmt
)))
3981 (defun org-e-odt-convert (&optional in-file out-fmt prefix-arg
)
3982 "Convert IN-FILE to format OUT-FMT using a command line converter.
3983 IN-FILE is the file to be converted. If unspecified, it defaults
3984 to variable `buffer-file-name'. OUT-FMT is the desired output
3985 format. Use `org-e-odt-convert-process' as the converter.
3986 If PREFIX-ARG is non-nil then the newly converted file is opened
3987 using `org-open-file'."
3989 (append (org-e-odt-convert-read-params) current-prefix-arg
))
3990 (org-e-odt-do-convert in-file out-fmt prefix-arg
))
3992 ;;; Library Initializations
3996 ;; Let Emacs open all OpenDocument files in archive mode
3997 (add-to-list 'auto-mode-alist
3998 (cons (concat "\\." (car desc
) "\\'") 'archive-mode
)))
3999 org-e-odt-file-extensions
)
4001 (provide 'org-e-odt
)
4003 ;;; org-e-odt.el ends here