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
87 .
(org-e-odt--translate-description-lists
88 org-e-odt--translate-list-tables
)))
91 ((?o
"As ODT file" org-e-odt-export-to-odt
)
92 (?O
"As ODT file and open"
94 (org-open-file (org-e-odt-export-to-odt s v b
) 'system
)))))
96 ((:odt-styles-file
"ODT_STYLES_FILE" nil nil t
)
97 (:LaTeX-fragments nil
"LaTeX" org-export-with-LaTeX-fragments
)))
104 ;;; Function Declarations
106 (declare-function org-id-find-id-file
"org-id" (id))
107 (declare-function hfy-face-to-style
"htmlfontify" (fn))
108 (declare-function hfy-face-or-def-to-name
"htmlfontify" (fn))
109 (declare-function archive-zip-extract
"arc-mode.el" (archive name
))
110 (declare-function org-create-math-formula
"org" (latex-frag &optional
112 (declare-function browse-url-file-url
"browse-url" (file))
116 ;;; Internal Variables
118 (defconst org-e-odt-lib-dir
119 (file-name-directory load-file-name
)
120 "Location of ODT exporter.
121 Use this to infer values of `org-e-odt-styles-dir' and
122 `org-e-odt-schema-dir'.")
124 (defvar org-e-odt-data-dir
125 (expand-file-name "../../etc/" org-e-odt-lib-dir
)
126 "Data directory for ODT exporter.
127 Use this to infer values of `org-e-odt-styles-dir' and
128 `org-e-odt-schema-dir'.")
130 (defconst org-e-odt-special-string-regexps
131 '(("\\\\-" .
"­\\1") ; shy
132 ("---\\([^-]\\)" .
"—\\1") ; mdash
133 ("--\\([^-]\\)" .
"–\\1") ; ndash
134 ("\\.\\.\\." .
"…")) ; hellip
135 "Regular expressions for special string conversion.")
137 (defconst org-e-odt-schema-dir-list
139 (and org-e-odt-data-dir
140 (expand-file-name "./schema/" org-e-odt-data-dir
)) ; bail out
142 (and (boundp 'org-e-odt-data-dir
) org-e-odt-data-dir
; see make install
143 (expand-file-name "./schema/" org-e-odt-data-dir
))))
144 "List of directories to search for OpenDocument schema files.
145 Use this list to set the default value of
146 `org-e-odt-schema-dir'. The entries in this list are
147 populated heuristically based on the values of `org-e-odt-lib-dir'
148 and `org-e-odt-data-dir'.")
150 (defconst org-e-odt-styles-dir-list
152 (and org-e-odt-data-dir
153 (expand-file-name "./styles/" org-e-odt-data-dir
)) ; bail out
155 (and (boundp 'org-e-odt-data-dir
) org-e-odt-data-dir
; see make install
156 (expand-file-name "./styles/" org-e-odt-data-dir
)))
157 (expand-file-name "../../etc/styles/" org-e-odt-lib-dir
) ; git
158 (expand-file-name "./etc/styles/" org-e-odt-lib-dir
) ; elpa
159 (expand-file-name "./org/" data-directory
) ; system
161 "List of directories to search for OpenDocument styles files.
162 See `org-e-odt-styles-dir'. The entries in this list are populated
163 heuristically based on the values of `org-e-odt-lib-dir' and
164 `org-e-odt-data-dir'.")
166 (defconst org-e-odt-styles-dir
169 (message "Debug (org-e-odt): Searching for OpenDocument styles files...")
170 (mapc (lambda (styles-dir)
172 (message "Debug (org-e-odt): Trying %s..." styles-dir
)
173 (when (and (file-readable-p
175 "OrgOdtContentTemplate.xml" styles-dir
))
178 "OrgOdtStyles.xml" styles-dir
)))
179 (message "Debug (org-e-odt): Using styles under %s"
181 (throw 'styles-dir styles-dir
))))
182 org-e-odt-styles-dir-list
)
185 (error "Error (org-e-odt): Cannot find factory styles files. Aborting."))
187 "Directory that holds auxiliary XML files used by the ODT exporter.
189 This directory contains the following XML files -
190 \"OrgOdtStyles.xml\" and \"OrgOdtContentTemplate.xml\". These
191 XML files are used as the default values of
192 `org-e-odt-styles-file' and
193 `org-e-odt-content-template-file'.
195 The default value of this variable varies depending on the
196 version of org in use and is initialized from
197 `org-e-odt-styles-dir-list'. Note that the user could be using org
198 from one of: org's own private git repository, GNU ELPA tar or
201 (defconst org-e-odt-bookmark-prefix
"OrgXref.")
203 (defconst org-e-odt-manifest-file-entry-tag
204 "\n<manifest:file-entry manifest:media-type=\"%s\" manifest:full-path=\"%s\"%s/>")
206 (defconst org-e-odt-file-extensions
207 '(("odt" .
"OpenDocument Text")
208 ("ott" .
"OpenDocument Text Template")
209 ("odm" .
"OpenDocument Master Document")
210 ("ods" .
"OpenDocument Spreadsheet")
211 ("ots" .
"OpenDocument Spreadsheet Template")
212 ("odg" .
"OpenDocument Drawing (Graphics)")
213 ("otg" .
"OpenDocument Drawing Template")
214 ("odp" .
"OpenDocument Presentation")
215 ("otp" .
"OpenDocument Presentation Template")
216 ("odi" .
"OpenDocument Image")
217 ("odf" .
"OpenDocument Formula")
218 ("odc" .
"OpenDocument Chart")))
220 (defvar org-e-odt-table-style-format
222 <style:style style:name=\"%s\" style:family=\"table\">
223 <style:table-properties style:rel-width=\"%d%%\" fo:margin-top=\"0cm\" fo:margin-bottom=\"0.20cm\" table:align=\"center\"/>
226 "Template for auto-generated Table styles.")
228 (defvar org-e-odt-automatic-styles
'()
229 "Registry of automatic styles for various OBJECT-TYPEs.
230 The variable has the following form:
232 \(\(OBJECT-NAME-A.1 OBJECT-PROPS-A.1\)
233 \(OBJECT-NAME-A.2 OBJECT-PROPS-A.2\) ...\)\)
235 \(\(OBJECT-NAME-B.1 OBJECT-PROPS-B.1\)
236 \(OBJECT-NAME-B.2 OBJECT-PROPS-B.2\) ...\)\)
239 OBJECT-TYPEs could be \"Section\", \"Table\", \"Figure\" etc.
240 OBJECT-PROPS is (typically) a plist created by passing
241 \"#+ATTR_ODT: \" option to `org-e-odt-parse-block-attributes'.
243 Use `org-e-odt-add-automatic-style' to add update this variable.'")
245 (defvar org-e-odt-object-counters nil
246 "Running counters for various OBJECT-TYPEs.
247 Use this to generate automatic names and style-names. See
248 `org-e-odt-add-automatic-style'.")
250 (defvar org-e-odt-src-block-paragraph-format
251 "<style:style style:name=\"OrgSrcBlock\" style:family=\"paragraph\" style:parent-style-name=\"Preformatted_20_Text\">
252 <style:paragraph-properties fo:background-color=\"%s\" fo:padding=\"0.049cm\" fo:border=\"0.51pt solid #000000\" style:shadow=\"none\">
253 <style:background-image/>
254 </style:paragraph-properties>
255 <style:text-properties fo:color=\"%s\"/>
257 "Custom paragraph style for colorized source and example blocks.
258 This style is much the same as that of \"OrgFixedWidthBlock\"
259 except that the foreground and background colors are set
260 according to the default face identified by the `htmlfontify'.")
262 (defvar hfy-optimisations
)
263 (defvar org-e-odt-embedded-formulas-count
0)
264 (defvar org-e-odt-entity-frame-styles
265 '(("As-CharImage" "__Figure__" ("OrgInlineImage" nil
"as-char"))
266 ("ParagraphImage" "__Figure__" ("OrgDisplayImage" nil
"paragraph"))
267 ("PageImage" "__Figure__" ("OrgPageImage" nil
"page"))
268 ("CaptionedAs-CharImage" "__Figure__"
270 " style:rel-width=\"100%\" style:rel-height=\"scale\"" "paragraph")
271 ("OrgInlineImage" nil
"as-char"))
272 ("CaptionedParagraphImage" "__Figure__"
274 " style:rel-width=\"100%\" style:rel-height=\"scale\"" "paragraph")
275 ("OrgImageCaptionFrame" nil
"paragraph"))
276 ("CaptionedPageImage" "__Figure__"
278 " style:rel-width=\"100%\" style:rel-height=\"scale\"" "paragraph")
279 ("OrgPageImageCaptionFrame" nil
"page"))
280 ("InlineFormula" "__MathFormula__" ("OrgInlineFormula" nil
"as-char"))
281 ("DisplayFormula" "__MathFormula__" ("OrgDisplayFormula" nil
"as-char"))
282 ("CaptionedDisplayFormula" "__MathFormula__"
283 ("OrgCaptionedFormula" nil
"paragraph")
284 ("OrgFormulaCaptionFrame" nil
"as-char"))))
286 (defvar org-e-odt-embedded-images-count
0)
287 (defvar org-e-odt-image-size-probe-method
288 (append (and (executable-find "identify") '(imagemagick)) ; See Bug#10675
290 "Ordered list of methods for determining image sizes.")
292 (defvar org-e-odt-default-image-sizes-alist
293 '(("as-char" .
(5 .
0.4))
294 ("paragraph" .
(5 .
5)))
295 "Hardcoded image dimensions one for each of the anchor
298 ;; A4 page size is 21.0 by 29.7 cms
299 ;; The default page settings has 2cm margin on each of the sides. So
300 ;; the effective text area is 17.0 by 25.7 cm
301 (defvar org-e-odt-max-image-size
'(17.0 .
20.0)
302 "Limiting dimensions for an embedded image.")
304 (defvar org-e-odt-label-styles
305 '(("math-formula" "%c" "text" "(%n)")
306 ("math-label" "(%n)" "text" "(%n)")
307 ("category-and-value" "%e %n: %c" "category-and-value" "%e %n")
308 ("value" "%e %n: %c" "value" "%n"))
309 "Specify how labels are applied and referenced.
310 This is an alist where each element is of the
311 form (LABEL-STYLE-NAME LABEL-ATTACH-FMT LABEL-REF-MODE
314 LABEL-ATTACH-FMT controls how labels and captions are attached to
315 an entity. It may contain following specifiers - %e, %n and %c.
316 %e is replaced with the CATEGORY-NAME. %n is replaced with
317 \"<text:sequence ...> SEQNO </text:sequence>\". %c is replaced
318 with CAPTION. See `org-e-odt-format-label-definition'.
320 LABEL-REF-MODE and LABEL-REF-FMT controls how label references
321 are generated. The following XML is generated for a label
322 reference - \"<text:sequence-ref
323 text:reference-format=\"LABEL-REF-MODE\" ...> LABEL-REF-FMT
324 </text:sequence-ref>\". LABEL-REF-FMT may contain following
325 specifiers - %e and %n. %e is replaced with the CATEGORY-NAME.
326 %n is replaced with SEQNO. See
327 `org-e-odt-format-label-reference'.")
329 (defvar org-e-odt-category-map-alist
330 '(("__Table__" "Table" "value" "Table")
331 ("__Figure__" "Illustration" "value" "Figure")
332 ("__MathFormula__" "Text" "math-formula" "Equation")
333 ("__DvipngImage__" "Equation" "value" "Equation")
334 ("__Listing__" "Listing" "value" "Listing")
335 ;; ("__Table__" "Table" "category-and-value")
336 ;; ("__Figure__" "Figure" "category-and-value")
337 ;; ("__DvipngImage__" "Equation" "category-and-value")
339 "Map a CATEGORY-HANDLE to OD-VARIABLE and LABEL-STYLE.
340 This is a list where each entry is of the form \\(CATEGORY-HANDLE
341 OD-VARIABLE LABEL-STYLE CATEGORY-NAME\\). CATEGORY_HANDLE
342 identifies the captionable entity in question. OD-VARIABLE is
343 the OpenDocument sequence counter associated with the entity.
344 These counters are declared within
345 \"<text:sequence-decls>...</text:sequence-decls>\" block of
346 `org-e-odt-content-template-file'. LABEL-STYLE is a key into
347 `org-e-odt-label-styles' and specifies how a given entity should
348 be captioned and referenced. CATEGORY-NAME is used for
349 qualifying captions on export. You can modify the CATEGORY-NAME
350 used in the exported document by modifying
351 `org-export-dictionary'. For example, an embedded image in an
352 English document is captioned as \"Figure 1: Orgmode Logo\", by
353 default. If you want the image to be captioned as \"Illustration
354 1: Orgmode Logo\" instead, install an entry in
355 `org-export-dictionary' which translates \"Figure\" to
356 \"Illustration\" when the language is \"en\" and encoding is
359 (defvar org-e-odt-manifest-file-entries nil
)
360 (defvar hfy-user-sheet-assoc
)
362 (defvar org-e-odt-zip-dir nil
363 "Temporary work directory for OpenDocument exporter.")
367 ;;; User Configuration Variables
369 (defgroup org-export-e-odt nil
370 "Options for exporting Org mode files to ODT."
371 :tag
"Org Export ODT"
377 (defcustom org-e-odt-prettify-xml nil
378 "Specify whether or not the xml output should be prettified.
379 When this option is turned on, `indent-region' is run on all
380 component xml buffers before they are saved. Turn this off for
381 regular use. Turn this on if you need to examine the xml
383 :group
'org-export-e-odt
390 (defcustom org-e-odt-schema-dir
393 (message "Debug (org-e-odt): Searching for OpenDocument schema files...")
397 (message "Debug (org-e-odt): Trying %s..." schema-dir
)
398 (when (and (file-readable-p
399 (expand-file-name "od-manifest-schema-v1.2-cs01.rnc"
402 (expand-file-name "od-schema-v1.2-cs01.rnc"
405 (expand-file-name "schemas.xml" schema-dir
)))
406 (message "Debug (org-e-odt): Using schema files under %s"
408 (throw 'schema-dir schema-dir
))))
409 org-e-odt-schema-dir-list
)
410 (message "Debug (org-e-odt): No OpenDocument schema files installed")
413 "Directory that contains OpenDocument schema files.
415 This directory contains:
416 1. rnc files for OpenDocument schema
417 2. a \"schemas.xml\" file that specifies locating rules needed
418 for auto validation of OpenDocument XML files.
420 Use the customize interface to set this variable. This ensures
421 that `rng-schema-locating-files' is updated and auto-validation
422 of OpenDocument XML takes place based on the value
423 `rng-nxml-auto-validate-flag'.
425 The default value of this variable varies depending on the
426 version of org in use and is initialized from
427 `org-e-odt-schema-dir-list'. The OASIS schema files are available
428 only in the org's private git repository. It is *not* bundled
429 with GNU ELPA tar or standard Emacs distribution."
431 (const :tag
"Not set" nil
)
432 (directory :tag
"Schema directory"))
433 :group
'org-export-e-odt
437 "Set `org-e-odt-schema-dir'.
438 Also add it to `rng-schema-locating-files'."
439 (let ((schema-dir value
))
443 (expand-file-name "od-manifest-schema-v1.2-cs01.rnc" schema-dir
))
445 (expand-file-name "od-schema-v1.2-cs01.rnc" schema-dir
))
447 (expand-file-name "schemas.xml" schema-dir
)))
450 (message "Error (org-e-odt): %s has no OpenDocument schema files"
453 (when org-e-odt-schema-dir
454 (eval-after-load 'rng-loc
455 '(add-to-list 'rng-schema-locating-files
456 (expand-file-name "schemas.xml"
457 org-e-odt-schema-dir
))))))
462 (defcustom org-e-odt-content-template-file nil
463 "Template file for \"content.xml\".
464 The exporter embeds the exported content just before
465 \"</office:text>\" element.
467 If unspecified, the file named \"OrgOdtContentTemplate.xml\"
468 under `org-e-odt-styles-dir' is used."
470 :group
'org-export-e-odt
473 (defcustom org-e-odt-styles-file nil
474 "Default styles file for use with ODT export.
475 Valid values are one of:
477 2. path to a styles.xml file
478 3. path to a *.odt or a *.ott file
479 4. list of the form (ODT-OR-OTT-FILE (FILE-MEMBER-1 FILE-MEMBER-2
482 In case of option 1, an in-built styles.xml is used. See
483 `org-e-odt-styles-dir' for more information.
485 In case of option 3, the specified file is unzipped and the
486 styles.xml embedded therein is used.
488 In case of option 4, the specified ODT-OR-OTT-FILE is unzipped
489 and FILE-MEMBER-1, FILE-MEMBER-2 etc are copied in to the
490 generated odt file. Use relative path for specifying the
491 FILE-MEMBERS. styles.xml must be specified as one of the
494 Use options 1, 2 or 3 only if styles.xml alone suffices for
495 achieving the desired formatting. Use option 4, if the styles.xml
496 references additional files like header and footer images for
497 achieving the desired formatting.
499 Use \"#+ODT_STYLES_FILE: ...\" directive to set this variable on
500 a per-file basis. For example,
502 #+ODT_STYLES_FILE: \"/path/to/styles.xml\" or
503 #+ODT_STYLES_FILE: (\"/path/to/file.ott\" (\"styles.xml\" \"image/hdr.png\"))."
504 :group
'org-export-e-odt
508 (const :tag
"Factory settings" nil
)
509 (file :must-match t
:tag
"styles.xml")
510 (file :must-match t
:tag
"ODT or OTT file")
511 (list :tag
"ODT or OTT file + Members"
512 (file :must-match t
:tag
"ODF Text or Text Template file")
514 (file :tag
" Member" "styles.xml")
515 (repeat (file :tag
"Member"))))))
517 (defcustom org-e-odt-display-outline-level
2
518 "Outline levels considered for enumerating captioned entities."
519 :group
'org-export-e-odt
523 ;;;; Document conversion
525 (defcustom org-e-odt-convert-processes
527 "soffice --headless --convert-to %f%x --outdir %d %i")
529 "unoconv -f %f -o %d %i"))
530 "Specify a list of document converters and their usage.
531 The converters in this list are offered as choices while
532 customizing `org-e-odt-convert-process'.
534 This variable is a list where each element is of the
535 form (CONVERTER-NAME CONVERTER-CMD). CONVERTER-NAME is the name
536 of the converter. CONVERTER-CMD is the shell command for the
537 converter and can contain format specifiers. These format
538 specifiers are interpreted as below:
540 %i input file name in full
541 %I input file name as a URL
542 %f format of the output file
543 %o output file name in full
544 %O output file name as a URL
545 %d output dir in full
546 %D output dir as a URL.
547 %x extra options as set in `org-e-odt-convert-capabilities'."
548 :group
'org-export-e-odt
552 (const :tag
"None" nil
)
553 (alist :tag
"Converters"
554 :key-type
(string :tag
"Converter Name")
555 :value-type
(group (string :tag
"Command line")))))
557 (defcustom org-e-odt-convert-process
"LibreOffice"
558 "Use this converter to convert from \"odt\" format to other formats.
559 During customization, the list of converter names are populated
560 from `org-e-odt-convert-processes'."
561 :group
'org-export-e-odt
563 :type
'(choice :convert-widget
565 (apply 'widget-convert
(widget-type w
)
566 (eval (car (widget-get w
:args
)))))
567 `((const :tag
"None" nil
)
568 ,@(mapcar (lambda (c)
569 `(const :tag
,(car c
) ,(car c
)))
570 org-e-odt-convert-processes
))))
572 (defcustom org-e-odt-convert-capabilities
574 ("odt" "ott" "doc" "rtf" "docx")
575 (("pdf" "pdf") ("odt" "odt") ("rtf" "rtf") ("ott" "ott")
576 ("doc" "doc" ":\"MS Word 97\"") ("docx" "docx") ("html" "html")))
579 (("pdf" "pdf") ("odt" "odt") ("html" "html")))
581 ("ods" "ots" "xls" "csv" "xlsx")
582 (("pdf" "pdf") ("ots" "ots") ("html" "html") ("csv" "csv") ("ods" "ods")
583 ("xls" "xls") ("xlsx" "xlsx")))
585 ("odp" "otp" "ppt" "pptx")
586 (("pdf" "pdf") ("swf" "swf") ("odp" "odp") ("otp" "otp") ("ppt" "ppt")
587 ("pptx" "pptx") ("odg" "odg"))))
588 "Specify input and output formats of `org-e-odt-convert-process'.
589 More correctly, specify the set of input and output formats that
590 the user is actually interested in.
592 This variable is an alist where each element is of the
593 form (DOCUMENT-CLASS INPUT-FMT-LIST OUTPUT-FMT-ALIST).
594 INPUT-FMT-LIST is a list of INPUT-FMTs. OUTPUT-FMT-ALIST is an
595 alist where each element is of the form (OUTPUT-FMT
596 OUTPUT-FILE-EXTENSION EXTRA-OPTIONS).
598 The variable is interpreted as follows:
599 `org-e-odt-convert-process' can take any document that is in
600 INPUT-FMT-LIST and produce any document that is in the
601 OUTPUT-FMT-LIST. A document converted to OUTPUT-FMT will have
602 OUTPUT-FILE-EXTENSION as the file name extension. OUTPUT-FMT
603 serves dual purposes:
604 - It is used for populating completion candidates during
605 `org-e-odt-convert' commands.
606 - It is used as the value of \"%f\" specifier in
607 `org-e-odt-convert-process'.
609 EXTRA-OPTIONS is used as the value of \"%x\" specifier in
610 `org-e-odt-convert-process'.
612 DOCUMENT-CLASS is used to group a set of file formats in
613 INPUT-FMT-LIST in to a single class.
615 Note that this variable inherently captures how LibreOffice based
616 converters work. LibreOffice maps documents of various formats
617 to classes like Text, Web, Spreadsheet, Presentation etc and
618 allow document of a given class (irrespective of it's source
619 format) to be converted to any of the export formats associated
622 See default setting of this variable for an typical
624 :group
'org-export-e-odt
628 (const :tag
"None" nil
)
629 (alist :tag
"Capabilities"
630 :key-type
(string :tag
"Document Class")
632 (group (repeat :tag
"Input formats" (string :tag
"Input format"))
633 (alist :tag
"Output formats"
634 :key-type
(string :tag
"Output format")
636 (group (string :tag
"Output file extension")
638 (const :tag
"None" nil
)
639 (string :tag
"Extra options"))))))))
641 (defcustom org-e-odt-preferred-output-format nil
642 "Automatically post-process to this format after exporting to \"odt\".
643 Command `org-e-odt-export-to-odt' exports first to \"odt\" format
644 and then uses `org-e-odt-convert-process' to convert the
645 resulting document to this format. During customization of this
646 variable, the list of valid values are populated based on
647 `org-e-odt-convert-capabilities'.
649 You can set this option on per-file basis using file local
650 values. See Info node `(emacs) File Variables'."
651 :group
'org-export-e-odt
653 :type
'(choice :convert-widget
655 (apply 'widget-convert
(widget-type w
)
656 (eval (car (widget-get w
:args
)))))
657 `((const :tag
"None" nil
)
658 ,@(mapcar (lambda (c)
660 (org-e-odt-reachable-formats "odt")))))
662 (put 'org-e-odt-preferred-output-format
'safe-local-variable
'stringp
)
667 (defcustom org-e-odt-format-drawer-function nil
668 "Function called to format a drawer in HTML code.
670 The function must accept two parameters:
671 NAME the drawer name, like \"LOGBOOK\"
672 CONTENTS the contents of the drawer.
674 The function should return the string to be exported.
676 For example, the variable could be set to the following function
677 in order to mimic default behaviour:
679 \(defun org-e-odt-format-drawer-default \(name contents\)
680 \"Format a drawer element for HTML export.\"
682 :group
'org-export-e-odt
688 (defcustom org-e-odt-format-headline-function nil
689 "Function to format headline text.
691 This function will be called with 5 arguments:
692 TODO the todo keyword \(string or nil\).
693 TODO-TYPE the type of todo \(symbol: `todo', `done', nil\)
694 PRIORITY the priority of the headline \(integer or nil\)
695 TEXT the main headline text \(string\).
696 TAGS the tags string, separated with colons \(string or nil\).
698 The function result will be used in the section format string.
700 As an example, one could set the variable to the following, in
701 order to reproduce the default set-up:
703 \(defun org-e-odt-format-headline \(todo todo-type priority text tags\)
704 \"Default format function for an headline.\"
706 \(format \"\\\\textbf{\\\\textsc{\\\\textsf{%s}}} \" todo\)\)
708 \(format \"\\\\framebox{\\\\#%c} \" priority\)\)
710 \(when tags \(format \"\\\\hfill{}\\\\textsc{%s}\" tags\)\)\)\)"
711 :group
'org-export-e-odt
717 (defcustom org-e-odt-format-inlinetask-function nil
718 "Function called to format an inlinetask in HTML code.
720 The function must accept six parameters:
721 TODO the todo keyword, as a string
722 TODO-TYPE the todo type, a symbol among `todo', `done' and nil.
723 PRIORITY the inlinetask priority, as a string
724 NAME the inlinetask name, as a string.
725 TAGS the inlinetask tags, as a string.
726 CONTENTS the contents of the inlinetask, as a string.
728 The function should return the string to be exported.
730 For example, the variable could be set to the following function
731 in order to mimic default behaviour:
733 \(defun org-e-odt-format-inlinetask \(todo type priority name tags contents\)
734 \"Format an inline task element for HTML export.\"
738 \(format \"\\\\textbf{\\\\textsf{\\\\textsc{%s}}} \" todo\)\)
739 \(when priority \(format \"\\\\framebox{\\\\#%c} \" priority\)\)
741 \(when tags \(format \"\\\\hfill{}\\\\textsc{%s}\" tags\)\)\)\)\)
742 \(format \(concat \"\\\\begin{center}\\n\"
744 \"\\\\begin{minipage}[c]{.6\\\\textwidth}\\n\"
746 \"\\\\rule[.8em]{\\\\textwidth}{2pt}\\n\\n\"
748 \"\\\\end{minipage}}\"
749 \"\\\\end{center}\"\)
750 full-title contents\)\)"
751 :group
'org-export-e-odt
757 (defcustom org-e-odt-inline-image-rules
758 '(("file" .
"\\.\\(jpeg\\|jpg\\|png\\|gif\\)\\'"))
759 "Rules characterizing image files that can be inlined into HTML.
761 A rule consists in an association whose key is the type of link
762 to consider, and value is a regexp that will be matched against
765 Note that, by default, the image extension *actually* allowed
766 depend on the way the HTML file is processed. When used with
767 pdflatex, pdf, jpg and png images are OK. When processing
768 through dvi to Postscript, only ps and eps are allowed. The
769 default we use here encompasses both."
770 :group
'org-export-e-odt
771 :type
'(alist :key-type
(string :tag
"Type")
772 :value-type
(regexp :tag
"Path")))
774 (defcustom org-e-odt-pixels-per-inch display-pixels-per-inch
775 "Scaling factor for converting images pixels to inches.
776 Use this for sizing of embedded images. See Info node `(org)
777 Images in ODT export' for more information."
779 :group
'org-export-e-odt
785 (defcustom org-e-odt-quotes
787 ("\\(\\s-\\|[[(]\\|^\\)\"" .
"« ")
788 ("\\(\\S-\\)\"" .
"» ")
789 ("\\(\\s-\\|(\\|^\\)'" .
"'"))
791 ("\\(\\s-\\|[[(]\\|^\\)\"" .
"“")
792 ("\\(\\S-\\)\"" .
"”")
793 ("\\(\\s-\\|(\\|^\\)'" .
"‘")
794 ("\\(\\S-\\)'" .
"’")))
795 "Alist for quotes to use when converting english double-quotes.
797 The CAR of each item in this alist is the language code.
798 The CDR of each item in this alist is a list of three CONS:
799 - the first CONS defines the opening quote;
800 - the second CONS defines the closing quote;
801 - the last CONS defines single quotes.
803 For each item in a CONS, the first string is a regexp
804 for allowed characters before/after the quote, the second
805 string defines the replacement string for this quote."
806 :group
'org-export-e-odt
808 (cons :tag
"Opening quote"
809 (string :tag
"Regexp for char before")
810 (string :tag
"Replacement quote "))
811 (cons :tag
"Closing quote"
812 (string :tag
"Regexp for char after ")
813 (string :tag
"Replacement quote "))
814 (cons :tag
"Single quote"
815 (string :tag
"Regexp for char before")
816 (string :tag
"Replacement quote "))))
821 (defcustom org-e-odt-create-custom-styles-for-srcblocks t
822 "Whether custom styles for colorized source blocks be automatically created.
823 When this option is turned on, the exporter creates custom styles
824 for source blocks based on the advice of `htmlfontify'. Creation
825 of custom styles happen as part of `org-e-odt-hfy-face-to-css'.
827 When this option is turned off exporter does not create such
830 Use the latter option if you do not want the custom styles to be
831 based on your current display settings. It is necessary that the
832 styles.xml already contains needed styles for colorizing to work.
834 This variable is effective only if
835 `org-e-odt-fontify-srcblocks' is turned on."
836 :group
'org-export-e-odt
840 (defcustom org-e-odt-fontify-srcblocks t
841 "Specify whether or not source blocks need to be fontified.
842 Turn this option on if you want to colorize the source code
843 blocks in the exported file. For colorization to work, you need
844 to make available an enhanced version of `htmlfontify' library."
846 :group
'org-export-e-odt
852 (defcustom org-e-odt-table-caption-above t
853 "When non-nil, place caption string at the beginning of the table.
854 Otherwise, place it near the end."
855 :group
'org-export-e-odt
858 (defcustom org-e-odt-table-styles
859 '(("OrgEquation" "OrgEquation"
860 ((use-first-column-styles . t
)
861 (use-last-column-styles . t
)))
862 ("TableWithHeaderRowAndColumn" "Custom"
863 ((use-first-row-styles . t
)
864 (use-first-column-styles . t
)))
865 ("TableWithFirstRowandLastRow" "Custom"
866 ((use-first-row-styles . t
)
867 (use-last-row-styles . t
)))
868 ("GriddedTable" "Custom" nil
))
869 "Specify how Table Styles should be derived from a Table Template.
870 This is a list where each element is of the
871 form (TABLE-STYLE-NAME TABLE-TEMPLATE-NAME TABLE-CELL-OPTIONS).
873 TABLE-STYLE-NAME is the style associated with the table through
874 \"#+ATTR_ODT: :style TABLE-STYLE-NAME\" line.
876 TABLE-TEMPLATE-NAME is a set of - upto 9 - automatic
877 TABLE-CELL-STYLE-NAMEs and PARAGRAPH-STYLE-NAMEs (as defined
878 below) that is included in
879 `org-e-odt-content-template-file'.
881 TABLE-CELL-STYLE-NAME := TABLE-TEMPLATE-NAME + TABLE-CELL-TYPE +
883 PARAGRAPH-STYLE-NAME := TABLE-TEMPLATE-NAME + TABLE-CELL-TYPE +
885 TABLE-CELL-TYPE := \"FirstRow\" | \"LastColumn\" |
886 \"FirstRow\" | \"LastRow\" |
887 \"EvenRow\" | \"OddRow\" |
888 \"EvenColumn\" | \"OddColumn\" | \"\"
889 where \"+\" above denotes string concatenation.
891 TABLE-CELL-OPTIONS is an alist where each element is of the
892 form (TABLE-CELL-STYLE-SELECTOR . ON-OR-OFF).
893 TABLE-CELL-STYLE-SELECTOR := `use-first-row-styles' |
894 `use-last-row-styles' |
895 `use-first-column-styles' |
896 `use-last-column-styles' |
897 `use-banding-rows-styles' |
898 `use-banding-columns-styles' |
899 `use-first-row-styles'
900 ON-OR-OFF := `t' | `nil'
902 For example, with the following configuration
904 \(setq org-e-odt-table-styles
905 '\(\(\"TableWithHeaderRowsAndColumns\" \"Custom\"
906 \(\(use-first-row-styles . t\)
907 \(use-first-column-styles . t\)\)\)
908 \(\"TableWithHeaderColumns\" \"Custom\"
909 \(\(use-first-column-styles . t\)\)\)\)\)
911 1. A table associated with \"TableWithHeaderRowsAndColumns\"
912 style will use the following table-cell styles -
913 \"CustomFirstRowTableCell\", \"CustomFirstColumnTableCell\",
914 \"CustomTableCell\" and the following paragraph styles
915 \"CustomFirstRowTableParagraph\",
916 \"CustomFirstColumnTableParagraph\", \"CustomTableParagraph\"
919 2. A table associated with \"TableWithHeaderColumns\" style will
920 use the following table-cell styles -
921 \"CustomFirstColumnTableCell\", \"CustomTableCell\" and the
922 following paragraph styles
923 \"CustomFirstColumnTableParagraph\", \"CustomTableParagraph\"
926 Note that TABLE-TEMPLATE-NAME corresponds to the
927 \"<table:table-template>\" elements contained within
928 \"<office:styles>\". The entries (TABLE-STYLE-NAME
929 TABLE-TEMPLATE-NAME TABLE-CELL-OPTIONS) correspond to
930 \"table:template-name\" and \"table:use-first-row-styles\" etc
931 attributes of \"<table:table>\" element. Refer ODF-1.2
932 specification for more information. Also consult the
933 implementation filed under `org-e-odt-get-table-cell-styles'.
935 The TABLE-STYLE-NAME \"OrgEquation\" is used internally for
936 formatting of numbered display equations. Do not delete this
937 style from the list."
938 :group
'org-export-e-odt
941 (const :tag
"None" nil
)
942 (repeat :tag
"Table Styles"
943 (list :tag
"Table Style Specification"
944 (string :tag
"Table Style Name")
945 (string :tag
"Table Template Name")
946 (alist :options
(use-first-row-styles
948 use-first-column-styles
949 use-last-column-styles
950 use-banding-rows-styles
951 use-banding-columns-styles
)
953 :value-type
(const :tag
"True" t
))))))
957 ;;; Internal functions
961 (defun org-e-odt--date (&optional org-ts fmt
)
964 (and (stringp org-ts
)
965 (string-match org-ts-regexp0 org-ts
)
967 (org-fix-decoded-time
968 (org-parse-time-string (match-string 0 org-ts
) t
)))))
971 (fmt (format-time-string fmt time
))
972 (t (setq date
(format-time-string "%Y-%m-%dT%H:%M:%S%z" time
))
973 (format "%s:%s" (substring date
0 -
2) (substring date -
2)))))))
977 (defun org-e-odt--frame (text width height style
&optional extra
981 (if width
(format " svg:width=\"%0.2fcm\"" width
) "")
982 (if height
(format " svg:height=\"%0.2fcm\"" height
) "")
984 (format " text:anchor-type=\"%s\"" (or anchor-type
"paragraph")))))
986 "\n<draw:frame draw:style-name=\"%s\"%s>\n%s\n</draw:frame>"
989 (let ((title (get-text-property 0 :title text
))
990 (desc (get-text-property 0 :description text
)))
992 (format "<svg:title>%s</svg:title>"
993 (org-e-odt-encode-plain-text title t
)))
995 (format "<svg:desc>%s</svg:desc>"
996 (org-e-odt-encode-plain-text desc t
)))))))))
1001 (defun org-e-odt--copy-image-file (path)
1002 "Returns the internal name of the file"
1003 (let* ((image-type (file-name-extension path
))
1004 (media-type (format "image/%s" image-type
))
1005 (target-dir "Images/")
1007 (format "%s%04d.%s" target-dir
1008 (incf org-e-odt-embedded-images-count
) image-type
)))
1009 (message "Embedding %s as %s ..."
1010 (substring-no-properties path
) target-file
)
1012 (when (= 1 org-e-odt-embedded-images-count
)
1013 (make-directory (concat org-e-odt-zip-dir target-dir
))
1014 (org-e-odt-create-manifest-file-entry "" target-dir
))
1016 (copy-file path
(concat org-e-odt-zip-dir target-file
) 'overwrite
)
1017 (org-e-odt-create-manifest-file-entry media-type target-file
)
1020 (defun org-e-odt--image-size (file &optional user-width
1021 user-height scale dpi embed-as
)
1022 (let* ((--pixels-to-cms
1023 (function (lambda (pixels dpi
)
1024 (let ((cms-per-inch 2.54)
1025 (inches (/ pixels dpi
)))
1026 (* cms-per-inch inches
)))))
1029 (lambda (size-in-pixels dpi
)
1031 (cons (funcall --pixels-to-cms
(car size-in-pixels
) dpi
)
1032 (funcall --pixels-to-cms
(cdr size-in-pixels
) dpi
))))))
1033 (dpi (or dpi org-e-odt-pixels-per-inch
))
1034 (anchor-type (or embed-as
"paragraph"))
1035 (user-width (and (not scale
) user-width
))
1036 (user-height (and (not scale
) user-height
))
1039 (not (and user-height user-width
))
1042 (and (executable-find "identify")
1043 (let ((size-in-pixels
1044 (let ((dim (shell-command-to-string
1045 (format "identify -format \"%%w:%%h\" \"%s\""
1047 (when (string-match "\\([0-9]+\\):\\([0-9]+\\)" dim
)
1048 (cons (string-to-number (match-string 1 dim
))
1049 (string-to-number (match-string 2 dim
)))))))
1050 (funcall --size-in-cms size-in-pixels dpi
)))
1052 (let ((size-in-pixels
1053 (ignore-errors ; Emacs could be in batch mode
1055 (image-size (create-image file
) 'pixels
))))
1056 (funcall --size-in-cms size-in-pixels dpi
))
1057 ;; Use hard-coded values.
1058 (cdr (assoc-string anchor-type
1059 org-e-odt-default-image-sizes-alist
))
1061 (error "Cannot determine Image size. Aborting ..."))))
1062 (width (car size
)) (height (cdr size
)))
1065 (setq width
(* width scale
) height
(* height scale
)))
1066 ((and user-height user-width
)
1067 (setq width user-width height user-height
))
1069 (setq width
(* user-height
(/ width height
)) height user-height
))
1071 (setq height
(* user-width
(/ height width
)) width user-width
))
1073 ;; ensure that an embedded image fits comfortably within a page
1074 (let ((max-width (car org-e-odt-max-image-size
))
1075 (max-height (cdr org-e-odt-max-image-size
)))
1076 (when (or (> width max-width
) (> height max-height
))
1077 (let* ((scale1 (/ max-width width
))
1078 (scale2 (/ max-height height
))
1079 (scale (min scale1 scale2
)))
1080 (setq width
(* scale width
) height
(* scale height
)))))
1081 (cons width height
)))
1083 (defun org-e-odt-link--inline-image (element info
)
1084 "Return HTML code for an inline image.
1085 LINK is the link pointing to the inline image. INFO is a plist
1086 used as a communication channel."
1088 ((eq (org-element-type element
) 'link
)
1089 (let* ((type (org-element-property :type element
))
1090 (raw-path (org-element-property :path element
)))
1091 (cond ((member type
'("http" "https"))
1092 (concat type
":" raw-path
))
1093 ((file-name-absolute-p raw-path
)
1094 (expand-file-name raw-path
))
1096 ((member (org-element-type element
)
1097 '(latex-fragment latex-environment
))
1098 (let* ((latex-frag (org-remove-indentation
1099 (org-element-property :value element
)))
1100 (formula-link (org-e-odt-format-latex
1101 latex-frag
'dvipng info
)))
1103 (string-match "file:\\([^]]*\\)" formula-link
)
1104 (match-string 1 formula-link
))))
1105 (t (error "what is this?"))))
1106 (src-expanded (if (file-name-absolute-p src
) src
1107 (expand-file-name src
(file-name-directory
1108 (plist-get info
:input-file
)))))
1110 "\n<draw:image xlink:href=\"%s\" xlink:type=\"simple\" xlink:show=\"embed\" xlink:actuate=\"onLoad\"/>"
1111 (org-e-odt--copy-image-file src-expanded
)))
1112 ;; extract attributes from #+ATTR_ODT line.
1113 (attr-from (case (org-element-type element
)
1114 (link (org-export-get-parent-element element
))
1116 ;; convert attributes to a plist.
1117 (attr-plist (org-export-read-attribute :attr_odt attr-from
))
1118 ;; handle `:anchor', `:style' and `:attributes' properties.
1120 (car (assoc-string (plist-get attr-plist
:anchor
)
1121 '(("as-char") ("paragraph") ("page")) t
)))
1123 (and user-frame-anchor
(plist-get attr-plist
:style
)))
1125 (and user-frame-anchor
(plist-get attr-plist
:attributes
)))
1127 (list user-frame-style user-frame-attrs user-frame-anchor
))
1128 ;; (embed-as (or embed-as user-frame-anchor "paragraph"))
1130 ;; handle `:width', `:height' and `:scale' properties.
1131 (size (org-e-odt--image-size
1132 src-expanded
(plist-get attr-plist
:width
)
1133 (plist-get attr-plist
:height
)
1134 (plist-get attr-plist
:scale
) nil
;; embed-as
1137 (width (car size
)) (height (cdr size
))
1139 (case (org-element-type element
)
1140 ((org-e-odt-standalone-image-p element info
) "paragraph")
1141 (latex-fragment "as-char")
1142 (latex-environment "paragraph")
1144 (captions (org-e-odt-format-label element info
'definition
))
1145 (caption (car captions
)) (short-caption (cdr captions
))
1146 (entity (concat (and caption
"Captioned") embed-as
"Image")))
1147 (org-e-odt-format-entity entity href width height
1148 captions user-frame-params
)))
1150 ;;;; Library wrappers
1152 (defun org-e-odt--zip-extract (archive members target
)
1153 (when (atom members
) (setq members
(list members
)))
1154 (mapc (lambda (archive member target
)
1156 (let* ((--quote-file-name
1157 ;; This is shamelessly stolen from `archive-zip-extract'.
1159 (if (or (not (memq system-type
'(windows-nt ms-dos
)))
1160 (and (boundp 'w32-quote-process-args
)
1161 (null w32-quote-process-args
)))
1162 (shell-quote-argument name
)
1164 (target (funcall --quote-file-name target
))
1165 (archive (expand-file-name archive
))
1166 (archive-zip-extract
1167 (list "unzip" "-qq" "-o" "-d" target
))
1168 exit-code command-output
)
1169 (setq command-output
1171 (setq exit-code
(archive-zip-extract archive member
))
1173 (unless (zerop exit-code
)
1174 (message command-output
)
1175 (error "Extraction failed"))))
1181 (defun org-e-odt--target (text id
)
1184 (format "\n<text:bookmark-start text:name=\"OrgXref.%s\"/>" id
)
1185 (format "\n<text:bookmark text:name=\"%s\"/>" id
) text
1186 (format "\n<text:bookmark-end text:name=\"OrgXref.%s\"/>" id
))))
1190 (defun org-e-odt--textbox (text width height style
&optional
1193 (format "\n<draw:text-box %s>%s\n</draw:text-box>"
1194 (concat (format " fo:min-height=\"%0.2fcm\"" (or height
.2))
1196 (format " fo:min-width=\"%0.2fcm\"" (or width
.2))))
1198 width nil style extra anchor-type
))
1202 ;;;; Table of Contents
1204 (defun org-e-odt-begin-toc (index-title depth
)
1207 <text:table-of-content text:style-name=\"Sect2\" text:protected=\"true\" text:name=\"Table of Contents1\">
1208 <text:table-of-content-source text:outline-level=\"%d\">
1209 <text:index-title-template text:style-name=\"Contents_20_Heading\">%s</text:index-title-template>
1210 " depth index-title
)
1212 (let ((levels (number-sequence 1 10)))
1217 <text:table-of-content-entry-template text:outline-level=\"%d\" text:style-name=\"Contents_20_%d\">
1218 <text:index-entry-link-start text:style-name=\"Internet_20_link\"/>
1219 <text:index-entry-chapter/>
1220 <text:index-entry-text/>
1221 <text:index-entry-link-end/>
1222 </text:table-of-content-entry-template>
1223 " level level
)) levels
""))
1226 </text:table-of-content-source>
1229 <text:index-title text:style-name=\"Sect1\" text:name=\"Table of Contents1_Head\">
1230 <text:p text:style-name=\"Contents_20_Heading\">%s</text:p>
1234 (defun org-e-odt-end-toc ()
1237 </text:table-of-content>
1242 (defun* org-e-odt-format-toc-headline
1243 (todo todo-type priority text tags
1244 &key level section-number headline-label
&allow-other-keys
)
1246 (and org-export-with-section-numbers
1247 (concat section-number
". "))
1252 (format "<text:span text:style-name=\"%s\">%s</text:span>"
1255 (setq text
(format "<text:span text:style-name=\"%s\">%s</text:span>"
1257 (format "<text:a xlink:type=\"simple\" xlink:href=\"#%s\">%s</text:a>"
1258 headline-label text
))
1260 (defun org-e-odt-toc (depth info
)
1261 (assert (wholenump depth
))
1262 (let* ((title (org-export-translate "Table of Contents" :utf-8 info
))
1263 (headlines (org-export-collect-headlines
1264 info
(and (wholenump depth
) depth
))))
1267 (org-e-odt-begin-toc title depth
)
1270 (let* ((entry (org-e-odt-format-headline--wrap
1271 headline info
'org-e-odt-format-toc-headline
))
1272 (level (org-export-get-relative-level headline info
))
1273 (style (format "Contents_20_%d" level
)))
1274 (format "\n<text:p text:style-name=\"%s\">%s</text:p>"
1277 (org-e-odt-end-toc)))))
1280 ;;;; Document styles
1282 (defun org-e-odt-add-automatic-style (object-type &optional object-props
)
1283 "Create an automatic style of type OBJECT-TYPE with param OBJECT-PROPS.
1284 OBJECT-PROPS is (typically) a plist created by passing
1285 \"#+ATTR_ODT: \" option of the object in question to
1286 `org-e-odt-parse-block-attributes'.
1288 Use `org-e-odt-object-counters' to generate an automatic
1289 OBJECT-NAME and STYLE-NAME. If OBJECT-PROPS is non-nil, add a
1290 new entry in `org-e-odt-automatic-styles'. Return (OBJECT-NAME
1292 (assert (stringp object-type
))
1293 (let* ((object (intern object-type
))
1295 (seqno (1+ (or (plist-get org-e-odt-object-counters seqvar
) 0)))
1296 (object-name (format "%s%d" object-type seqno
)) style-name
)
1297 (setq org-e-odt-object-counters
1298 (plist-put org-e-odt-object-counters seqvar seqno
))
1300 (setq style-name
(format "Org%s" object-name
))
1301 (setq org-e-odt-automatic-styles
1302 (plist-put org-e-odt-automatic-styles object
1303 (append (list (list style-name object-props
))
1304 (plist-get org-e-odt-automatic-styles object
)))))
1305 (cons object-name style-name
)))
1308 ;;;; Caption and Labels
1311 (defun org-e-odt--wrap-label (element output
)
1312 "Wrap label associated to ELEMENT around OUTPUT, if appropriate.
1313 This function shouldn't be used for floats. See
1314 `org-e-odt--caption/label-string'."
1315 ;; (let ((label (org-element-property :name element)))
1316 ;; (if (or (not output) (not label) (string= output "") (string= label ""))
1318 ;; (concat (format "\\label{%s}\n" label) output)))
1322 (defun org-e-odt--caption/label-string
(caption label info
)
1323 "Return caption and label HTML string for floats.
1325 CAPTION is a cons cell of secondary strings, the car being the
1326 standard caption and the cdr its short form. LABEL is a string
1327 representing the label. INFO is a plist holding contextual
1330 If there's no caption nor label, return the empty string.
1332 For non-floats, see `org-e-odt--wrap-label'."
1333 (setq label nil
) ;; FIXME
1335 (let ((label-str (if label
(format "\\label{%s}" label
) "")))
1337 ((and (not caption
) (not label
)) "")
1338 ((not caption
) (format "\\label{%s}\n" label
))
1339 ;; Option caption format with short name.
1341 (format "\\caption[%s]{%s%s}\n"
1342 (org-export-data (cdr caption
) info
)
1344 (org-export-data (car caption
) info
)))
1345 ;; Standard caption format.
1346 ;; (t (format "\\caption{%s%s}\n"
1348 ;; (org-export-data (car caption) info)))
1349 (t (org-export-data (car caption
) info
)))))
1353 (defun org-e-odt--checkbox (item)
1354 "Return check-box string associated to ITEM."
1355 (let ((checkbox (org-element-property :checkbox item
)))
1356 (if (not checkbox
) ""
1357 (format "<text:span text:style-name=\"%s\">%s</text:span>"
1358 "OrgCode" (case checkbox
1359 (on "[✓] ") ; CHECK MARK
1365 (defun org-e-odt-template (contents info
)
1366 "Return complete document string after HTML conversion.
1367 CONTENTS is the transcoded contents string. RAW-DATA is the
1368 original parsed data. INFO is a plist holding export options."
1370 (let ((title (org-export-data (plist-get info
:title
) info
))
1371 (author (let ((author (plist-get info
:author
)))
1372 (if (not author
) "" (org-export-data author info
))))
1373 (date (org-e-odt--date
1374 (org-export-data (plist-get info
:date
) info
)))
1375 (email (plist-get info
:email
))
1376 (keywords (plist-get info
:keywords
))
1377 (description (plist-get info
:description
)))
1380 "<?xml version=\"1.0\" encoding=\"UTF-8\"?>
1381 <office:document-meta
1382 xmlns:office=\"urn:oasis:names:tc:opendocument:xmlns:office:1.0\"
1383 xmlns:xlink=\"http://www.w3.org/1999/xlink\"
1384 xmlns:dc=\"http://purl.org/dc/elements/1.1/\"
1385 xmlns:meta=\"urn:oasis:names:tc:opendocument:xmlns:meta:1.0\"
1386 xmlns:ooo=\"http://openoffice.org/2004/office\"
1387 office:version=\"1.2\">
1389 (format "<dc:creator>%s</dc:creator>\n" author
)
1390 (format "<meta:initial-creator>%s</meta:initial-creator>\n" author
)
1391 (format "<dc:date>%s</dc:date>\n" date
)
1392 (format "<meta:creation-date>%s</meta:creation-date>\n" date
)
1393 (format "<meta:generator>%s</meta:generator>\n"
1394 (let ((creator-info (plist-get info
:with-creator
)))
1395 (if (or (not creator-info
) (eq creator-info
'comment
)) ""
1396 (plist-get info
:creator
))))
1397 (format "<meta:keyword>%s</meta:keyword>\n" keywords
)
1398 (format "<dc:subject>%s</dc:subject>\n" description
)
1399 (format "<dc:title>%s</dc:title>\n" title
)
1401 " </office:meta>\n" "</office:document-meta>")
1402 nil
(concat org-e-odt-zip-dir
"meta.xml"))
1403 ;; Add meta.xml in to manifest.
1404 (org-e-odt-create-manifest-file-entry "text/xml" "meta.xml"))
1406 ;; Update styles file.
1407 ;; Copy styles.xml. Also dump htmlfontify styles, if there is any.
1408 ;; Write styles file.
1409 (let* ((styles-file (plist-get info
:odt-styles-file
))
1410 (styles-file (and styles-file
(read (org-trim styles-file
))))
1411 ;; Non-availability of styles.xml is not a critical
1412 ;; error. For now throw an error purely for aesthetic
1414 (styles-file (or styles-file
1415 org-e-odt-styles-file
1416 (expand-file-name "OrgOdtStyles.xml"
1417 org-e-odt-styles-dir
)
1418 (error "org-e-odt: Missing styles file?"))))
1420 ((listp styles-file
)
1421 (let ((archive (nth 0 styles-file
))
1422 (members (nth 1 styles-file
)))
1423 (org-e-odt--zip-extract archive members org-e-odt-zip-dir
)
1426 (when (org-file-image-p member
)
1427 (let* ((image-type (file-name-extension member
))
1428 (media-type (format "image/%s" image-type
)))
1429 (org-e-odt-create-manifest-file-entry media-type member
))))
1431 ((and (stringp styles-file
) (file-exists-p styles-file
))
1432 (let ((styles-file-type (file-name-extension styles-file
)))
1434 ((string= styles-file-type
"xml")
1435 (copy-file styles-file
(concat org-e-odt-zip-dir
"styles.xml") t
))
1436 ((member styles-file-type
'("odt" "ott"))
1437 (org-e-odt--zip-extract styles-file
"styles.xml" org-e-odt-zip-dir
)))))
1439 (error (format "Invalid specification of styles.xml file: %S"
1440 org-e-odt-styles-file
))))
1442 ;; create a manifest entry for styles.xml
1443 (org-e-odt-create-manifest-file-entry "text/xml" "styles.xml")
1445 ;; FIXME: Who is opening an empty styles.xml before this point?
1446 (with-current-buffer
1447 (find-file-noselect (concat org-e-odt-zip-dir
"styles.xml") t
)
1450 ;; Write custom styles for source blocks
1451 ;; Save STYLES used for colorizing of source blocks.
1452 ;; Update styles.xml with styles that were collected as part of
1453 ;; `org-e-odt-hfy-face-to-css' callbacks.
1454 (let ((styles (mapconcat (lambda (style) (format " %s\n" (cddr style
)))
1455 hfy-user-sheet-assoc
"")))
1457 (goto-char (point-min))
1458 (when (re-search-forward "</office:styles>" nil t
)
1459 (goto-char (match-beginning 0))
1460 (insert "\n<!-- Org Htmlfontify Styles -->\n" styles
"\n"))))
1462 ;; Update styles.xml - take care of outline numbering
1464 ;; Don't make automatic backup of styles.xml file. This setting
1465 ;; prevents the backed-up styles.xml file from being zipped in to
1466 ;; odt file. This is more of a hackish fix. Better alternative
1467 ;; would be to fix the zip command so that the output odt file
1468 ;; includes only the needed files and excludes any auto-generated
1469 ;; extra files like backups and auto-saves etc etc. Note that
1470 ;; currently the zip command zips up the entire temp directory so
1471 ;; that any auto-generated files created under the hood ends up in
1472 ;; the resulting odt file.
1473 (set (make-local-variable 'backup-inhibited
) t
)
1475 ;; Outline numbering is retained only upto LEVEL.
1476 ;; To disable outline numbering pass a LEVEL of 0.
1478 (goto-char (point-min))
1480 "<text:outline-level-style\\([^>]*\\)text:level=\"\\([^\"]*\\)\"\\([^>]*\\)>")
1482 "<text:outline-level-style\\1text:level=\"\\2\" style:num-format=\"\">"))
1483 (while (re-search-forward regex nil t
)
1484 (unless (let ((sec-num (plist-get info
:section-numbers
))
1485 (level (string-to-number (match-string 2))))
1486 (if (wholenump sec-num
) (<= level sec-num
) sec-num
))
1487 (replace-match replacement t nil
))))
1489 ;; Update content.xml.
1491 (insert-file-contents
1492 (or org-e-odt-content-template-file
1493 (expand-file-name "OrgOdtContentTemplate.xml"
1494 org-e-odt-styles-dir
)))
1495 ;; Write automatic styles.
1496 ;; - Position the cursor.
1497 (goto-char (point-min))
1498 (re-search-forward " </office:automatic-styles>" nil t
)
1499 (goto-char (match-beginning 0))
1500 ;; - Dump automatic table styles
1501 (loop for
(style-name props
) in
1502 (plist-get org-e-odt-automatic-styles
'Table
) do
1503 (when (setq props
(or (plist-get props
:rel-width
) 96))
1504 (insert (format org-e-odt-table-style-format style-name props
))))
1505 ;; Update display level.
1506 ;; - Remove existing sequence decls. Also position the cursor.
1507 (goto-char (point-min))
1508 (when (re-search-forward "<text:sequence-decls" nil t
)
1509 (delete-region (match-beginning 0)
1510 (re-search-forward "</text:sequence-decls>" nil nil
)))
1511 ;; Update sequence decls according to user preference.
1514 "\n<text:sequence-decls>\n%s\n</text:sequence-decls>"
1518 "<text:sequence-decl text:display-outline-level=\"%d\" text:name=\"%s\"/>"
1519 org-e-odt-display-outline-level
(nth 1 x
)))
1520 org-e-odt-category-map-alist
"\n")))
1521 ;; Position the cursor to document body.
1522 (goto-char (point-min))
1523 (re-search-forward "</office:text>" nil nil
)
1524 (goto-char (match-beginning 0))
1526 ;; Preamble - Title, Author, Date etc.
1528 (let* ((title (org-export-data (plist-get info
:title
) info
))
1529 (author (and (plist-get info
:with-author
)
1530 (let ((auth (plist-get info
:author
)))
1531 (and auth
(org-export-data auth info
)))))
1532 (date (org-export-data (plist-get info
:date
) info
))
1533 (iso-date (org-e-odt--date date
))
1534 (date (org-e-odt--date date
"%d %b %Y"))
1535 (email (plist-get info
:email
))
1536 ;; switch on or off above vars based on user settings
1537 (author (and (plist-get info
:with-author
) (or author email
)))
1538 ;; (date (and (plist-get info :time-stamp-file) date))
1539 (email (and (plist-get info
:with-email
) email
)))
1544 (format "\n<text:p text:style-name=\"%s\">%s</text:p>"
1545 "OrgTitle" (format "\n<text:title>%s</text:title>" title
))
1547 "\n<text:p text:style-name=\"OrgTitle\"/>"))
1549 ((and author
(not email
))
1552 (format "\n<text:p text:style-name=\"%s\">%s</text:p>"
1554 (format "<text:initial-creator>%s</text:initial-creator>" author
))
1556 "\n<text:p text:style-name=\"OrgSubtitle\"/>"))
1561 "\n<text:p text:style-name=\"%s\">%s</text:p>"
1564 "<text:a xlink:type=\"simple\" xlink:href=\"%s\">%s</text:a>"
1565 (concat "mailto:" email
)
1566 (format "<text:initial-creator>%s</text:initial-creator>" author
)))
1568 "\n<text:p text:style-name=\"OrgSubtitle\"/>")))
1573 "\n<text:p text:style-name=\"%s\">%s</text:p>"
1576 "\n<text:date style:data-style-name=\"%s\" text:date-value=\"%s\">%s</text:date>"
1578 "OrgDate" iso-date date
))
1580 "<text:p text:style-name=\"OrgSubtitle\"/>")))))
1581 ;; Table of Contents
1582 (let* ((with-toc (plist-get info
:with-toc
))
1583 (depth (and with-toc
(if (wholenump with-toc
)
1585 (plist-get info
:headline-levels
)))))
1586 (when depth
(insert (or (org-e-odt-toc depth info
) ""))))
1590 (buffer-substring-no-properties (point-min) (point-max))))
1594 ;;; Transcode Functions
1598 (defun org-e-odt-bold (bold contents info
)
1599 "Transcode BOLD from Org to ODT.
1600 CONTENTS is the text with bold markup. INFO is a plist holding
1601 contextual information."
1602 (format "<text:span text:style-name=\"%s\">%s</text:span>"
1608 (defun org-e-odt-center-block (center-block contents info
)
1609 "Transcode a CENTER-BLOCK element from Org to ODT.
1610 CONTENTS holds the contents of the center block. INFO is a plist
1611 holding contextual information."
1612 (org-e-odt--wrap-label center-block contents
))
1617 (defun org-e-odt-clock (clock contents info
)
1618 "Transcode a CLOCK element from Org to ODT.
1619 CONTENTS is nil. INFO is a plist used as a communication
1621 (format "<text:span text:style-name=\"%s\">%s</text:span>"
1622 "OrgTimestampWrapper"
1624 (format "<text:span text:style-name=\"%s\">%s</text:span>"
1625 "OrgTimestampKeyword" org-clock-string
)
1626 (format "<text:span text:style-name=\"%s\">%s</text:span>"
1628 (concat (org-translate-time
1629 (org-element-property :value clock
))
1630 (let ((time (org-element-property :time clock
)))
1631 (and time
(format " (%s)" time
))))))))
1636 (defun org-e-odt-code (code contents info
)
1637 "Transcode a CODE object from Org to ODT.
1638 CONTENTS is nil. INFO is a plist used as a communication
1640 (format "<text:span text:style-name=\"%s\">%s</text:span>"
1641 "OrgCode" (org-element-property :value code
)))
1646 ;; Comments are ignored.
1651 ;; Comment Blocks are ignored.
1656 (defun org-e-odt-drawer (drawer contents info
)
1657 "Transcode a DRAWER element from Org to ODT.
1658 CONTENTS holds the contents of the block. INFO is a plist
1659 holding contextual information."
1660 (let* ((name (org-element-property :drawer-name drawer
))
1661 (output (if (functionp org-e-odt-format-drawer-function
)
1662 (funcall org-e-odt-format-drawer-function
1664 ;; If there's no user defined function: simply
1665 ;; display contents of the drawer.
1667 (org-e-odt--wrap-label drawer output
)))
1672 (defun org-e-odt-dynamic-block (dynamic-block contents info
)
1673 "Transcode a DYNAMIC-BLOCK element from Org to ODT.
1674 CONTENTS holds the contents of the block. INFO is a plist
1675 holding contextual information. See `org-export-data'."
1676 (org-e-odt--wrap-label dynamic-block contents
))
1681 (defun org-e-odt-entity (entity contents info
)
1682 "Transcode an ENTITY object from Org to ODT.
1683 CONTENTS are the definition itself. INFO is a plist holding
1684 contextual information."
1685 ;; (let ((ent (org-element-property :latex entity)))
1686 ;; (if (org-element-property :latex-math-p entity)
1687 ;; (format "$%s$" ent)
1689 (org-element-property :utf-8 entity
))
1694 (defun org-e-odt-example-block (example-block contents info
)
1695 "Transcode a EXAMPLE-BLOCK element from Org to ODT.
1696 CONTENTS is nil. INFO is a plist holding contextual information."
1697 (org-e-odt--wrap-label
1698 example-block
(org-e-odt-format-code example-block info
)))
1703 (defun org-e-odt-export-snippet (export-snippet contents info
)
1704 "Transcode a EXPORT-SNIPPET object from Org to ODT.
1705 CONTENTS is nil. INFO is a plist holding contextual information."
1706 (when (eq (org-export-snippet-backend export-snippet
) 'e-odt
)
1707 (org-element-property :value export-snippet
)))
1712 (defun org-e-odt-export-block (export-block contents info
)
1713 "Transcode a EXPORT-BLOCK element from Org to ODT.
1714 CONTENTS is nil. INFO is a plist holding contextual information."
1715 (when (string= (org-element-property :type export-block
) "ODT")
1716 (org-remove-indentation (org-element-property :value export-block
))))
1721 (defun org-e-odt-fixed-width (fixed-width contents info
)
1722 "Transcode a FIXED-WIDTH element from Org to ODT.
1723 CONTENTS is nil. INFO is a plist holding contextual information."
1724 (org-e-odt--wrap-label
1725 fixed-width
(org-e-odt-do-format-code
1726 (org-element-property :value fixed-width
))))
1729 ;;;; Footnote Definition
1731 ;; Footnote Definitions are ignored.
1734 ;;;; Footnote Reference
1736 (defun org-e-odt-footnote-reference (footnote-reference contents info
)
1737 "Transcode a FOOTNOTE-REFERENCE element from Org to ODT.
1738 CONTENTS is nil. INFO is a plist holding contextual information."
1739 (let ((--format-footnote-definition
1742 (setq n
(format "%d" n
))
1743 (let ((id (concat "fn" n
))
1744 (note-class "footnote")
1745 (par-style "Footnote"))
1747 "<text:note text:id=\"%s\" text:note-class=\"%s\">%s</text:note>"
1750 (format "<text:note-citation>%s</text:note-citation>" n
)
1751 (format "<text:note-body>%s</text:note-body>" def
)))))))
1752 (--format-footnote-reference
1755 (setq n
(format "%d" n
))
1756 (let ((note-class "footnote")
1758 (ref-name (concat "fn" n
)))
1760 "<text:span text:style-name=\"%s\">%s</text:span>"
1762 (format "<text:note-ref text:note-class=\"%s\" text:reference-format=\"%s\" text:ref-name=\"%s\">%s</text:note-ref>"
1763 note-class ref-format ref-name n
)))))))
1765 ;; Insert separator between two footnotes in a row.
1766 (let ((prev (org-export-get-previous-element footnote-reference info
)))
1767 (and (eq (org-element-type prev
) 'footnote-reference
)
1768 (format "<text:span text:style-name=\"%s\">%s</text:span>"
1769 "OrgSuperscript" ",")))
1770 ;; Trancode footnote reference.
1771 (let ((n (org-export-get-footnote-number footnote-reference info
)))
1773 ((not (org-export-footnote-first-reference-p footnote-reference info
))
1774 (funcall --format-footnote-reference n
))
1775 ;; Inline definitions are secondary strings.
1776 ;; Non-inline footnotes definitions are full Org data.
1778 (let* ((raw (org-export-get-footnote-definition footnote-reference
1780 (def (let ((def (org-trim (org-export-data raw info
))))
1781 (if (eq (org-element-type raw
) 'org-data
) def
1782 (format "\n<text:p text:style-name=\"%s\">%s</text:p>"
1784 (funcall --format-footnote-definition n def
))))))))
1789 (defun* org-e-odt-format-headline
1790 (todo todo-type priority text tags
1791 &key level section-number headline-label
&allow-other-keys
)
1796 (let ((style (if (member todo org-done-keywords
) "OrgDone" "OrgTodo")))
1797 (format "<text:span text:style-name=\"%s\">%s</text:span>"
1803 (concat "<text:tab/>"
1804 (format "<text:span text:style-name=\"%s\">%s</text:span>"
1805 "OrgTag" (mapconcat 'org-trim tags
" : "))))))
1807 (defun org-e-odt-format-headline--wrap (headline info
1808 &optional format-function
1810 "Transcode an HEADLINE element from Org to ODT.
1811 CONTENTS holds the contents of the headline. INFO is a plist
1812 holding contextual information."
1813 (let* ((level (+ (org-export-get-relative-level headline info
)))
1814 (headline-number (org-export-get-headline-number headline info
))
1815 (section-number (and (org-export-numbered-headline-p headline info
)
1816 (mapconcat 'number-to-string
1817 headline-number
".")))
1818 (todo (and (plist-get info
:with-todo-keywords
)
1819 (let ((todo (org-element-property :todo-keyword headline
)))
1820 (and todo
(org-export-data todo info
)))))
1821 (todo-type (and todo
(org-element-property :todo-type headline
)))
1822 (priority (and (plist-get info
:with-priority
)
1823 (org-element-property :priority headline
)))
1824 (text (org-export-data (org-element-property :title headline
) info
))
1825 (tags (and (plist-get info
:with-tags
)
1826 (org-export-get-tags headline info
)))
1827 (headline-label (concat "sec-" (mapconcat 'number-to-string
1828 headline-number
"-")))
1829 (format-function (cond
1830 ((functionp format-function
) format-function
)
1831 ((functionp org-e-odt-format-headline-function
)
1833 (lambda (todo todo-type priority text tags
1835 (funcall org-e-odt-format-headline-function
1836 todo todo-type priority text tags
))))
1837 (t 'org-e-odt-format-headline
))))
1838 (apply format-function
1839 todo todo-type priority text tags
1840 :headline-label headline-label
:level level
1841 :section-number section-number extra-keys
)))
1843 (defun org-e-odt-headline (headline contents info
)
1844 "Transcode an HEADLINE element from Org to ODT.
1845 CONTENTS holds the contents of the headline. INFO is a plist
1846 holding contextual information."
1847 ;; Case 1: This is a footnote section: ignore it.
1848 (unless (org-element-property :footnote-section-p headline
)
1849 (let* ((text (org-export-data (org-element-property :title headline
) info
))
1850 ;; Create the headline text.
1851 (full-text (org-e-odt-format-headline--wrap headline info
))
1852 ;; Get level relative to current parsed data.
1853 (level (org-export-get-relative-level headline info
))
1854 ;; Get canonical label for the headline.
1855 (id (concat "sec-" (mapconcat 'number-to-string
1856 (org-export-get-headline-number
1857 headline info
) "-")))
1858 ;; Get user-specified labels for the headline.
1859 (extra-ids (list (org-element-property :custom-id headline
)
1860 (org-element-property :id headline
)))
1863 (mapconcat (lambda (x)
1865 (let ((x (if (org-uuidgen-p x
) (concat "ID-" x
) x
)))
1867 "" (org-export-solidify-link-text x
)))))
1870 (anchored-title (org-e-odt--target full-text id
)))
1872 ;; Case 2. This is a deep sub-tree: export it as a list item.
1873 ;; Also export as items headlines for which no section
1874 ;; format has been found.
1875 ((org-export-low-level-p headline info
)
1876 ;; Build the real contents of the sub-tree.
1878 (and (org-export-first-sibling-p headline info
)
1879 (format "\n<text:list text:style-name=\"%s\" %s>"
1880 ;; Choose style based on list type.
1881 (if (org-export-numbered-headline-p headline info
)
1882 "OrgNumberedList" "OrgBulletedList")
1883 ;; If top-level list, re-start numbering. Otherwise,
1884 ;; continue numbering.
1885 (format "text:continue-numbering=\"%s\""
1886 (let* ((parent (org-export-get-parent-headline
1889 (org-export-low-level-p parent info
))
1891 (let ((headline-has-table-p
1892 (let ((section (assq 'section
(org-element-contents headline
))))
1893 (assq 'table
(and section
(org-element-contents section
))))))
1894 (format "\n<text:list-item>\n%s\n%s"
1896 (format "\n<text:p text:style-name=\"%s\">%s</text:p>"
1898 (concat extra-targets anchored-title
))
1900 (if headline-has-table-p
1901 "</text:list-header>"
1902 "</text:list-item>")))
1903 (and (org-export-last-sibling-p headline info
)
1905 ;; Case 3. Standard headline. Export it as a section.
1909 "\n<text:h text:style-name=\"%s\" text:outline-level=\"%s\">%s</text:h>"
1910 (format "Heading_20_%s" level
)
1912 (concat extra-targets anchored-title
))
1916 ;;;; Horizontal Rule
1918 (defun org-e-odt-horizontal-rule (horizontal-rule contents info
)
1919 "Transcode an HORIZONTAL-RULE object from Org to ODT.
1920 CONTENTS is nil. INFO is a plist holding contextual information."
1921 (org-e-odt--wrap-label
1923 (format "\n<text:p text:style-name=\"%s\">%s</text:p>"
1924 "Horizontal_20_Line" "")))
1927 ;;;; Inline Babel Call
1929 ;; Inline Babel Calls are ignored.
1932 ;;;; Inline Src Block
1934 (defun org-e-odt--find-verb-separator (s)
1935 "Return a character not used in string S.
1936 This is used to choose a separator for constructs like \\verb."
1937 (let ((ll "~,./?;':\"|!@#%^&-_=+abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ<>()[]{}"))
1938 (loop for c across ll
1939 when
(not (string-match (regexp-quote (char-to-string c
)) s
))
1940 return
(char-to-string c
))))
1942 (defun org-e-odt-inline-src-block (inline-src-block contents info
)
1943 "Transcode an INLINE-SRC-BLOCK element from Org to ODT.
1944 CONTENTS holds the contents of the item. INFO is a plist holding
1945 contextual information."
1946 (let* ((org-lang (org-element-property :language inline-src-block
))
1947 (code (org-element-property :value inline-src-block
))
1948 (separator (org-e-odt--find-verb-separator code
)))
1954 (defun org-e-odt-inlinetask (inlinetask contents info
)
1955 "Transcode an INLINETASK element from Org to ODT.
1956 CONTENTS holds the contents of the block. INFO is a plist
1957 holding contextual information."
1959 ;; If `org-e-odt-format-inlinetask-function' is provided, call it
1960 ;; with appropriate arguments.
1961 ((functionp org-e-odt-format-inlinetask-function
)
1962 (let ((format-function
1964 (lambda (todo todo-type priority text tags
1965 &key contents
&allow-other-keys
)
1966 (funcall org-e-odt-format-inlinetask-function
1967 todo todo-type priority text tags contents
)))))
1968 (org-e-odt-format-headline--wrap
1969 inlinetask info format-function
:contents contents
)))
1970 ;; Otherwise, use a default template.
1971 (t (org-e-odt--wrap-label
1973 (format "\n<text:p text:style-name=\"%s\">%s</text:p>"
1977 (format "\n<text:p text:style-name=\"%s\">%s</text:p>"
1978 "OrgInlineTaskHeading"
1979 (org-e-odt-format-headline--wrap
1982 nil nil
"OrgInlineTaskFrame" " style:rel-width=\"100%\""))))))
1986 (defun org-e-odt-italic (italic contents info
)
1987 "Transcode ITALIC from Org to ODT.
1988 CONTENTS is the text with italic markup. INFO is a plist holding
1989 contextual information."
1990 (format "<text:span text:style-name=\"%s\">%s</text:span>"
1991 "Emphasis" contents
))
1996 (defun org-e-odt-item (item contents info
)
1997 "Transcode an ITEM element from Org to ODT.
1998 CONTENTS holds the contents of the item. INFO is a plist holding
1999 contextual information."
2000 (let* ((plain-list (org-export-get-parent item
))
2001 (type (org-element-property :type plain-list
))
2002 (counter (org-element-property :counter item
))
2003 (tag (let ((tag (org-element-property :tag item
)))
2005 (concat (org-e-odt--checkbox item
)
2006 (org-export-data tag info
))))))
2008 ((ordered unordered descriptive-1 descriptive-2
)
2009 (format "\n<text:list-item>\n%s\n%s"
2011 (let* ((--element-has-a-table-p
2013 (lambda (element info
)
2014 (loop for el in
(org-element-contents element
)
2015 thereis
(eq (org-element-type el
) 'table
))))))
2017 ((funcall --element-has-a-table-p item info
)
2018 "</text:list-header>")
2019 (t "</text:list-item>")))))
2020 (t (error "Unknown list type: %S" type
)))))
2024 (defun org-e-odt-keyword (keyword contents info
)
2025 "Transcode a KEYWORD element from Org to ODT.
2026 CONTENTS is nil. INFO is a plist holding contextual information."
2027 (let ((key (org-element-property :key keyword
))
2028 (value (org-element-property :value keyword
)))
2030 ((string= key
"ODT") value
)
2031 ((string= key
"INDEX") (format "\\index{%s}" value
))
2032 ((string= key
"TARGET") nil
; FIXME
2033 ;; (format "\\label{%s}" (org-export-solidify-link-text value))
2035 ((string= key
"toc")
2036 (let ((value (downcase value
)))
2038 ((string-match "\\<headlines\\>" value
)
2039 (let ((depth (or (and (string-match "[0-9]+" value
)
2040 (string-to-number (match-string 0 value
)))
2041 (plist-get info
:with-toc
))))
2042 (when (wholenump depth
) (org-e-odt-toc depth info
))))
2043 ((string= "tables" value
) "FIXME")
2044 ((string= "figures" value
) "FIXME")
2045 ((string= "listings" value
)
2047 ;; At the moment, src blocks with a caption are wrapped
2048 ;; into a figure environment.
2052 ;;;; Latex Environment
2055 (eval-after-load 'org-odt
2056 '(ad-deactivate 'org-format-latex-as-mathml
))
2058 ;; (defadvice org-format-latex-as-mathml ; FIXME
2059 ;; (after org-e-odt-protect-latex-fragment activate)
2060 ;; "Encode LaTeX fragment as XML.
2061 ;; Do this when translation to MathML fails."
2062 ;; (when (or (not (> (length ad-return-value) 0))
2063 ;; (get-text-property 0 'org-protected ad-return-value))
2064 ;; (setq ad-return-value
2065 ;; (org-propertize (org-e-odt-encode-plain-text (ad-get-arg 0))
2066 ;; 'org-protected t))))
2068 (defun org-e-odt-format-latex (latex-frag processing-type info
)
2069 (let* ((prefix (case processing-type
2071 (mathml "ltxmathml/")))
2072 (input-file (plist-get info
:input-file
))
2074 (concat prefix
(file-name-sans-extension
2075 (file-name-nondirectory input-file
))))
2076 (cache-dir (file-name-directory input-file
))
2077 (display-msg (case processing-type
2078 (dvipng "Creating LaTeX Image...")
2079 (mathml "Creating MathML snippet..."))))
2082 (org-format-latex cache-subdir cache-dir nil display-msg
2083 nil nil processing-type
)
2086 (defun org-e-odt-latex-environment (latex-environment contents info
)
2087 "Transcode a LATEX-ENVIRONMENT element from Org to ODT.
2088 CONTENTS is nil. INFO is a plist holding contextual information."
2089 (org-e-odt--wrap-label
2092 (org-remove-indentation
2093 (org-element-property :value latex-environment
)))
2094 (processing-type (plist-get info
:LaTeX-fragments
))
2095 (caption (org-element-property :caption latex-environment
))
2096 (short-caption (and (cdr caption
)
2097 (org-export-data (cdr caption
) info
)))
2098 (caption (and (car caption
) (org-export-data (car caption
) info
)))
2099 (label (org-element-property :name latex-environment
))
2101 (label (org-element-property :name latex-environment
)))
2103 (when (memq processing-type
'(t mathjax
))
2104 (unless (and (fboundp 'org-format-latex-mathml-available-p
)
2105 (org-format-latex-mathml-available-p))
2106 (message "LaTeX to MathML converter not available. Trying dvinpng...")
2107 (setq processing-type
'dvipng
)))
2109 (when (eq processing-type
'dvipng
)
2110 (unless (and (org-check-external-command "latex" "" t
)
2111 (org-check-external-command "dvipng" "" t
))
2112 (message "LaTeX to PNG converter not available. Using verbatim.")
2113 (setq processing-type
'verbatim
)))
2115 (case processing-type
2117 (org-e-odt-format-formula latex-environment info
))
2119 (format "\n<text:p text:style-name=\"%s\">%s</text:p>"
2121 (org-e-odt-link--inline-image latex-environment info
)))
2122 (t (org-e-odt-do-format-code latex-frag
))))))
2128 ;; (when latex-frag ; FIXME
2129 ;; (setq href (org-propertize href :title "LaTeX Fragment"
2130 ;; :description latex-frag)))
2132 ;; provide descriptions
2134 (defun org-e-odt-latex-fragment (latex-fragment contents info
)
2135 "Transcode a LATEX-FRAGMENT object from Org to ODT.
2136 CONTENTS is nil. INFO is a plist holding contextual information."
2137 (let* ((latex-frag (org-element-property :value latex-fragment
))
2138 (processing-type (plist-get info
:LaTeX-fragments
)))
2140 ((member processing-type
'(t mathjax
))
2141 (org-e-odt-format-formula latex-fragment info
))
2142 ((eq processing-type
'dvipng
)
2143 (org-e-odt-link--inline-image latex-fragment info
))
2144 (t (org-e-odt-encode-plain-text latex-frag t
)))))
2149 (defun org-e-odt-line-break (line-break contents info
)
2150 "Transcode a LINE-BREAK object from Org to ODT.
2151 CONTENTS is nil. INFO is a plist holding contextual information."
2152 "<text:line-break/>\n")
2159 ;;;; Links :: Generic
2161 ;; (org-lparse-link-description-is-image
2162 ;; (format "\n<draw:a xlink:type=\"simple\" xlink:href=\"%s\">\n%s\n</draw:a>"
2165 ;;;; Links :: Label references
2167 (defun org-e-odt-enumerate-element (element info
&optional predicate n
)
2168 (let* ((--numbered-parent-headline-at-<=-n
2170 (lambda (element n info
)
2171 (loop for x in
(org-export-get-genealogy element
)
2172 thereis
(and (eq (org-element-type x
) 'headline
)
2173 (<= (org-export-get-relative-level x info
) n
)
2174 (org-export-numbered-headline-p x info
)
2178 (lambda (element scope info
&optional predicate
)
2181 (or scope
(plist-get info
:parse-tree
))
2182 (org-element-type element
)
2184 (and (or (not predicate
) (funcall predicate el info
))
2188 info
'first-match
)))))
2189 (scope (funcall --numbered-parent-headline-at-
<=-n
2190 element
(or n org-e-odt-display-outline-level
) info
))
2191 (ordinal (funcall --enumerate element scope info predicate
))
2196 (mapconcat 'number-to-string
2197 (org-export-get-headline-number scope info
) "."))
2201 (number-to-string ordinal
))))
2204 (defun org-e-odt-format-label (element info op
)
2205 (let* ((caption-from
2206 (case (org-element-type element
)
2207 (link (org-export-get-parent-element element
))
2209 ;; get label and caption.
2210 (label (org-element-property :name caption-from
))
2211 (caption (org-element-property :caption caption-from
))
2212 (short-caption (cdr caption
))
2213 ;; transcode captions.
2214 (caption (and (car caption
) (org-export-data (car caption
) info
)))
2215 (short-caption (and short-caption
2216 (org-export-data short-caption info
))))
2217 (when (or label caption
)
2218 (let* ((default-category
2220 ((eq (org-element-type element
) 'table
)
2222 ((org-e-odt-standalone-image-p element info
)
2224 ((member (org-element-type element
)
2225 '(latex-environment latex-fragment
))
2226 (let ((processing-type (plist-get info
:LaTeX-fragments
)))
2228 ((eq processing-type
'dvipng
) "__DvipngImage__")
2229 ((eq processing-type
'mathjax
) "__MathFormula__")
2230 ((eq processing-type
't
) "__MathFormula__")
2231 (t (error "Handle LaTeX:verbatim")))))
2232 ((eq (org-element-type element
) 'src-block
)
2234 (t (error "Handle enumeration of %S" element
))))
2237 ((member (org-element-type element
)
2238 '(table latex-environment src-block
))
2240 ((org-e-odt-standalone-image-p element info
)
2241 'org-e-odt-standalone-image-p
)
2242 (t (error "Handle enumeration of %S" element
))))
2243 (seqno (org-e-odt-enumerate-element
2244 element info predicate
)) ; FIXME
2245 ;; handle label props.
2246 (label-props (assoc default-category org-e-odt-category-map-alist
))
2247 ;; identify opendocument counter
2248 (counter (nth 1 label-props
))
2249 ;; identify label style
2250 (label-style (nth 2 label-props
))
2251 ;; retrieve localized category sting
2252 (category (org-export-translate (nth 3 label-props
) :utf-8 info
)))
2255 ;; assign an internal label, if user has not provided one
2256 (setq label
(or label
(format "%s-%s" default-category seqno
)))
2257 (setq label
(org-export-solidify-link-text label
))
2261 (cadr (assoc-string label-style org-e-odt-label-styles t
))
2264 "<text:sequence text:ref-name=\"%s\" text:name=\"%s\" text:formula=\"ooow:%s+1\" style:num-format=\"1\">%s</text:sequence>"
2265 label counter counter seqno
))
2266 (?c .
,(or caption
""))))
2270 (setq label
(org-export-solidify-link-text label
))
2271 (let* ((fmt (cddr (assoc-string label-style org-e-odt-label-styles t
)))
2274 (format "<text:sequence-ref text:reference-format=\"%s\" text:ref-name=\"%s\">%s</text:sequence-ref>"
2275 fmt1 label
(format-spec fmt2
`((?e .
,category
)
2277 (t (error "Unknow %S on label" op
)))))))
2279 ;;;; Links :: Math formula
2281 (defun org-e-odt-format-formula (element info
)
2283 ((eq (org-element-type element
) 'link
) ; FIXME
2284 (let* ((type (org-element-property :type element
))
2285 (raw-path (org-element-property :path element
)))
2287 ((file-name-absolute-p raw-path
)
2288 (expand-file-name raw-path
))
2290 ((member (org-element-type element
)
2291 '(latex-fragment latex-environment
))
2292 (let* ((latex-frag (org-remove-indentation
2293 (org-element-property :value element
)))
2294 (formula-link (org-e-odt-format-latex
2295 latex-frag
'mathml info
)))
2297 (string-match "file:\\([^]]*\\)" formula-link
)
2298 (match-string 1 formula-link
))))
2299 (t (error "what is this?"))))
2300 (full-src (if (file-name-absolute-p src
) src
2301 (expand-file-name src
(file-name-directory
2302 (plist-get info
:input-file
)))))
2304 (case (org-element-type element
)
2305 (link (org-export-get-parent-element element
))
2307 (captions (org-e-odt-format-label caption-from info
'definition
))
2308 (caption (car captions
))
2310 (format "\n<draw:object %s xlink:href=\"%s\" xlink:type=\"simple\"/>"
2311 " xlink:show=\"embed\" xlink:actuate=\"onLoad\""
2312 (file-name-directory (org-e-odt-copy-formula-file full-src
))))
2313 (embed-as (if caption
'paragraph
'character
))
2316 ((eq embed-as
'character
)
2317 (org-e-odt-format-entity "InlineFormula" href width height
))
2319 (let* ((equation (org-e-odt-format-entity
2320 "CaptionedDisplayFormula" href width height captions
))
2322 (let* ((org-e-odt-category-map-alist
2323 '(("__Table__" "Table" "value")
2324 ("__Figure__" "Illustration" "value")
2325 ("__MathFormula__" "Text" "math-label")
2326 ("__DvipngImage__" "Equation" "value")
2327 ("__Listing__" "Listing" "value"))))
2328 (car (org-e-odt-format-label caption-from info
'definition
))))
2330 (org-element-adopt-elements
2331 (list 'table
'(:type org
:attr_odt
(":style \"OrgEquation\"")))
2332 (org-element-adopt-elements
2333 (list 'table-row
'(:type standard
))
2334 (list 'table-cell nil
"<c8>") (list 'table-cell nil
"<c1>"))
2335 (org-element-adopt-elements
2336 (list 'table-row
'(:type standard
))
2337 (org-element-adopt-elements
2338 (list 'table-cell nil
)
2339 (list 'export-block
(list :type
"ODT" :value equation
)))
2340 (org-element-adopt-elements
2341 (list 'table-cell nil
)
2342 (list 'export-block
(list :type
"ODT" :value label
))))))
2344 (org-export-collect-tree-properties
2345 formula-tree
(org-export-get-environment 'e-odt
))))
2346 (org-export-data formula-tree formula-info
))))))
2348 (defun org-e-odt-copy-formula-file (src-file)
2349 "Returns the internal name of the file"
2350 (let* ((target-dir (format "Formula-%04d/"
2351 (incf org-e-odt-embedded-formulas-count
)))
2352 (target-file (concat target-dir
"content.xml")))
2353 ;; Create a directory for holding formula file. Also enter it in
2355 (make-directory (concat org-e-odt-zip-dir target-dir
))
2356 (org-e-odt-create-manifest-file-entry
2357 "application/vnd.oasis.opendocument.formula" target-dir
"1.2")
2358 ;; Copy over the formula file from user directory to zip
2360 (message "Embedding %s as %s ..." src-file target-file
)
2361 (let ((case-fold-search nil
))
2364 ((string-match "\\.\\(mathml\\|mml\\)\\'" src-file
)
2365 (copy-file src-file
(concat org-e-odt-zip-dir target-file
) 'overwrite
))
2366 ;; Case 2: OpenDocument formula.
2367 ((string-match "\\.odf\\'" src-file
)
2368 (org-e-odt--zip-extract src-file
"content.xml"
2369 (concat org-e-odt-zip-dir target-dir
)))
2370 (t (error "%s is not a formula file" src-file
))))
2371 ;; Enter the formula file in to manifest.
2372 (org-e-odt-create-manifest-file-entry "text/xml" target-file
)
2377 (defun org-e-odt-format-entity (entity href width height
&optional
2378 captions user-frame-params
)
2379 (let* ((caption (car captions
)) (short-caption (cdr captions
))
2380 (entity-style (assoc-string entity org-e-odt-entity-frame-styles t
))
2381 default-frame-params frame-params
2382 (--merge-frame-params
2384 (lambda (default-frame-params user-frame-params
)
2385 (if (not user-frame-params
) default-frame-params
2386 (assert (= (length default-frame-params
) 3))
2387 (assert (= (length user-frame-params
) 3))
2388 (loop for user-frame-param in user-frame-params
2389 for default-frame-param in default-frame-params
2390 collect
(or user-frame-param default-frame-param
)))))))
2393 (setq default-frame-params
(nth 2 entity-style
))
2394 (setq frame-params
(funcall --merge-frame-params
2395 default-frame-params user-frame-params
))
2396 (apply 'org-e-odt--frame href width height frame-params
))
2398 (setq default-frame-params
(nth 3 entity-style
))
2399 (setq frame-params
(funcall --merge-frame-params
2400 default-frame-params user-frame-params
))
2401 (apply 'org-e-odt--textbox
2402 (format "\n<text:p text:style-name=\"%s\">%s</text:p>"
2405 (apply 'org-e-odt--frame href width height
2406 (let ((entity-style-1 (copy-sequence
2407 (nth 2 entity-style
))))
2408 (setcar (cdr entity-style-1
)
2410 (cadr entity-style-1
)
2412 (format " draw:name=\"%s\" "
2416 width height frame-params
)))))
2418 (defun org-e-odt-standalone-image-p (element info
)
2419 "Test if ELEMENT is a standalone image for the purpose ODT export.
2420 INFO is a plist holding contextual information.
2422 Return non-nil, if ELEMENT is of type paragraph and it's sole
2423 content, save for whitespaces, is a link that qualifies as an
2426 Return non-nil, if ELEMENT is of type link and it's containing
2427 paragraph has no other content save for leading and trailing
2430 Return nil, otherwise.
2432 Bind `org-e-odt-standalone-image-predicate' to constrain
2433 paragraph further. For example, to check for only captioned
2434 standalone images, do the following.
2436 \(setq org-e-odt-standalone-image-predicate
2437 \(lambda \(paragraph\)
2438 \(org-element-property :caption paragraph\)\)\)
2440 (let ((--standalone-image-predicate
2441 (function (lambda (paragraph)
2442 (or (org-element-property :caption paragraph
)
2443 (org-element-property :name paragraph
)))))
2444 (paragraph (case (org-element-type element
)
2446 (link (and (org-export-inline-image-p
2447 element org-e-odt-inline-image-rules
)
2448 (org-export-get-parent element
)))
2451 (assert (eq (org-element-type paragraph
) 'paragraph
))
2452 (when (funcall --standalone-image-predicate paragraph
)
2453 (let ((contents (org-element-contents paragraph
)))
2454 (loop for x in contents
2455 with inline-image-count
= 0
2457 ((eq (org-element-type x
) 'plain-text
)
2458 (not (org-string-nw-p x
)))
2459 ((eq (org-element-type x
) 'link
)
2460 (when (org-export-inline-image-p
2461 x org-e-odt-inline-image-rules
)
2462 (= (incf inline-image-count
) 1)))
2466 (defun org-e-odt-get-previous-elements (blob info
)
2467 (let ((parent (org-export-get-parent blob
)))
2468 (cdr (memq blob
(reverse (org-element-contents parent
))))))
2470 (defun org-e-odt-resolve-numbered-paragraph (element info
)
2471 (when (eq (org-element-type element
) 'item
)
2472 (let ((el element
) ordinal
)
2473 (while (eq (org-element-type el
) 'item
)
2474 (push (1+ (length (org-e-odt-get-previous-elements el info
))) ordinal
)
2475 (setq el
(org-export-get-parent (org-export-get-parent el
))))
2479 (defun org-e-odt-link (link desc info
)
2480 "Transcode a LINK object from Org to ODT.
2482 DESC is the description part of the link, or the empty string.
2483 INFO is a plist holding contextual information. See
2485 (let* ((type (org-element-property :type link
))
2486 (raw-path (org-element-property :path link
))
2487 ;; Ensure DESC really exists, or set it to nil.
2488 (desc (and (not (string= desc
"")) desc
))
2489 (imagep (org-export-inline-image-p
2490 link org-e-odt-inline-image-rules
))
2492 ((member type
'("http" "https" "ftp" "mailto"))
2493 (concat type
":" raw-path
))
2494 ((string= type
"file")
2495 (if (file-name-absolute-p raw-path
)
2496 (concat "file://" (expand-file-name raw-path
))
2497 (concat "file://" raw-path
)))
2502 ((and (not desc
) (org-export-inline-image-p
2503 link org-e-odt-inline-image-rules
))
2504 (org-e-odt-link--inline-image link info
))
2505 ;; Radio target: Transcode target's contents and use them as
2506 ;; link's description.
2507 ((string= type
"radio")
2508 (let ((destination (org-export-resolve-radio-link link info
)))
2510 (let ((desc (org-export-data (org-element-contents destination
) info
))
2511 (href (org-export-solidify-link-text path
)))
2513 "<text:bookmark-ref text:reference-format=\"text\" text:ref-name=\"OrgXref.%s\">%s</text:bookmark-ref>"
2515 ;; Links pointing to an headline: Find destination and build
2516 ;; appropriate referencing command.
2517 ((member type
'("custom-id" "fuzzy" "id"))
2518 (let ((destination (if (string= type
"fuzzy")
2519 (org-export-resolve-fuzzy-link link info
)
2520 (org-export-resolve-id-link link info
))))
2521 (case (org-element-type destination
)
2522 ;; Fuzzy link points nowhere.
2524 (format "<text:span text:style-name=\"%s\">%s</text:span>"
2525 "Emphasis" (or desc
(org-export-data
2526 (org-element-property
2527 :raw-link link
) info
))))
2528 ;; Fuzzy link points to an invisible target.
2530 ;; LINK points to an headline. Check if LINK should display
2533 (let* ((headline-no (org-export-get-headline-number destination info
))
2534 (label (format "sec-%s" (mapconcat 'number-to-string
2537 ;; Case 1: Headline is numbered and LINK has no
2538 ;; description or LINK's description matches headline's
2539 ;; title. Display section number.
2540 ((and (org-export-numbered-headline-p destination info
)
2541 (or (not desc
) (string= desc
(org-element-property
2542 :raw-value destination
))))
2544 "<text:bookmark-ref text:reference-format=\"chapter\" text:ref-name=\"OrgXref.%s\">%s</text:bookmark-ref>"
2545 label
(mapconcat 'number-to-string headline-no
".")))
2546 ;; Case 2: Either the headline is un-numbered or
2547 ;; LINK has a custom description. Display LINK's
2548 ;; description or headline's title.
2550 (let ((desc (or desc
(org-export-data
2551 (org-element-property :title destination
)
2554 "<text:bookmark-ref text:reference-format=\"text\" text:ref-name=\"OrgXref.%s\">%s</text:bookmark-ref>"
2556 ;; Fuzzy link points to a target. Do as above.
2558 ;; Identify nearest meaningful container
2560 (loop for parent in
(org-export-get-genealogy destination
)
2563 (org-element-type parent
)
2564 '(footnote-definition footnote-reference headline item
2567 ;; There is a meaningful container
2569 (case (org-element-type container
)
2570 ;; Container is item
2573 "<text:bookmark-ref text:reference-format=\"number-all-superior\" text:ref-name=\"OrgXref.%s\">%s</text:bookmark-ref>"
2574 (org-solidify-link-text path
)
2576 (mapconcat 'number-to-string
2577 (org-e-odt-resolve-numbered-paragraph
2578 container info
) ".")))))))
2581 ;; (setq number (cond
2582 ;; ((org-e-odt-standalone-image-p destination info)
2583 ;; (org-export-get-ordinal
2584 ;; (assoc 'link (org-element-contents destination))
2585 ;; info 'link 'org-e-odt-standalone-image-p))
2586 ;; (t (org-export-get-ordinal destination info))))
2587 ;; (setq desc (when number
2588 ;; (if (atom number) (number-to-string number)
2589 ;; (mapconcat 'number-to-string number ".")))))
2591 (let ((label-reference
2592 (org-e-odt-format-label destination info
'reference
)))
2593 (assert label-reference
)
2594 label-reference
)))))
2595 ;; Coderef: replace link with the reference name or the
2596 ;; equivalent line number.
2597 ((string= type
"coderef")
2598 (let* ((line-no (format "%d" (org-export-resolve-coderef path info
)))
2599 (href (concat "coderef-" path
)))
2601 (org-export-get-coderef-format path desc
)
2603 "<text:bookmark-ref text:reference-format=\"number\" text:ref-name=\"OrgXref.%s\">%s</text:bookmark-ref>"
2605 ;; Link type is handled by a special function.
2606 ((functionp (setq protocol
(nth 2 (assoc type org-link-protocols
))))
2607 (funcall protocol
(org-link-unescape path
) desc
'odt
))
2608 ;; External link with a description part.
2610 (format "<text:a xlink:type=\"simple\" xlink:href=\"%s\">%s</text:a>"
2612 ;; External link without a description part.
2614 (format "<text:a xlink:type=\"simple\" xlink:href=\"%s\">%s</text:a>"
2616 ;; No path, only description. Try to do something useful.
2617 (t (format "<text:span text:style-name=\"%s\">%s</text:span>"
2618 "Emphasis" desc
)))))
2623 (defun org-e-odt-paragraph (paragraph contents info
)
2624 "Transcode a PARAGRAPH element from Org to ODT.
2625 CONTENTS is the contents of the paragraph, as a string. INFO is
2626 the plist used as a communication channel."
2627 (let* ((parent (org-export-get-parent paragraph
))
2628 (parent-type (org-element-type parent
))
2629 (style (case parent-type
2630 (quote-block "Quotations")
2631 (center-block "OrgCenter")
2632 (footnote-definition "Footnote")
2633 (t (or (org-element-property :style paragraph
)
2635 ;; If this paragraph is a leading paragraph in an item and the
2636 ;; item has a checkbox, splice the checkbox and paragraph contents
2638 (when (and (eq (org-element-type parent
) 'item
)
2639 (eq paragraph
(car (org-element-contents parent
))))
2640 (setq contents
(concat (org-e-odt--checkbox parent
) contents
)))
2642 (format "\n<text:p text:style-name=\"%s\">%s</text:p>" style contents
)))
2647 (defun org-e-odt-plain-list (plain-list contents info
)
2648 "Transcode a PLAIN-LIST element from Org to ODT.
2649 CONTENTS is the contents of the list. INFO is a plist holding
2650 contextual information."
2651 (org-e-odt--wrap-label
2653 (format "\n<text:list text:style-name=\"%s\" %s>\n%s</text:list>"
2654 ;; Choose style based on list type.
2655 (case (org-element-property :type plain-list
)
2656 (ordered "OrgNumberedList")
2657 (unordered "OrgBulletedList")
2658 (descriptive-1 "OrgDescriptionList")
2659 (descriptive-2 "OrgDescriptionList"))
2660 ;; If top-level list, re-start numbering. Otherwise,
2661 ;; continue numbering.
2662 (format "text:continue-numbering=\"%s\""
2663 (let* ((parent (org-export-get-parent plain-list
)))
2664 (if (and parent
(eq (org-element-type parent
) 'item
))
2670 (defun org-e-odt-fill-tabs-and-spaces (line)
2671 (replace-regexp-in-string
2672 "\\([\t]\\|\\([ ]+\\)\\)"
2675 ((string= s
"\t") "<text:tab/>")
2676 (t (let ((n (length s
)))
2679 ((> n
1) (concat " " (format "<text:s text:c=\"%d\"/>" (1- n
))))
2683 (defun org-e-odt-encode-plain-text (text &optional no-whitespace-filling
)
2686 (setq text
(replace-regexp-in-string (car pair
) (cdr pair
) text t t
)))
2687 '(("&" .
"&") ("<" .
"<") (">" .
">")))
2688 (if no-whitespace-filling text
2689 (org-e-odt-fill-tabs-and-spaces text
)))
2691 (defun org-e-odt--quotation-marks (text info
)
2692 "Export quotation marks depending on language conventions.
2693 TEXT is a string containing quotation marks to be replaced. INFO
2694 is a plist used as a communication channel."
2697 (while (setq start
(string-match (car l
) text start
))
2698 (let ((new-quote (concat (match-string 1 text
) (cdr l
))))
2699 (setq text
(replace-match new-quote t t text
))))))
2700 (cdr (or (assoc (plist-get info
:language
) org-e-odt-quotes
)
2701 ;; Falls back on English.
2702 (assoc "en" org-e-odt-quotes
))))
2705 (defun org-e-odt-plain-text (text info
)
2706 "Transcode a TEXT string from Org to ODT.
2707 TEXT is the string to transcode. INFO is a plist holding
2708 contextual information."
2709 ;; Protect &, < and >.
2710 (setq text
(org-e-odt-encode-plain-text text t
))
2711 ;; Handle quotation marks
2712 (setq text
(org-e-odt--quotation-marks text info
))
2713 ;; Convert special strings.
2714 (when (plist-get info
:with-special-strings
)
2717 (setq text
(replace-regexp-in-string (car pair
) (cdr pair
) text t nil
)))
2718 org-e-odt-special-string-regexps
))
2719 ;; Handle break preservation if required.
2720 (when (plist-get info
:preserve-breaks
)
2721 (setq text
(replace-regexp-in-string
2722 "\\(\\\\\\\\\\)?[ \t]*\n" "<text:line-break/>\n" text t
)))
2729 (defun org-e-odt-planning (planning contents info
)
2730 "Transcode a PLANNING element from Org to ODT.
2731 CONTENTS is nil. INFO is a plist used as a communication
2733 (format "<text:span text:style-name=\"%s\">%s</text:span>"
2734 "OrgTimestampWrapper"
2736 (let ((closed (org-element-property :closed planning
)))
2739 (format "<text:span text:style-name=\"%s\">%s</text:span>"
2740 "OrgTimestampKeyword" org-closed-string
)
2741 (format "<text:span text:style-name=\"%s\">%s</text:span>"
2742 "OrgTimestamp" (org-translate-time closed
)))))
2743 (let ((deadline (org-element-property :deadline planning
)))
2746 (format "<text:span text:style-name=\"%s\">%s</text:span>"
2747 "OrgTimestampKeyword" org-deadline-string
)
2748 (format "<text:span text:style-name=\"%s\">%s</text:span>"
2749 "OrgTimestamp" (org-translate-time deadline
)))))
2750 (let ((scheduled (org-element-property :scheduled planning
)))
2753 (format "<text:span text:style-name=\"%s\">%s</text:span>"
2754 "OrgTimestampKeyword" org-scheduled-string
)
2755 (format "<text:span text:style-name=\"%s\">%s</text:span>"
2756 "OrgTimestamp" (org-translate-time scheduled
))))))))
2759 ;;;; Property Drawer
2761 (defun org-e-odt-property-drawer (property-drawer contents info
)
2762 "Transcode a PROPERTY-DRAWER element from Org to ODT.
2763 CONTENTS is nil. INFO is a plist holding contextual
2765 ;; The property drawer isn't exported but we want separating blank
2766 ;; lines nonetheless.
2772 (defun org-e-odt-quote-block (quote-block contents info
)
2773 "Transcode a QUOTE-BLOCK element from Org to ODT.
2774 CONTENTS holds the contents of the block. INFO is a plist
2775 holding contextual information."
2776 (org-e-odt--wrap-label quote-block contents
))
2781 (defun org-e-odt-quote-section (quote-section contents info
)
2782 "Transcode a QUOTE-SECTION element from Org to ODT.
2783 CONTENTS is nil. INFO is a plist holding contextual information."
2784 (let ((value (org-remove-indentation
2785 (org-element-property :value quote-section
))))
2786 (when value
(org-e-odt-do-format-code value
))))
2791 (defun org-e-odt-format-section (text style
&optional name
)
2792 (let ((default-name (car (org-e-odt-add-automatic-style "Section"))))
2793 (format "\n<text:section text:style-name=\"%s\" %s>\n%s\n</text:section>"
2795 (format "text:name=\"%s\"" (or name default-name
))
2799 (defun org-e-odt-section (section contents info
) ; FIXME
2800 "Transcode a SECTION element from Org to ODT.
2801 CONTENTS holds the contents of the section. INFO is a plist
2802 holding contextual information."
2807 (defun org-e-odt-radio-target (radio-target text info
)
2808 "Transcode a RADIO-TARGET object from Org to ODT.
2809 TEXT is the text of the target. INFO is a plist holding
2810 contextual information."
2812 text
(org-export-solidify-link-text
2813 (org-element-property :value radio-target
))))
2818 (defun org-e-odt-special-block (special-block contents info
)
2819 "Transcode a SPECIAL-BLOCK element from Org to ODT.
2820 CONTENTS holds the contents of the block. INFO is a plist
2821 holding contextual information."
2822 (let ((type (downcase (org-element-property :type special-block
)))
2823 (attributes (org-export-read-attribute :attr_odt special-block
)))
2824 (org-e-odt--wrap-label
2828 ((string= type
"annotation")
2829 (let ((author (or (plist-get attributes
:author
)
2830 (let ((author (plist-get info
:author
)))
2831 (and author
(org-export-data author info
)))))
2832 (date (or (plist-get attributes
:date
)
2833 (plist-get info
:date
))))
2835 (format "\n<text:p text:style-name=\"%s\">%s</text:p>"
2837 (format "<office:annotation>\n%s\n</office:annotation>"
2840 (format "<dc:creator>%s</dc:creator>" author
))
2842 (format "<dc:date>%s</dc:date>"
2843 (org-e-odt--date date
)))
2846 ((string= type
"textbox")
2847 (let ((width (plist-get attributes
:width
))
2848 (height (plist-get attributes
:height
))
2849 (style (plist-get attributes
:style
))
2850 (extra (plist-get attributes
:extra
))
2851 (anchor (plist-get attributes
:anchor
)))
2852 (format "\n<text:p text:style-name=\"%s\">%s</text:p>"
2853 "Text_20_body" (org-e-odt--textbox contents width height
2854 style extra anchor
))))
2860 (defun org-e-odt-hfy-face-to-css (fn)
2861 "Create custom style for face FN.
2862 When FN is the default face, use it's foreground and background
2863 properties to create \"OrgSrcBlock\" paragraph style. Otherwise
2864 use it's color attribute to create a character style whose name
2865 is obtained from FN. Currently all attributes of FN other than
2868 The style name for a face FN is derived using the following
2869 operations on the face name in that order - de-dash, CamelCase
2870 and prefix with \"OrgSrc\". For example,
2871 `font-lock-function-name-face' is associated with
2872 \"OrgSrcFontLockFunctionNameFace\"."
2873 (let* ((css-list (hfy-face-to-style fn
))
2874 (style-name ((lambda (fn)
2877 'capitalize
(split-string
2878 (hfy-face-or-def-to-name fn
) "-")
2880 (color-val (cdr (assoc "color" css-list
)))
2881 (background-color-val (cdr (assoc "background" css-list
)))
2882 (style (and org-e-odt-create-custom-styles-for-srcblocks
2885 (format org-e-odt-src-block-paragraph-format
2886 background-color-val color-val
))
2890 <style:style style:name=\"%s\" style:family=\"text\">
2891 <style:text-properties fo:color=\"%s\"/>
2892 </style:style>" style-name color-val
))))))
2893 (cons style-name style
)))
2895 (defun org-e-odt-htmlfontify-string (line)
2896 (let* ((hfy-html-quote-regex "\\([<\"&> ]\\)")
2897 (hfy-html-quote-map '(("\"" """)
2902 (" " "<text:tab/>")))
2903 (hfy-face-to-css 'org-e-odt-hfy-face-to-css
)
2904 (hfy-optimisations-1 (copy-sequence hfy-optimisations
))
2905 (hfy-optimisations (add-to-list 'hfy-optimisations-1
2907 (hfy-begin-span-handler
2908 (lambda (style text-block text-id text-begins-block-p
)
2909 (insert (format "<text:span text:style-name=\"%s\">" style
))))
2910 (hfy-end-span-handler (lambda nil
(insert "</text:span>"))))
2911 (with-no-warnings (htmlfontify-string line
))))
2913 (defun org-e-odt-do-format-code
2914 (code &optional lang refs retain-labels num-start
)
2915 (let* ((lang (or (assoc-default lang org-src-lang-modes
) lang
))
2916 (lang-mode (and lang
(intern (format "%s-mode" lang
))))
2917 (code-lines (org-split-string code
"\n"))
2918 (code-length (length code-lines
))
2919 (use-htmlfontify-p (and (functionp lang-mode
)
2920 org-e-odt-fontify-srcblocks
2921 (require 'htmlfontify nil t
)
2922 (fboundp 'htmlfontify-string
)))
2923 (code (if (not use-htmlfontify-p
) code
2927 (font-lock-fontify-buffer)
2929 (fontifier (if use-htmlfontify-p
'org-e-odt-htmlfontify-string
2930 'org-e-odt-encode-plain-text
))
2931 (par-style (if use-htmlfontify-p
"OrgSrcBlock"
2932 "OrgFixedWidthBlock"))
2934 (assert (= code-length
(length (org-split-string code
"\n"))))
2936 (org-export-format-code
2938 (lambda (loc line-num ref
)
2940 (concat par-style
(and (= (incf i
) code-length
) "LastLine")))
2942 (setq loc
(concat loc
(and ref retain-labels
(format " (%s)" ref
))))
2943 (setq loc
(funcall fontifier loc
))
2945 (setq loc
(org-e-odt--target loc
(concat "coderef-" ref
))))
2947 (setq loc
(format "\n<text:p text:style-name=\"%s\">%s</text:p>"
2949 (if (not line-num
) loc
2950 (format "\n<text:list-item>%s\n</text:list-item>" loc
)))
2953 ((not num-start
) code
)
2956 "\n<text:list text:style-name=\"OrgSrcBlockNumberedLine\"%s>%s</text:list>"
2957 " text:continue-numbering=\"false\"" code
))
2960 "\n<text:list text:style-name=\"OrgSrcBlockNumberedLine\"%s>%s</text:list>"
2961 " text:continue-numbering=\"true\"" code
)))))
2963 (defun org-e-odt-format-code (element info
)
2964 (let* ((lang (org-element-property :language element
))
2965 ;; Extract code and references.
2966 (code-info (org-export-unravel-code element
))
2967 (code (car code-info
))
2968 (refs (cdr code-info
))
2969 ;; Does the src block contain labels?
2970 (retain-labels (org-element-property :retain-labels element
))
2971 ;; Does it have line numbers?
2972 (num-start (case (org-element-property :number-lines element
)
2973 (continued (org-export-get-loc element info
))
2975 (org-e-odt-do-format-code code lang refs retain-labels num-start
)))
2977 (defun org-e-odt-src-block (src-block contents info
)
2978 "Transcode a SRC-BLOCK element from Org to ODT.
2979 CONTENTS holds the contents of the item. INFO is a plist holding
2980 contextual information."
2981 (let* ((lang (org-element-property :language src-block
))
2982 (caption (org-element-property :caption src-block
))
2983 (short-caption (and (cdr caption
)
2984 (org-export-data (cdr caption
) info
)))
2985 (caption (and (car caption
) (org-export-data (car caption
) info
)))
2986 (label (org-element-property :name src-block
))
2987 (attributes (org-export-read-attribute :attr_odt src-block
)))
2988 ;; FIXME: Handle caption
2989 ;; caption-str (when caption)
2990 ;; (main (org-export-data (car caption) info))
2991 ;; (secondary (org-export-data (cdr caption) info))
2992 ;; (caption-str (org-e-odt--caption/label-string caption label info))
2993 (let* ((captions (org-e-odt-format-label src-block info
'definition
))
2994 (caption (car captions
)) (short-caption (cdr captions
)))
2997 (format "\n<text:p text:style-name=\"%s\">%s</text:p>"
2999 (let ((--src-block (org-e-odt-format-code src-block info
)))
3000 (if (not (plist-get attributes
:textbox
)) --src-block
3001 (format "\n<text:p text:style-name=\"%s\">%s</text:p>"
3003 (org-e-odt--textbox --src-block nil nil nil
))))))))
3006 ;;;; Statistics Cookie
3008 (defun org-e-odt-statistics-cookie (statistics-cookie contents info
)
3009 "Transcode a STATISTICS-COOKIE object from Org to ODT.
3010 CONTENTS is nil. INFO is a plist holding contextual information."
3011 (let ((cookie-value (org-element-property :value statistics-cookie
)))
3012 (format "<text:span text:style-name=\"%s\">%s</text:span>"
3013 "OrgCode" cookie-value
)))
3018 (defun org-e-odt-strike-through (strike-through contents info
)
3019 "Transcode STRIKE-THROUGH from Org to ODT.
3020 CONTENTS is the text with strike-through markup. INFO is a plist
3021 holding contextual information."
3022 (format "<text:span text:style-name=\"%s\">%s</text:span>"
3023 "Strikethrough" contents
))
3028 (defun org-e-odt-subscript (subscript contents info
)
3029 "Transcode a SUBSCRIPT object from Org to ODT.
3030 CONTENTS is the contents of the object. INFO is a plist holding
3031 contextual information."
3032 (format "<text:span text:style-name=\"%s\">%s</text:span>"
3033 "OrgSubscript" contents
))
3038 (defun org-e-odt-superscript (superscript contents info
)
3039 "Transcode a SUPERSCRIPT object from Org to ODT.
3040 CONTENTS is the contents of the object. INFO is a plist holding
3041 contextual information."
3042 (format "<text:span text:style-name=\"%s\">%s</text:span>"
3043 "OrgSuperscript" contents
))
3048 (defun org-e-odt-table-style-spec (element info
)
3049 (let* ((table (org-export-get-parent-table element
))
3050 (table-attributes (org-export-read-attribute :attr_odt table
))
3051 (table-style (plist-get table-attributes
:style
)))
3052 (assoc table-style org-e-odt-table-styles
)))
3054 (defun org-e-odt-get-table-cell-styles (table-cell info
)
3055 "Retrieve styles applicable to a table cell.
3056 R and C are (zero-based) row and column numbers of the table
3057 cell. STYLE-SPEC is an entry in `org-e-odt-table-styles'
3058 applicable to the current table. It is `nil' if the table is not
3059 associated with any style attributes.
3061 Return a cons of (TABLE-CELL-STYLE-NAME . PARAGRAPH-STYLE-NAME).
3063 When STYLE-SPEC is nil, style the table cell the conventional way
3064 - choose cell borders based on row and column groupings and
3065 choose paragraph alignment based on `org-col-cookies' text
3067 `org-e-odt-get-paragraph-style-cookie-for-table-cell'.
3069 When STYLE-SPEC is non-nil, ignore the above cookie and return
3070 styles congruent with the ODF-1.2 specification."
3071 (let* ((table-cell-address (org-export-table-cell-address table-cell info
))
3072 (r (car table-cell-address
)) (c (cdr table-cell-address
))
3073 (style-spec (org-e-odt-table-style-spec table-cell info
))
3074 (table-dimensions (org-export-table-dimensions
3075 (org-export-get-parent-table table-cell
)
3078 ;; LibreOffice - particularly the Writer - honors neither table
3079 ;; templates nor custom table-cell styles. Inorder to retain
3080 ;; inter-operability with LibreOffice, only automatic styles are
3081 ;; used for styling of table-cells. The current implementation is
3082 ;; congruent with ODF-1.2 specification and hence is
3083 ;; future-compatible.
3085 ;; Additional Note: LibreOffice's AutoFormat facility for tables -
3086 ;; which recognizes as many as 16 different cell types - is much
3087 ;; richer. Unfortunately it is NOT amenable to easy configuration
3089 (let* ((template-name (nth 1 style-spec
))
3090 (cell-style-selectors (nth 2 style-spec
))
3093 ((and (cdr (assoc 'use-first-column-styles cell-style-selectors
))
3094 (= c
0)) "FirstColumn")
3095 ((and (cdr (assoc 'use-last-column-styles cell-style-selectors
))
3096 (= (1+ c
) (cdr table-dimensions
)))
3098 ((and (cdr (assoc 'use-first-row-styles cell-style-selectors
))
3099 (= r
0)) "FirstRow")
3100 ((and (cdr (assoc 'use-last-row-styles cell-style-selectors
))
3101 (= (1+ r
) (car table-dimensions
)))
3103 ((and (cdr (assoc 'use-banding-rows-styles cell-style-selectors
))
3104 (= (% r
2) 1)) "EvenRow")
3105 ((and (cdr (assoc 'use-banding-rows-styles cell-style-selectors
))
3106 (= (% r
2) 0)) "OddRow")
3107 ((and (cdr (assoc 'use-banding-columns-styles cell-style-selectors
))
3108 (= (% c
2) 1)) "EvenColumn")
3109 ((and (cdr (assoc 'use-banding-columns-styles cell-style-selectors
))
3110 (= (% c
2) 0)) "OddColumn")
3112 (concat template-name cell-type
)))))
3114 (defun org-e-odt-table-cell (table-cell contents info
)
3115 "Transcode a TABLE-CELL element from Org to ODT.
3116 CONTENTS is nil. INFO is a plist used as a communication
3118 (let* ((table-cell-address (org-export-table-cell-address table-cell info
))
3119 (r (car table-cell-address
))
3120 (c (cdr table-cell-address
))
3121 (horiz-span (or (org-export-table-cell-width table-cell info
) 0))
3122 (table-row (org-export-get-parent table-cell
))
3123 (custom-style-prefix (org-e-odt-get-table-cell-styles
3127 (and custom-style-prefix
3128 (format "%sTableParagraph" custom-style-prefix
))
3131 ((and (= 1 (org-export-table-row-group table-row info
))
3132 (org-export-table-has-header-p
3133 (org-export-get-parent-table table-row
) info
))
3135 ((let* ((table (org-export-get-parent-table table-cell
))
3136 (table-attrs (org-export-read-attribute :attr_odt table
))
3137 (table-header-columns (plist-get table-attrs
3139 (<= c
(cond ((wholenump table-header-columns
)
3140 (- table-header-columns
1))
3141 (table-header-columns 0)
3144 (t "OrgTableContents"))
3145 (capitalize (symbol-name (org-export-table-cell-alignment
3146 table-cell info
))))))
3149 (and custom-style-prefix
(format "%sTableCell"
3150 custom-style-prefix
))
3153 (when (or (org-export-table-row-starts-rowgroup-p table-row info
)
3155 (when (org-export-table-row-ends-rowgroup-p table-row info
) "B")
3156 (when (and (org-export-table-cell-starts-colgroup-p table-cell info
)
3157 (not (zerop c
)) ) "L"))))
3160 (format " table:style-name=\"%s\"" cell-style-name
)
3161 (and (> horiz-span
0)
3162 (format " table:number-columns-spanned=\"%d\""
3163 (1+ horiz-span
))))))
3164 (unless contents
(setq contents
""))
3166 (assert paragraph-style
)
3167 (format "\n<table:table-cell%s>\n%s\n</table:table-cell>"
3169 (let ((table-cell-contents (org-element-contents table-cell
)))
3170 (if (memq (org-element-type (car table-cell-contents
))
3171 org-element-all-elements
)
3173 (format "\n<text:p text:style-name=\"%s\">%s</text:p>"
3174 paragraph-style contents
))))
3176 (dotimes (i horiz-span s
)
3177 (setq s
(concat s
"\n<table:covered-table-cell/>"))))
3183 (defun org-e-odt-table-row (table-row contents info
)
3184 "Transcode a TABLE-ROW element from Org to ODT.
3185 CONTENTS is the contents of the row. INFO is a plist used as a
3186 communication channel."
3187 ;; Rules are ignored since table separators are deduced from
3188 ;; borders of the current row.
3189 (when (eq (org-element-property :type table-row
) 'standard
)
3190 (let* ((rowgroup-tags
3191 (if (and (= 1 (org-export-table-row-group table-row info
))
3192 (org-export-table-has-header-p
3193 (org-export-get-parent-table table-row
) info
))
3194 ;; If the row belongs to the first rowgroup and the
3195 ;; table has more than one row groups, then this row
3196 ;; belongs to the header row group.
3197 '("\n<table:table-header-rows>" .
"\n</table:table-header-rows>")
3198 ;; Otherwise, it belongs to non-header row group.
3199 '("\n<table:table-rows>" .
"\n</table:table-rows>"))))
3201 ;; Does this row begin a rowgroup?
3202 (when (org-export-table-row-starts-rowgroup-p table-row info
)
3203 (car rowgroup-tags
))
3205 (format "\n<table:table-row>\n%s\n</table:table-row>" contents
)
3206 ;; Does this row end a rowgroup?
3207 (when (org-export-table-row-ends-rowgroup-p table-row info
)
3208 (cdr rowgroup-tags
))))))
3213 (defun org-e-odt-table-first-row-data-cells (table info
)
3218 (unless (eq (org-element-property :type row
) 'rule
) row
))
3220 (special-column-p (org-export-table-has-special-column-p table
)))
3221 (if (not special-column-p
) (org-element-contents table-row
)
3222 (cdr (org-element-contents table-row
)))))
3224 (defun org-e-odt--table (table contents info
)
3225 "Transcode a TABLE element from Org to ODT.
3226 CONTENTS is the contents of the table. INFO is a plist holding
3227 contextual information."
3228 (case (org-element-property :type table
)
3229 ;; Case 1: table.el doesn't support export to OD format. Strip
3230 ;; such tables from export.
3235 "(org-e-odt): Found table.el-type table in the source Org file."
3236 " table.el doesn't support export to ODT format."
3237 " Stripping the table from export."))))
3238 ;; Case 2: Native Org tables.
3240 (let* ((captions (org-e-odt-format-label table info
'definition
))
3241 (caption (car captions
)) (short-caption (cdr captions
))
3242 (attributes (org-export-read-attribute :attr_odt table
))
3243 (custom-table-style (nth 1 (org-e-odt-table-style-spec table info
)))
3246 (lambda (table info
)
3247 (let* ((table-style (or custom-table-style
"OrgTable"))
3248 (column-style (format "%sColumn" table-style
)))
3250 (lambda (table-cell)
3251 (let ((width (1+ (or (org-export-table-cell-width
3252 table-cell info
) 0)))
3254 "\n<table:table-column table:style-name=\"%s\"/>"
3257 (dotimes (i width out
) (setq out
(concat s out
)))))
3258 (org-e-odt-table-first-row-data-cells table info
) "\n"))))))
3262 (format "\n<text:p text:style-name=\"%s\">%s</text:p>"
3265 (let* ((automatic-name
3266 (org-e-odt-add-automatic-style "Table" attributes
)))
3268 "\n<table:table table:name=\"%s\" table:style-name=\"%s\">"
3269 (or short-caption
(car automatic-name
))
3270 (or custom-table-style
(cdr automatic-name
) "OrgTable")))
3271 ;; column specification.
3272 (funcall table-column-specs table info
)
3276 "</table:table>")))))
3278 (defun org-e-odt-table (table contents info
)
3279 "Transcode a TABLE element from Org to ODT.
3280 CONTENTS is the contents of the table. INFO is a plist holding
3281 contextual information.
3283 Use `org-e-odt--table' to typeset the table. Handle details
3284 pertaining to indentation here."
3285 (let* ((--get-previous-elements
3288 (let ((parent (org-export-get-parent blob
)))
3289 (cdr (memq blob
(reverse (org-element-contents parent
))))))))
3290 (--element-preceded-by-table-p
3292 (lambda (element info
)
3293 (loop for el in
(funcall --get-previous-elements element info
)
3294 thereis
(eq (org-element-type el
) 'table
)))))
3295 (--walk-list-genealogy-and-collect-tags
3297 (lambda (table info
)
3298 (let* ((genealogy (org-export-get-genealogy table
))
3300 (when (eq (org-element-type (car genealogy
)) 'item
)
3301 (loop for el in genealogy
3302 when
(memq (org-element-type el
)
3307 (loop for el in genealogy
3308 when
(and (eq (org-element-type el
) 'headline
)
3309 (org-export-low-level-p el info
))
3313 (org-element-contents
3314 (org-export-get-parent el
)))))))
3317 ;; Handle list genealogy.
3318 (loop for el in list-genealogy collect
3319 (case (org-element-type el
)
3321 (setq parent-list el
)
3322 (cons "</text:list>"
3323 (format "\n<text:list text:style-name=\"%s\" %s>"
3324 (case (org-element-property :type el
)
3325 (ordered "OrgNumberedList")
3326 (unordered "OrgBulletedList")
3327 (descriptive-1 "OrgDescriptionList")
3328 (descriptive-2 "OrgDescriptionList"))
3329 "text:continue-numbering=\"true\"")))
3333 (if (funcall --element-preceded-by-table-p table info
)
3334 '("</text:list-header>" .
"<text:list-header>")
3335 '("</text:list-item>" .
"<text:list-header>")))
3336 ((funcall --element-preceded-by-table-p
3338 '("</text:list-header>" .
"<text:list-header>"))
3339 (t '("</text:list-item>" .
"<text:list-item>"))))))
3340 ;; Handle low-level headlines.
3341 (loop for el in llh-genealogy
3342 with step
= 'item collect
3345 (setq step
'item
) ; Flip-flop
3346 (setq parent-list el
)
3347 (cons "</text:list>"
3348 (format "\n<text:list text:style-name=\"%s\" %s>"
3349 (if (org-export-numbered-headline-p
3353 "text:continue-numbering=\"true\"")))
3355 (setq step
'plain-list
) ; Flip-flop
3358 (if (funcall --element-preceded-by-table-p table info
)
3359 '("</text:list-header>" .
"<text:list-header>")
3360 '("</text:list-item>" .
"<text:list-header>")))
3361 ((let ((section?
(org-export-get-previous-element
3364 (eq (org-element-type section?
) 'section
)
3365 (assq 'table
(org-element-contents section?
))))
3366 '("</text:list-header>" .
"<text:list-header>"))
3368 '("</text:list-item>" .
"<text:list-item>")))))))))))
3369 (close-open-tags (funcall --walk-list-genealogy-and-collect-tags
3371 ;; OpenDocument schema does not permit table to occur within a
3374 ;; One solution - the easiest and lightweight, in terms of
3375 ;; implementation - is to put the table in an indented text box
3376 ;; and make the text box part of the list-item. Unfortunately if
3377 ;; the table is big and spans multiple pages, the text box could
3378 ;; overflow. In this case, the following attribute will come
3381 ;; ,---- From OpenDocument-v1.1.pdf
3382 ;; | 15.27.28 Overflow behavior
3384 ;; | For text boxes contained within text document, the
3385 ;; | style:overflow-behavior property specifies the behavior of text
3386 ;; | boxes where the containing text does not fit into the text
3389 ;; | If the attribute's value is clip, the text that does not fit
3390 ;; | into the text box is not displayed.
3392 ;; | If the attribute value is auto-create-new-frame, a new frame
3393 ;; | will be created on the next page, with the same position and
3394 ;; | dimensions of the original frame.
3396 ;; | If the style:overflow-behavior property's value is
3397 ;; | auto-create-new-frame and the text box has a minimum width or
3398 ;; | height specified, then the text box will grow until the page
3399 ;; | bounds are reached before a new frame is created.
3402 ;; Unfortunately, LibreOffice-3.4.6 doesn't honor
3403 ;; auto-create-new-frame property and always resorts to clipping
3404 ;; the text box. This results in table being truncated.
3406 ;; So we solve the problem the hard (and fun) way using list
3409 ;; The problem only becomes more interesting if you take in to
3410 ;; account the following facts:
3412 ;; - Description lists are simulated as plain lists.
3413 ;; - Low-level headlines can be listified.
3414 ;; - In Org-mode, a table can occur not only as a regular list
3415 ;; item, but also within description lists and low-level
3418 ;; See `org-e-odt-translate-description-lists' and
3419 ;; `org-e-odt-translate-low-level-headlines' for how this is
3423 ;; Discontinue the list.
3424 (mapconcat 'car close-open-tags
"\n")
3425 ;; Put the table in an indented section.
3426 (let* ((table (org-e-odt--table table contents info
))
3427 (level (/ (length (mapcar 'car close-open-tags
)) 2))
3428 (style (format "OrgIndentedSection-Level-%d" level
)))
3429 (when table
(org-e-odt-format-section table style
)))
3430 ;; Continue the list.
3431 (mapconcat 'cdr
(nreverse close-open-tags
) "\n"))))
3436 (defun org-e-odt-target (target contents info
)
3437 "Transcode a TARGET object from Org to ODT.
3438 CONTENTS is nil. INFO is a plist holding contextual
3440 (let ((value (org-element-property :value target
)))
3441 (org-e-odt--target "" (org-export-solidify-link-text value
))))
3446 (defun org-e-odt-timestamp (timestamp contents info
)
3447 "Transcode a TIMESTAMP object from Org to ODT.
3448 CONTENTS is nil. INFO is a plist used as a communication
3450 (let ((timestamp-1 (org-element-property :value timestamp
))
3451 (timestamp-2 (org-element-property :range-end timestamp
)))
3452 (format "<text:span text:style-name=\"%s\">%s</text:span>"
3453 "OrgTimestampWrapper"
3455 (format "<text:span text:style-name=\"%s\">%s</text:span>"
3456 "OrgTimestamp" (org-translate-time timestamp-1
))
3459 (format "<text:span text:style-name=\"%s\">%s</text:span>"
3460 "OrgTimestamp" (org-translate-time timestamp-2
)))))))
3465 (defun org-e-odt-underline (underline contents info
)
3466 "Transcode UNDERLINE from Org to ODT.
3467 CONTENTS is the text with underline markup. INFO is a plist
3468 holding contextual information."
3469 (format "<text:span text:style-name=\"%s\">%s</text:span>"
3470 "Underline" contents
))
3475 (defun org-e-odt-verbatim (verbatim contents info
)
3476 "Transcode a VERBATIM object from Org to ODT.
3477 CONTENTS is nil. INFO is a plist used as a communication
3479 (format "<text:span text:style-name=\"%s\">%s</text:span>"
3480 "OrgCode" (org-element-property :value verbatim
)))
3485 (defun org-e-odt-verse-block (verse-block contents info
)
3486 "Transcode a VERSE-BLOCK element from Org to ODT.
3487 CONTENTS is verse block contents. INFO is a plist holding
3488 contextual information."
3489 ;; Add line breaks to each line of verse.
3490 (setq contents
(replace-regexp-in-string
3491 "\\(<text:line-break/>\\)?[ \t]*\n"
3492 "<text:line-break/>" contents
))
3493 ;; Replace tabs and spaces.
3494 (setq contents
(org-e-odt-fill-tabs-and-spaces contents
))
3495 ;; Surround it in a verse environment.
3496 (org-e-odt--wrap-label
3498 (format "\n<text:p text:style-name=\"%s\">%s</text:p>"
3499 "OrgVerse" contents
)))
3505 ;;;; Description lists
3507 ;; This translator is necessary to handle indented tables in a uniform
3508 ;; manner. See comment in `org-e-odt--table'.
3510 (defun org-e-odt--translate-description-lists (tree backend info
)
3511 ;; OpenDocument has no notion of a description list. So simulate it
3512 ;; using plain lists. Description lists in the exported document
3513 ;; are typeset in the same manner as they are in a typical HTML
3516 ;; Specifically, a description list like this:
3519 ;; | - term-1 :: definition-1
3520 ;; | - term-2 :: definition-2
3523 ;; gets translated in to the following form:
3532 ;; Further effect is achieved by fixing the OD styles as below:
3534 ;; 1. Set the :type property of the simulated lists to
3535 ;; `descriptive-1' and `descriptive-2'. Map these to list-styles
3536 ;; that has *no* bullets whatsoever.
3538 ;; 2. The paragraph containing the definition term is styled to be
3544 (when (equal (org-element-property :type el
) 'descriptive
)
3545 (org-element-set-element
3547 (apply 'org-element-adopt-elements
3548 (list 'plain-list
(list :type
'descriptive-1
))
3551 (org-element-adopt-elements
3552 (list 'item
(list :checkbox
(org-element-property
3554 (list 'paragraph
(list :style
"Text_20_body_20_bold")
3555 (or (org-element-property :tag item
) "(no term)"))
3556 (org-element-adopt-elements
3557 (list 'plain-list
(list :type
'descriptive-2
))
3558 (apply 'org-element-adopt-elements
3560 (org-element-contents item
)))))
3561 (org-element-contents el
)))))
3568 ;; Lists that are marked with attribute `:list-table' are called as
3569 ;; list tables. They will be rendered as a table within the exported
3572 ;; Consider an example. The following list table
3574 ;; #+attr_odt :list-table t
3584 ;; will be exported as though it were an Org table like the one show
3587 ;; | Row 1 | 1.1 | 1.2 | 1.3 |
3588 ;; | Row 2 | 2.1 | 2.2 | 2.3 |
3590 ;; Note that org-tables are NOT multi-line and each line is mapped to
3591 ;; a unique row in the exported document. So if an exported table
3592 ;; needs to contain a single paragraph (with copious text) it needs to
3593 ;; be typed up in a single line. Editing such long lines using the
3594 ;; table editor will be a cumbersome task. Furthermore inclusion of
3595 ;; multi-paragraph text in a table cell is well-nigh impossible.
3597 ;; A LIST-TABLE circumvents above problems.
3599 ;; Note that in the example above the list items could be paragraphs
3600 ;; themselves and the list can be arbitrarily deep.
3602 ;; Inspired by following thread:
3603 ;; https://lists.gnu.org/archive/html/emacs-orgmode/2011-03/msg01101.html
3605 ;; Translate lists to tables
3607 (defun org-e-odt--translate-list-tables (tree backend info
)
3611 (when (org-export-read-attribute :attr_odt l1-list
:list-table
)
3612 ;; Replace list with table.
3613 (org-element-set-element
3615 ;; Build replacement table.
3616 (apply 'org-element-adopt-elements
3617 (list 'table
'(:type org
:attr_odt
(":style \"GriddedTable\"")))
3622 (let* ((l1-item-contents (org-element-contents l1-item
))
3623 l1-item-leading-text l2-list
)
3624 ;; Remove Level-2 list from the Level-item. It
3625 ;; will be subsequently attached as table-cells.
3626 (let ((cur l1-item-contents
) prev
)
3627 (while (and cur
(not (eq (org-element-type (car cur
))
3630 (setq cur
(cdr cur
)))
3633 (setq l2-list
(car cur
)))
3634 (setq l1-item-leading-text l1-item-contents
))
3635 ;; Level-1 items start a table row.
3636 (apply 'org-element-adopt-elements
3637 (list 'table-row
(list :type
'standard
))
3638 ;; Leading text of level-1 item define the
3639 ;; first table-cell.
3640 (apply 'org-element-adopt-elements
3641 (list 'table-cell nil
)
3642 l1-item-leading-text
)
3643 ;; Level-2 items define subsequent
3644 ;; table-cells of the row.
3649 (apply 'org-element-adopt-elements
3650 (list 'table-cell nil
)
3651 (org-element-contents l2-item
)))
3659 ;;; Interactive functions
3661 (defun org-e-odt-create-manifest-file-entry (&rest args
)
3662 (push args org-e-odt-manifest-file-entries
))
3664 (defun org-e-odt-write-manifest-file ()
3665 (make-directory (concat org-e-odt-zip-dir
"META-INF"))
3666 (let ((manifest-file (concat org-e-odt-zip-dir
"META-INF/manifest.xml")))
3667 (with-current-buffer
3668 (let ((nxml-auto-insert-xml-declaration-flag nil
))
3669 (find-file-noselect manifest-file t
))
3671 "<?xml version=\"1.0\" encoding=\"UTF-8\"?>
3672 <manifest:manifest xmlns:manifest=\"urn:oasis:names:tc:opendocument:xmlns:manifest:1.0\" manifest:version=\"1.2\">\n")
3674 (lambda (file-entry)
3675 (let* ((version (nth 2 file-entry
))
3676 (extra (if (not version
) ""
3677 (format " manifest:version=\"%s\"" version
))))
3679 (format org-e-odt-manifest-file-entry-tag
3680 (nth 0 file-entry
) (nth 1 file-entry
) extra
))))
3681 org-e-odt-manifest-file-entries
)
3682 (insert "\n</manifest:manifest>"))))
3684 (defmacro org-e-odt--export-wrap
(out-file &rest body
)
3685 `(let* ((--out-file ,out-file
)
3686 (out-file-type (file-name-extension --out-file
))
3687 (org-e-odt-xml-files '("META-INF/manifest.xml" "content.xml"
3688 "meta.xml" "styles.xml"))
3689 ;; Initialize workarea. All files that end up in the
3690 ;; exported get created here.
3691 (org-e-odt-zip-dir (file-name-as-directory
3692 (make-temp-file (format "%s-" out-file-type
) t
)))
3693 (org-e-odt-manifest-file-entries nil
)
3694 (--cleanup-xml-buffers
3697 ;; Kill all XML buffers.
3698 (mapc (lambda (file)
3699 (let ((buf (get-file-buffer
3700 (concat org-e-odt-zip-dir file
))))
3702 (set-buffer-modified-p nil
)
3703 (kill-buffer buf
))))
3704 org-e-odt-xml-files
)
3705 ;; Delete temporary directory and also other embedded
3706 ;; files that get copied there.
3707 (delete-directory org-e-odt-zip-dir t
)))))
3708 (org-condition-case-unless-debug err
3710 (unless (executable-find "zip")
3711 ;; Not at all OSes ship with zip by default
3712 (error "Executable \"zip\" needed for creating OpenDocument files"))
3713 ;; Do export. This creates a bunch of xml files ready to be
3714 ;; saved and zipped.
3716 ;; Create a manifest entry for content.xml.
3717 (org-e-odt-create-manifest-file-entry "text/xml" "content.xml")
3718 ;; Write mimetype file
3720 '(("odt" .
"application/vnd.oasis.opendocument.text")
3721 ("odf" .
"application/vnd.oasis.opendocument.formula")))
3722 (mimetype (cdr (assoc-string out-file-type mimetypes t
))))
3724 (error "Unknown OpenDocument backend %S" out-file-type
))
3725 (write-region mimetype nil
(concat org-e-odt-zip-dir
"mimetype"))
3726 (org-e-odt-create-manifest-file-entry mimetype
"/" "1.2"))
3727 ;; Write out the manifest entries before zipping
3728 (org-e-odt-write-manifest-file)
3729 ;; Save all XML files.
3730 (mapc (lambda (file)
3731 (let ((buf (get-file-buffer (concat org-e-odt-zip-dir file
))))
3733 (with-current-buffer buf
3734 ;; Prettify output if needed.
3735 (when org-e-odt-prettify-xml
3736 (indent-region (point-min) (point-max)))
3738 org-e-odt-xml-files
)
3740 (let* ((target --out-file
)
3741 (target-name (file-name-nondirectory target
))
3742 (target-dir (file-name-directory target
))
3743 (cmds `(("zip" "-mX0" ,target-name
"mimetype")
3744 ("zip" "-rmTq" ,target-name
"."))))
3745 ;; If a file with same name as the desired output file
3746 ;; exists, remove it.
3747 (when (file-exists-p target
)
3748 (delete-file target
))
3749 ;; Zip up the xml files.
3750 (let ((coding-system-for-write 'no-conversion
) exitcode err-string
)
3751 (message "Creating ODT file...")
3752 ;; Switch temporarily to content.xml. This way Zip
3753 ;; process will inherit `org-e-odt-zip-dir' as the current
3755 (with-current-buffer
3756 (find-file-noselect (concat org-e-odt-zip-dir
"content.xml") t
)
3759 (message "Running %s" (mapconcat 'identity cmd
" "))
3761 (with-output-to-string
3763 (apply 'call-process
(car cmd
)
3764 nil standard-output nil
(cdr cmd
)))))
3765 (or (zerop exitcode
)
3766 (error (concat "Unable to create OpenDocument file."
3767 (format " Zip failed with error (%s)"
3770 ;; Zip file is now in the rightful place.
3771 (rename-file target-name target
)))
3772 (message "Created %s" target
)
3773 ;; Cleanup work directory and work files.
3774 (funcall --cleanup-xml-buffers
)
3775 ;; Open the OpenDocument file in archive-mode for
3777 (find-file-noselect target t
)
3778 ;; Return exported file.
3780 ;; Case 1: Conversion desired on exported file. Run the
3781 ;; converter on the OpenDocument file. Return the
3783 (org-e-odt-preferred-output-format
3784 (or (org-e-odt-convert target org-e-odt-preferred-output-format
)
3786 ;; Case 2: No further conversion. Return exported
3787 ;; OpenDocument file.
3790 ;; Cleanup work directory and work files.
3791 (funcall --cleanup-xml-buffers
)
3792 (message "OpenDocument export failed: %s"
3793 (error-message-string err
))))))
3796 ;;;; Export to OpenDocument formula
3799 (defun org-e-odt-export-as-odf (latex-frag &optional odf-file
)
3800 "Export LATEX-FRAG as OpenDocument formula file ODF-FILE.
3801 Use `org-create-math-formula' to convert LATEX-FRAG first to
3802 MathML. When invoked as an interactive command, use
3803 `org-latex-regexps' to infer LATEX-FRAG from currently active
3804 region. If no LaTeX fragments are found, prompt for it. Push
3805 MathML source to kill ring, if `org-export-copy-to-kill-ring' is
3809 (setq frag
(and (setq frag
(and (region-active-p)
3810 (buffer-substring (region-beginning)
3812 (loop for e in org-latex-regexps
3813 thereis
(when (string-match (nth 1 e
) frag
)
3814 (match-string (nth 2 e
) frag
)))))
3815 (read-string "LaTeX Fragment: " frag nil frag
))
3816 ,(let ((odf-filename (expand-file-name
3818 (file-name-sans-extension
3819 (or (file-name-nondirectory buffer-file-name
)))
3821 (file-name-directory buffer-file-name
))))
3822 (read-file-name "ODF filename: " nil odf-filename nil
3823 (file-name-nondirectory odf-filename
)))))
3824 (let ((filename (or odf-file
3827 (file-name-sans-extension
3828 (or (file-name-nondirectory buffer-file-name
)))
3830 (file-name-directory buffer-file-name
)))))
3831 (org-e-odt--export-wrap
3833 (let* ((buffer (progn
3834 (require 'nxml-mode
)
3835 (let ((nxml-auto-insert-xml-declaration-flag nil
))
3836 (find-file-noselect (concat org-e-odt-zip-dir
3837 "content.xml") t
))))
3838 (coding-system-for-write 'utf-8
)
3839 (save-buffer-coding-system 'utf-8
))
3841 (set-buffer-file-coding-system coding-system-for-write
)
3842 (let ((mathml (org-create-math-formula latex-frag
)))
3843 (unless mathml
(error "No Math formula created"))
3845 ;; Add MathML to kill ring, if needed.
3846 (when org-export-copy-to-kill-ring
3847 (org-kill-new (buffer-string))))))))
3850 (defun org-e-odt-export-as-odf-and-open ()
3851 "Export LaTeX fragment as OpenDocument formula and immediately open it.
3852 Use `org-e-odt-export-as-odf' to read LaTeX fragment and OpenDocument
3855 (org-open-file (call-interactively 'org-e-odt-export-as-odf
) 'system
))
3858 ;;;; Export to OpenDocument Text
3861 (defun org-e-odt-export-to-odt
3862 (&optional subtreep visible-only body-only ext-plist pub-dir
)
3863 "Export current buffer to a HTML file.
3865 If narrowing is active in the current buffer, only export its
3868 If a region is active, export that region.
3870 When optional argument SUBTREEP is non-nil, export the sub-tree
3871 at point, extracting information from the headline properties
3874 When optional argument VISIBLE-ONLY is non-nil, don't export
3875 contents of hidden elements.
3877 When optional argument BODY-ONLY is non-nil, only write code
3878 between \"\\begin{document}\" and \"\\end{document}\".
3880 EXT-PLIST, when provided, is a property list with external
3881 parameters overriding Org default settings, but still inferior to
3882 file-local settings.
3884 When optional argument PUB-DIR is set, use it as the publishing
3887 Return output file's name."
3889 (org-e-odt--export-wrap
3890 (org-export-output-file-name ".odt" subtreep pub-dir
)
3891 (let* ((org-e-odt-embedded-images-count 0)
3892 (org-e-odt-embedded-formulas-count 0)
3893 (org-e-odt-automatic-styles nil
)
3894 (org-e-odt-object-counters nil
)
3895 ;; Let `htmlfontify' know that we are interested in collecting
3897 (hfy-user-sheet-assoc nil
))
3898 ;; Initialize content.xml and kick-off the export process.
3899 (let ((out-buf (progn
3900 (require 'nxml-mode
)
3901 (let ((nxml-auto-insert-xml-declaration-flag nil
))
3903 (concat org-e-odt-zip-dir
"content.xml") t
)))))
3904 (org-export-to-buffer 'e-odt out-buf subtreep visible-only body-only
)))))
3907 ;;;; Convert between OpenDocument and other formats
3909 (defun org-e-odt-reachable-p (in-fmt out-fmt
)
3910 "Return non-nil if IN-FMT can be converted to OUT-FMT."
3912 (let ((reachable-formats (org-e-odt-do-reachable-formats in-fmt
)))
3913 (dolist (e reachable-formats
)
3914 (let ((out-fmt-spec (assoc out-fmt
(cdr e
))))
3916 (throw 'done
(cons (car e
) out-fmt-spec
))))))))
3918 (defun org-e-odt-do-convert (in-file out-fmt
&optional prefix-arg
)
3919 "Workhorse routine for `org-e-odt-convert'."
3920 (require 'browse-url
)
3921 (let* ((in-file (expand-file-name (or in-file buffer-file-name
)))
3922 (dummy (or (file-readable-p in-file
)
3923 (error "Cannot read %s" in-file
)))
3924 (in-fmt (file-name-extension in-file
))
3925 (out-fmt (or out-fmt
(error "Output format unspecified")))
3926 (how (or (org-e-odt-reachable-p in-fmt out-fmt
)
3927 (error "Cannot convert from %s format to %s format?"
3929 (convert-process (car how
))
3930 (out-file (concat (file-name-sans-extension in-file
) "."
3931 (nth 1 (or (cdr how
) out-fmt
))))
3932 (extra-options (or (nth 2 (cdr how
)) ""))
3933 (out-dir (file-name-directory in-file
))
3934 (cmd (format-spec convert-process
3935 `((?i .
,(shell-quote-argument in-file
))
3936 (?I .
,(browse-url-file-url in-file
))
3939 (?O .
,(browse-url-file-url out-file
))
3940 (?d .
, (shell-quote-argument out-dir
))
3941 (?D .
,(browse-url-file-url out-dir
))
3942 (?x .
,extra-options
)))))
3943 (when (file-exists-p out-file
)
3944 (delete-file out-file
))
3946 (message "Executing %s" cmd
)
3947 (let ((cmd-output (shell-command-to-string cmd
)))
3948 (message "%s" cmd-output
))
3951 ((file-exists-p out-file
)
3952 (message "Exported to %s" out-file
)
3954 (message "Opening %s..." out-file
)
3955 (org-open-file out-file
'system
))
3958 (message "Export to %s failed" out-file
)
3961 (defun org-e-odt-do-reachable-formats (in-fmt)
3962 "Return verbose info about formats to which IN-FMT can be converted.
3963 Return a list where each element is of the
3964 form (CONVERTER-PROCESS . OUTPUT-FMT-ALIST). See
3965 `org-e-odt-convert-processes' for CONVERTER-PROCESS and see
3966 `org-e-odt-convert-capabilities' for OUTPUT-FMT-ALIST."
3968 (and org-e-odt-convert-process
3969 (cadr (assoc-string org-e-odt-convert-process
3970 org-e-odt-convert-processes t
))))
3972 (and org-e-odt-convert-process
3973 (cadr (assoc-string org-e-odt-convert-process
3974 org-e-odt-convert-processes t
))
3975 org-e-odt-convert-capabilities
))
3978 (dolist (c capabilities
)
3979 (when (member in-fmt
(nth 1 c
))
3980 (push (cons converter
(nth 2 c
)) reachable-formats
))))
3983 (defun org-e-odt-reachable-formats (in-fmt)
3984 "Return list of formats to which IN-FMT can be converted.
3985 The list of the form (OUTPUT-FMT-1 OUTPUT-FMT-2 ...)."
3987 (mapc (lambda (e) (add-to-list 'l e
))
3988 (apply 'append
(mapcar
3989 (lambda (e) (mapcar 'car
(cdr e
)))
3990 (org-e-odt-do-reachable-formats in-fmt
))))
3993 (defun org-e-odt-convert-read-params ()
3994 "Return IN-FILE and OUT-FMT params for `org-e-odt-do-convert'.
3995 This is a helper routine for interactive use."
3996 (let* ((input (if (featurep 'ido
) 'ido-completing-read
'completing-read
))
3997 (in-file (read-file-name "File to be converted: "
3998 nil buffer-file-name t
))
3999 (in-fmt (file-name-extension in-file
))
4000 (out-fmt-choices (org-e-odt-reachable-formats in-fmt
))
4002 (or (and out-fmt-choices
4003 (funcall input
"Output format: "
4004 out-fmt-choices nil nil nil
))
4006 "No known converter or no known output formats for %s files"
4008 (list in-file out-fmt
)))
4011 (defun org-e-odt-convert (&optional in-file out-fmt prefix-arg
)
4012 "Convert IN-FILE to format OUT-FMT using a command line converter.
4013 IN-FILE is the file to be converted. If unspecified, it defaults
4014 to variable `buffer-file-name'. OUT-FMT is the desired output
4015 format. Use `org-e-odt-convert-process' as the converter.
4016 If PREFIX-ARG is non-nil then the newly converted file is opened
4017 using `org-open-file'."
4019 (append (org-e-odt-convert-read-params) current-prefix-arg
))
4020 (org-e-odt-do-convert in-file out-fmt prefix-arg
))
4022 ;;; Library Initializations
4026 ;; Let Emacs open all OpenDocument files in archive mode
4027 (add-to-list 'auto-mode-alist
4028 (cons (concat "\\." (car desc
) "\\'") 'archive-mode
)))
4029 org-e-odt-file-extensions
)
4031 (provide 'org-e-odt
)
4033 ;;; org-e-odt.el ends here