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
))
87 ((:odt-styles-file
"ODT_STYLES_FILE" nil nil t
)
88 (:LaTeX-fragments nil
"LaTeX" org-export-with-LaTeX-fragments
)))
95 ;;; Function Declarations
97 (declare-function org-id-find-id-file
"org-id" (id))
98 (declare-function hfy-face-to-style
"htmlfontify" (fn))
99 (declare-function hfy-face-or-def-to-name
"htmlfontify" (fn))
100 (declare-function archive-zip-extract
"arc-mode.el" (archive name
))
101 (declare-function org-create-math-formula
"org" (latex-frag &optional
103 (declare-function browse-url-file-url
"browse-url" (file))
107 ;;; Internal Variables
109 (defconst org-e-odt-lib-dir
110 (file-name-directory load-file-name
)
111 "Location of ODT exporter.
112 Use this to infer values of `org-e-odt-styles-dir' and
113 `org-e-odt-schema-dir'.")
115 (defvar org-e-odt-data-dir
116 (expand-file-name "../../etc/" org-e-odt-lib-dir
)
117 "Data directory for ODT exporter.
118 Use this to infer values of `org-e-odt-styles-dir' and
119 `org-e-odt-schema-dir'.")
121 (defconst org-e-odt-special-string-regexps
122 '(("\\\\-" .
"­\\1") ; shy
123 ("---\\([^-]\\)" .
"—\\1") ; mdash
124 ("--\\([^-]\\)" .
"–\\1") ; ndash
125 ("\\.\\.\\." .
"…")) ; hellip
126 "Regular expressions for special string conversion.")
128 (defconst org-e-odt-schema-dir-list
130 (and org-e-odt-data-dir
131 (expand-file-name "./schema/" org-e-odt-data-dir
)) ; bail out
133 (and (boundp 'org-e-odt-data-dir
) org-e-odt-data-dir
; see make install
134 (expand-file-name "./schema/" org-e-odt-data-dir
))))
135 "List of directories to search for OpenDocument schema files.
136 Use this list to set the default value of
137 `org-e-odt-schema-dir'. The entries in this list are
138 populated heuristically based on the values of `org-e-odt-lib-dir'
139 and `org-e-odt-data-dir'.")
141 (defconst org-e-odt-styles-dir-list
143 (and org-e-odt-data-dir
144 (expand-file-name "./styles/" org-e-odt-data-dir
)) ; bail out
146 (and (boundp 'org-e-odt-data-dir
) org-e-odt-data-dir
; see make install
147 (expand-file-name "./styles/" org-e-odt-data-dir
)))
148 (expand-file-name "../../etc/styles/" org-e-odt-lib-dir
) ; git
149 (expand-file-name "./etc/styles/" org-e-odt-lib-dir
) ; elpa
150 (expand-file-name "./org/" data-directory
) ; system
152 "List of directories to search for OpenDocument styles files.
153 See `org-e-odt-styles-dir'. The entries in this list are populated
154 heuristically based on the values of `org-e-odt-lib-dir' and
155 `org-e-odt-data-dir'.")
157 (defconst org-e-odt-styles-dir
160 (message "Debug (org-e-odt): Searching for OpenDocument styles files...")
161 (mapc (lambda (styles-dir)
163 (message "Debug (org-e-odt): Trying %s..." styles-dir
)
164 (when (and (file-readable-p
166 "OrgOdtContentTemplate.xml" styles-dir
))
169 "OrgOdtStyles.xml" styles-dir
)))
170 (message "Debug (org-e-odt): Using styles under %s"
172 (throw 'styles-dir styles-dir
))))
173 org-e-odt-styles-dir-list
)
176 (error "Error (org-e-odt): Cannot find factory styles files. Aborting."))
178 "Directory that holds auxiliary XML files used by the ODT exporter.
180 This directory contains the following XML files -
181 \"OrgOdtStyles.xml\" and \"OrgOdtContentTemplate.xml\". These
182 XML files are used as the default values of
183 `org-e-odt-styles-file' and
184 `org-e-odt-content-template-file'.
186 The default value of this variable varies depending on the
187 version of org in use and is initialized from
188 `org-e-odt-styles-dir-list'. Note that the user could be using org
189 from one of: org's own private git repository, GNU ELPA tar or
192 (defconst org-e-odt-bookmark-prefix
"OrgXref.")
194 (defconst org-e-odt-manifest-file-entry-tag
195 "\n<manifest:file-entry manifest:media-type=\"%s\" manifest:full-path=\"%s\"%s/>")
197 (defconst org-e-odt-file-extensions
198 '(("odt" .
"OpenDocument Text")
199 ("ott" .
"OpenDocument Text Template")
200 ("odm" .
"OpenDocument Master Document")
201 ("ods" .
"OpenDocument Spreadsheet")
202 ("ots" .
"OpenDocument Spreadsheet Template")
203 ("odg" .
"OpenDocument Drawing (Graphics)")
204 ("otg" .
"OpenDocument Drawing Template")
205 ("odp" .
"OpenDocument Presentation")
206 ("otp" .
"OpenDocument Presentation Template")
207 ("odi" .
"OpenDocument Image")
208 ("odf" .
"OpenDocument Formula")
209 ("odc" .
"OpenDocument Chart")))
211 (defvar org-e-odt-table-style-format
213 <style:style style:name=\"%s\" style:family=\"table\">
214 <style:table-properties style:rel-width=\"%d%%\" fo:margin-top=\"0cm\" fo:margin-bottom=\"0.20cm\" table:align=\"center\"/>
217 "Template for auto-generated Table styles.")
219 (defvar org-e-odt-automatic-styles
'()
220 "Registry of automatic styles for various OBJECT-TYPEs.
221 The variable has the following form:
223 \(\(OBJECT-NAME-A.1 OBJECT-PROPS-A.1\)
224 \(OBJECT-NAME-A.2 OBJECT-PROPS-A.2\) ...\)\)
226 \(\(OBJECT-NAME-B.1 OBJECT-PROPS-B.1\)
227 \(OBJECT-NAME-B.2 OBJECT-PROPS-B.2\) ...\)\)
230 OBJECT-TYPEs could be \"Section\", \"Table\", \"Figure\" etc.
231 OBJECT-PROPS is (typically) a plist created by passing
232 \"#+ATTR_ODT: \" option to `org-e-odt-parse-block-attributes'.
234 Use `org-e-odt-add-automatic-style' to add update this variable.'")
236 (defvar org-e-odt-object-counters nil
237 "Running counters for various OBJECT-TYPEs.
238 Use this to generate automatic names and style-names. See
239 `org-e-odt-add-automatic-style'.")
241 (defvar org-e-odt-src-block-paragraph-format
242 "<style:style style:name=\"OrgSrcBlock\" style:family=\"paragraph\" style:parent-style-name=\"Preformatted_20_Text\">
243 <style:paragraph-properties fo:background-color=\"%s\" fo:padding=\"0.049cm\" fo:border=\"0.51pt solid #000000\" style:shadow=\"none\">
244 <style:background-image/>
245 </style:paragraph-properties>
246 <style:text-properties fo:color=\"%s\"/>
248 "Custom paragraph style for colorized source and example blocks.
249 This style is much the same as that of \"OrgFixedWidthBlock\"
250 except that the foreground and background colors are set
251 according to the default face identified by the `htmlfontify'.")
253 (defvar hfy-optimisations
)
254 (defvar org-e-odt-embedded-formulas-count
0)
255 (defvar org-e-odt-entity-frame-styles
256 '(("As-CharImage" "__Figure__" ("OrgInlineImage" nil
"as-char"))
257 ("ParagraphImage" "__Figure__" ("OrgDisplayImage" nil
"paragraph"))
258 ("PageImage" "__Figure__" ("OrgPageImage" nil
"page"))
259 ("CaptionedAs-CharImage" "__Figure__"
261 " style:rel-width=\"100%\" style:rel-height=\"scale\"" "paragraph")
262 ("OrgInlineImage" nil
"as-char"))
263 ("CaptionedParagraphImage" "__Figure__"
265 " style:rel-width=\"100%\" style:rel-height=\"scale\"" "paragraph")
266 ("OrgImageCaptionFrame" nil
"paragraph"))
267 ("CaptionedPageImage" "__Figure__"
269 " style:rel-width=\"100%\" style:rel-height=\"scale\"" "paragraph")
270 ("OrgPageImageCaptionFrame" nil
"page"))
271 ("InlineFormula" "__MathFormula__" ("OrgInlineFormula" nil
"as-char"))
272 ("DisplayFormula" "__MathFormula__" ("OrgDisplayFormula" nil
"as-char"))
273 ("CaptionedDisplayFormula" "__MathFormula__"
274 ("OrgCaptionedFormula" nil
"paragraph")
275 ("OrgFormulaCaptionFrame" nil
"as-char"))))
277 (defvar org-e-odt-embedded-images-count
0)
278 (defvar org-e-odt-image-size-probe-method
279 (append (and (executable-find "identify") '(imagemagick)) ; See Bug#10675
281 "Ordered list of methods for determining image sizes.")
283 (defvar org-e-odt-default-image-sizes-alist
284 '(("as-char" .
(5 .
0.4))
285 ("paragraph" .
(5 .
5)))
286 "Hardcoded image dimensions one for each of the anchor
289 ;; A4 page size is 21.0 by 29.7 cms
290 ;; The default page settings has 2cm margin on each of the sides. So
291 ;; the effective text area is 17.0 by 25.7 cm
292 (defvar org-e-odt-max-image-size
'(17.0 .
20.0)
293 "Limiting dimensions for an embedded image.")
295 (defvar org-e-odt-label-styles
296 '(("math-formula" "%c" "text" "(%n)")
297 ("math-label" "(%n)" "text" "(%n)")
298 ("category-and-value" "%e %n: %c" "category-and-value" "%e %n")
299 ("value" "%e %n: %c" "value" "%n"))
300 "Specify how labels are applied and referenced.
301 This is an alist where each element is of the
302 form (LABEL-STYLE-NAME LABEL-ATTACH-FMT LABEL-REF-MODE
305 LABEL-ATTACH-FMT controls how labels and captions are attached to
306 an entity. It may contain following specifiers - %e, %n and %c.
307 %e is replaced with the CATEGORY-NAME. %n is replaced with
308 \"<text:sequence ...> SEQNO </text:sequence>\". %c is replaced
309 with CAPTION. See `org-e-odt-format-label-definition'.
311 LABEL-REF-MODE and LABEL-REF-FMT controls how label references
312 are generated. The following XML is generated for a label
313 reference - \"<text:sequence-ref
314 text:reference-format=\"LABEL-REF-MODE\" ...> LABEL-REF-FMT
315 </text:sequence-ref>\". LABEL-REF-FMT may contain following
316 specifiers - %e and %n. %e is replaced with the CATEGORY-NAME.
317 %n is replaced with SEQNO. See
318 `org-e-odt-format-label-reference'.")
320 (defvar org-e-odt-category-map-alist
321 '(("__Table__" "Table" "value" "Table")
322 ("__Figure__" "Illustration" "value" "Figure")
323 ("__MathFormula__" "Text" "math-formula" "Equation")
324 ("__DvipngImage__" "Equation" "value" "Equation")
325 ("__Listing__" "Listing" "value" "Listing")
326 ;; ("__Table__" "Table" "category-and-value")
327 ;; ("__Figure__" "Figure" "category-and-value")
328 ;; ("__DvipngImage__" "Equation" "category-and-value")
330 "Map a CATEGORY-HANDLE to OD-VARIABLE and LABEL-STYLE.
331 This is a list where each entry is of the form \\(CATEGORY-HANDLE
332 OD-VARIABLE LABEL-STYLE CATEGORY-NAME\\). CATEGORY_HANDLE
333 identifies the captionable entity in question. OD-VARIABLE is
334 the OpenDocument sequence counter associated with the entity.
335 These counters are declared within
336 \"<text:sequence-decls>...</text:sequence-decls>\" block of
337 `org-e-odt-content-template-file'. LABEL-STYLE is a key into
338 `org-e-odt-label-styles' and specifies how a given entity should
339 be captioned and referenced. CATEGORY-NAME is used for
340 qualifying captions on export. You can modify the CATEGORY-NAME
341 used in the exported document by modifying
342 `org-export-dictionary'. For example, an embedded image in an
343 English document is captioned as \"Figure 1: Orgmode Logo\", by
344 default. If you want the image to be captioned as \"Illustration
345 1: Orgmode Logo\" instead, install an entry in
346 `org-export-dictionary' which translates \"Figure\" to
347 \"Illustration\" when the language is \"en\" and encoding is
350 (defvar org-e-odt-manifest-file-entries nil
)
351 (defvar hfy-user-sheet-assoc
)
353 (defvar org-e-odt-zip-dir nil
354 "Temporary work directory for OpenDocument exporter.")
358 ;;; User Configuration Variables
360 (defgroup org-export-e-odt nil
361 "Options for exporting Org mode files to ODT."
362 :tag
"Org Export ODT"
368 (defcustom org-e-odt-prettify-xml nil
369 "Specify whether or not the xml output should be prettified.
370 When this option is turned on, `indent-region' is run on all
371 component xml buffers before they are saved. Turn this off for
372 regular use. Turn this on if you need to examine the xml
374 :group
'org-export-e-odt
381 (defcustom org-e-odt-schema-dir
384 (message "Debug (org-e-odt): Searching for OpenDocument schema files...")
388 (message "Debug (org-e-odt): Trying %s..." schema-dir
)
389 (when (and (file-readable-p
390 (expand-file-name "od-manifest-schema-v1.2-cs01.rnc"
393 (expand-file-name "od-schema-v1.2-cs01.rnc"
396 (expand-file-name "schemas.xml" schema-dir
)))
397 (message "Debug (org-e-odt): Using schema files under %s"
399 (throw 'schema-dir schema-dir
))))
400 org-e-odt-schema-dir-list
)
401 (message "Debug (org-e-odt): No OpenDocument schema files installed")
404 "Directory that contains OpenDocument schema files.
406 This directory contains:
407 1. rnc files for OpenDocument schema
408 2. a \"schemas.xml\" file that specifies locating rules needed
409 for auto validation of OpenDocument XML files.
411 Use the customize interface to set this variable. This ensures
412 that `rng-schema-locating-files' is updated and auto-validation
413 of OpenDocument XML takes place based on the value
414 `rng-nxml-auto-validate-flag'.
416 The default value of this variable varies depending on the
417 version of org in use and is initialized from
418 `org-e-odt-schema-dir-list'. The OASIS schema files are available
419 only in the org's private git repository. It is *not* bundled
420 with GNU ELPA tar or standard Emacs distribution."
422 (const :tag
"Not set" nil
)
423 (directory :tag
"Schema directory"))
424 :group
'org-export-e-odt
428 "Set `org-e-odt-schema-dir'.
429 Also add it to `rng-schema-locating-files'."
430 (let ((schema-dir value
))
434 (expand-file-name "od-manifest-schema-v1.2-cs01.rnc" schema-dir
))
436 (expand-file-name "od-schema-v1.2-cs01.rnc" schema-dir
))
438 (expand-file-name "schemas.xml" schema-dir
)))
441 (message "Error (org-e-odt): %s has no OpenDocument schema files"
444 (when org-e-odt-schema-dir
445 (eval-after-load 'rng-loc
446 '(add-to-list 'rng-schema-locating-files
447 (expand-file-name "schemas.xml"
448 org-e-odt-schema-dir
))))))
453 (defcustom org-e-odt-content-template-file nil
454 "Template file for \"content.xml\".
455 The exporter embeds the exported content just before
456 \"</office:text>\" element.
458 If unspecified, the file named \"OrgOdtContentTemplate.xml\"
459 under `org-e-odt-styles-dir' is used."
461 :group
'org-export-e-odt
464 (defcustom org-e-odt-styles-file nil
465 "Default styles file for use with ODT export.
466 Valid values are one of:
468 2. path to a styles.xml file
469 3. path to a *.odt or a *.ott file
470 4. list of the form (ODT-OR-OTT-FILE (FILE-MEMBER-1 FILE-MEMBER-2
473 In case of option 1, an in-built styles.xml is used. See
474 `org-e-odt-styles-dir' for more information.
476 In case of option 3, the specified file is unzipped and the
477 styles.xml embedded therein is used.
479 In case of option 4, the specified ODT-OR-OTT-FILE is unzipped
480 and FILE-MEMBER-1, FILE-MEMBER-2 etc are copied in to the
481 generated odt file. Use relative path for specifying the
482 FILE-MEMBERS. styles.xml must be specified as one of the
485 Use options 1, 2 or 3 only if styles.xml alone suffices for
486 achieving the desired formatting. Use option 4, if the styles.xml
487 references additional files like header and footer images for
488 achieving the desired formatting.
490 Use \"#+ODT_STYLES_FILE: ...\" directive to set this variable on
491 a per-file basis. For example,
493 #+ODT_STYLES_FILE: \"/path/to/styles.xml\" or
494 #+ODT_STYLES_FILE: (\"/path/to/file.ott\" (\"styles.xml\" \"image/hdr.png\"))."
495 :group
'org-export-e-odt
499 (const :tag
"Factory settings" nil
)
500 (file :must-match t
:tag
"styles.xml")
501 (file :must-match t
:tag
"ODT or OTT file")
502 (list :tag
"ODT or OTT file + Members"
503 (file :must-match t
:tag
"ODF Text or Text Template file")
505 (file :tag
" Member" "styles.xml")
506 (repeat (file :tag
"Member"))))))
508 (defcustom org-e-odt-display-outline-level
2
509 "Outline levels considered for enumerating captioned entities."
510 :group
'org-export-e-odt
514 ;;;; Document conversion
516 (defcustom org-e-odt-convert-processes
518 "soffice --headless --convert-to %f%x --outdir %d %i")
520 "unoconv -f %f -o %d %i"))
521 "Specify a list of document converters and their usage.
522 The converters in this list are offered as choices while
523 customizing `org-e-odt-convert-process'.
525 This variable is a list where each element is of the
526 form (CONVERTER-NAME CONVERTER-CMD). CONVERTER-NAME is the name
527 of the converter. CONVERTER-CMD is the shell command for the
528 converter and can contain format specifiers. These format
529 specifiers are interpreted as below:
531 %i input file name in full
532 %I input file name as a URL
533 %f format of the output file
534 %o output file name in full
535 %O output file name as a URL
536 %d output dir in full
537 %D output dir as a URL.
538 %x extra options as set in `org-e-odt-convert-capabilities'."
539 :group
'org-export-e-odt
543 (const :tag
"None" nil
)
544 (alist :tag
"Converters"
545 :key-type
(string :tag
"Converter Name")
546 :value-type
(group (string :tag
"Command line")))))
548 (defcustom org-e-odt-convert-process
"LibreOffice"
549 "Use this converter to convert from \"odt\" format to other formats.
550 During customization, the list of converter names are populated
551 from `org-e-odt-convert-processes'."
552 :group
'org-export-e-odt
554 :type
'(choice :convert-widget
556 (apply 'widget-convert
(widget-type w
)
557 (eval (car (widget-get w
:args
)))))
558 `((const :tag
"None" nil
)
559 ,@(mapcar (lambda (c)
560 `(const :tag
,(car c
) ,(car c
)))
561 org-e-odt-convert-processes
))))
563 (defcustom org-e-odt-convert-capabilities
565 ("odt" "ott" "doc" "rtf" "docx")
566 (("pdf" "pdf") ("odt" "odt") ("rtf" "rtf") ("ott" "ott")
567 ("doc" "doc" ":\"MS Word 97\"") ("docx" "docx") ("html" "html")))
570 (("pdf" "pdf") ("odt" "odt") ("html" "html")))
572 ("ods" "ots" "xls" "csv" "xlsx")
573 (("pdf" "pdf") ("ots" "ots") ("html" "html") ("csv" "csv") ("ods" "ods")
574 ("xls" "xls") ("xlsx" "xlsx")))
576 ("odp" "otp" "ppt" "pptx")
577 (("pdf" "pdf") ("swf" "swf") ("odp" "odp") ("otp" "otp") ("ppt" "ppt")
578 ("pptx" "pptx") ("odg" "odg"))))
579 "Specify input and output formats of `org-e-odt-convert-process'.
580 More correctly, specify the set of input and output formats that
581 the user is actually interested in.
583 This variable is an alist where each element is of the
584 form (DOCUMENT-CLASS INPUT-FMT-LIST OUTPUT-FMT-ALIST).
585 INPUT-FMT-LIST is a list of INPUT-FMTs. OUTPUT-FMT-ALIST is an
586 alist where each element is of the form (OUTPUT-FMT
587 OUTPUT-FILE-EXTENSION EXTRA-OPTIONS).
589 The variable is interpreted as follows:
590 `org-e-odt-convert-process' can take any document that is in
591 INPUT-FMT-LIST and produce any document that is in the
592 OUTPUT-FMT-LIST. A document converted to OUTPUT-FMT will have
593 OUTPUT-FILE-EXTENSION as the file name extension. OUTPUT-FMT
594 serves dual purposes:
595 - It is used for populating completion candidates during
596 `org-e-odt-convert' commands.
597 - It is used as the value of \"%f\" specifier in
598 `org-e-odt-convert-process'.
600 EXTRA-OPTIONS is used as the value of \"%x\" specifier in
601 `org-e-odt-convert-process'.
603 DOCUMENT-CLASS is used to group a set of file formats in
604 INPUT-FMT-LIST in to a single class.
606 Note that this variable inherently captures how LibreOffice based
607 converters work. LibreOffice maps documents of various formats
608 to classes like Text, Web, Spreadsheet, Presentation etc and
609 allow document of a given class (irrespective of it's source
610 format) to be converted to any of the export formats associated
613 See default setting of this variable for an typical
615 :group
'org-export-e-odt
619 (const :tag
"None" nil
)
620 (alist :tag
"Capabilities"
621 :key-type
(string :tag
"Document Class")
623 (group (repeat :tag
"Input formats" (string :tag
"Input format"))
624 (alist :tag
"Output formats"
625 :key-type
(string :tag
"Output format")
627 (group (string :tag
"Output file extension")
629 (const :tag
"None" nil
)
630 (string :tag
"Extra options"))))))))
632 (defcustom org-e-odt-preferred-output-format nil
633 "Automatically post-process to this format after exporting to \"odt\".
634 Interactive commands `org-export-as-e-odt' and
635 `org-export-as-e-odt-and-open' export first to \"odt\" format and
636 then use `org-e-odt-convert-process' to convert the
637 resulting document to this format. During customization of this
638 variable, the list of valid values are populated based on
639 `org-e-odt-convert-capabilities'."
640 :group
'org-export-e-odt
642 :type
'(choice :convert-widget
644 (apply 'widget-convert
(widget-type w
)
645 (eval (car (widget-get w
:args
)))))
646 `((const :tag
"None" nil
)
647 ,@(mapcar (lambda (c)
649 (org-e-odt-reachable-formats "odt")))))
654 (defcustom org-e-odt-format-drawer-function nil
655 "Function called to format a drawer in HTML code.
657 The function must accept two parameters:
658 NAME the drawer name, like \"LOGBOOK\"
659 CONTENTS the contents of the drawer.
661 The function should return the string to be exported.
663 For example, the variable could be set to the following function
664 in order to mimic default behaviour:
666 \(defun org-e-odt-format-drawer-default \(name contents\)
667 \"Format a drawer element for HTML export.\"
669 :group
'org-export-e-odt
675 (defcustom org-e-odt-format-headline-function nil
676 "Function to format headline text.
678 This function will be called with 5 arguments:
679 TODO the todo keyword \(string or nil\).
680 TODO-TYPE the type of todo \(symbol: `todo', `done', nil\)
681 PRIORITY the priority of the headline \(integer or nil\)
682 TEXT the main headline text \(string\).
683 TAGS the tags string, separated with colons \(string or nil\).
685 The function result will be used in the section format string.
687 As an example, one could set the variable to the following, in
688 order to reproduce the default set-up:
690 \(defun org-e-odt-format-headline \(todo todo-type priority text tags\)
691 \"Default format function for an headline.\"
693 \(format \"\\\\textbf{\\\\textsc{\\\\textsf{%s}}} \" todo\)\)
695 \(format \"\\\\framebox{\\\\#%c} \" priority\)\)
697 \(when tags \(format \"\\\\hfill{}\\\\textsc{%s}\" tags\)\)\)\)"
698 :group
'org-export-e-odt
704 (defcustom org-e-odt-format-inlinetask-function nil
705 "Function called to format an inlinetask in HTML code.
707 The function must accept six parameters:
708 TODO the todo keyword, as a string
709 TODO-TYPE the todo type, a symbol among `todo', `done' and nil.
710 PRIORITY the inlinetask priority, as a string
711 NAME the inlinetask name, as a string.
712 TAGS the inlinetask tags, as a string.
713 CONTENTS the contents of the inlinetask, as a string.
715 The function should return the string to be exported.
717 For example, the variable could be set to the following function
718 in order to mimic default behaviour:
720 \(defun org-e-odt-format-inlinetask \(todo type priority name tags contents\)
721 \"Format an inline task element for HTML export.\"
725 \(format \"\\\\textbf{\\\\textsf{\\\\textsc{%s}}} \" todo\)\)
726 \(when priority \(format \"\\\\framebox{\\\\#%c} \" priority\)\)
728 \(when tags \(format \"\\\\hfill{}\\\\textsc{%s}\" tags\)\)\)\)\)
729 \(format \(concat \"\\\\begin{center}\\n\"
731 \"\\\\begin{minipage}[c]{.6\\\\textwidth}\\n\"
733 \"\\\\rule[.8em]{\\\\textwidth}{2pt}\\n\\n\"
735 \"\\\\end{minipage}}\"
736 \"\\\\end{center}\"\)
737 full-title contents\)\)"
738 :group
'org-export-e-odt
744 (defcustom org-e-odt-inline-image-rules
745 '(("file" .
"\\.\\(jpeg\\|jpg\\|png\\|gif\\)\\'"))
746 "Rules characterizing image files that can be inlined into HTML.
748 A rule consists in an association whose key is the type of link
749 to consider, and value is a regexp that will be matched against
752 Note that, by default, the image extension *actually* allowed
753 depend on the way the HTML file is processed. When used with
754 pdflatex, pdf, jpg and png images are OK. When processing
755 through dvi to Postscript, only ps and eps are allowed. The
756 default we use here encompasses both."
757 :group
'org-export-e-odt
758 :type
'(alist :key-type
(string :tag
"Type")
759 :value-type
(regexp :tag
"Path")))
761 (defcustom org-e-odt-pixels-per-inch display-pixels-per-inch
762 "Scaling factor for converting images pixels to inches.
763 Use this for sizing of embedded images. See Info node `(org)
764 Images in ODT export' for more information."
766 :group
'org-export-e-odt
772 (defcustom org-e-odt-quotes
774 ("\\(\\s-\\|[[(]\\|^\\)\"" .
"« ")
775 ("\\(\\S-\\)\"" .
"» ")
776 ("\\(\\s-\\|(\\|^\\)'" .
"'"))
778 ("\\(\\s-\\|[[(]\\|^\\)\"" .
"“")
779 ("\\(\\S-\\)\"" .
"”")
780 ("\\(\\s-\\|(\\|^\\)'" .
"‘")
781 ("\\(\\S-\\)'" .
"’")))
782 "Alist for quotes to use when converting english double-quotes.
784 The CAR of each item in this alist is the language code.
785 The CDR of each item in this alist is a list of three CONS:
786 - the first CONS defines the opening quote;
787 - the second CONS defines the closing quote;
788 - the last CONS defines single quotes.
790 For each item in a CONS, the first string is a regexp
791 for allowed characters before/after the quote, the second
792 string defines the replacement string for this quote."
793 :group
'org-export-e-odt
795 (cons :tag
"Opening quote"
796 (string :tag
"Regexp for char before")
797 (string :tag
"Replacement quote "))
798 (cons :tag
"Closing quote"
799 (string :tag
"Regexp for char after ")
800 (string :tag
"Replacement quote "))
801 (cons :tag
"Single quote"
802 (string :tag
"Regexp for char before")
803 (string :tag
"Replacement quote "))))
808 (defcustom org-e-odt-create-custom-styles-for-srcblocks t
809 "Whether custom styles for colorized source blocks be automatically created.
810 When this option is turned on, the exporter creates custom styles
811 for source blocks based on the advice of `htmlfontify'. Creation
812 of custom styles happen as part of `org-e-odt-hfy-face-to-css'.
814 When this option is turned off exporter does not create such
817 Use the latter option if you do not want the custom styles to be
818 based on your current display settings. It is necessary that the
819 styles.xml already contains needed styles for colorizing to work.
821 This variable is effective only if
822 `org-e-odt-fontify-srcblocks' is turned on."
823 :group
'org-export-e-odt
827 (defcustom org-e-odt-fontify-srcblocks t
828 "Specify whether or not source blocks need to be fontified.
829 Turn this option on if you want to colorize the source code
830 blocks in the exported file. For colorization to work, you need
831 to make available an enhanced version of `htmlfontify' library."
833 :group
'org-export-e-odt
839 (defcustom org-e-odt-table-caption-above t
840 "When non-nil, place caption string at the beginning of the table.
841 Otherwise, place it near the end."
842 :group
'org-export-e-odt
845 (defcustom org-e-odt-table-styles
846 '(("OrgEquation" "OrgEquation"
847 ((use-first-column-styles . t
)
848 (use-last-column-styles . t
))))
849 "Specify how Table Styles should be derived from a Table Template.
850 This is a list where each element is of the
851 form (TABLE-STYLE-NAME TABLE-TEMPLATE-NAME TABLE-CELL-OPTIONS).
853 TABLE-STYLE-NAME is the style associated with the table through
854 \"#+ATTR_ODT: :style TABLE-STYLE-NAME\" line.
856 TABLE-TEMPLATE-NAME is a set of - upto 9 - automatic
857 TABLE-CELL-STYLE-NAMEs and PARAGRAPH-STYLE-NAMEs (as defined
858 below) that is included in
859 `org-e-odt-content-template-file'.
861 TABLE-CELL-STYLE-NAME := TABLE-TEMPLATE-NAME + TABLE-CELL-TYPE +
863 PARAGRAPH-STYLE-NAME := TABLE-TEMPLATE-NAME + TABLE-CELL-TYPE +
865 TABLE-CELL-TYPE := \"FirstRow\" | \"LastColumn\" |
866 \"FirstRow\" | \"LastRow\" |
867 \"EvenRow\" | \"OddRow\" |
868 \"EvenColumn\" | \"OddColumn\" | \"\"
869 where \"+\" above denotes string concatenation.
871 TABLE-CELL-OPTIONS is an alist where each element is of the
872 form (TABLE-CELL-STYLE-SELECTOR . ON-OR-OFF).
873 TABLE-CELL-STYLE-SELECTOR := `use-first-row-styles' |
874 `use-last-row-styles' |
875 `use-first-column-styles' |
876 `use-last-column-styles' |
877 `use-banding-rows-styles' |
878 `use-banding-columns-styles' |
879 `use-first-row-styles'
880 ON-OR-OFF := `t' | `nil'
882 For example, with the following configuration
884 \(setq org-e-odt-table-styles
885 '\(\(\"TableWithHeaderRowsAndColumns\" \"Custom\"
886 \(\(use-first-row-styles . t\)
887 \(use-first-column-styles . t\)\)\)
888 \(\"TableWithHeaderColumns\" \"Custom\"
889 \(\(use-first-column-styles . t\)\)\)\)\)
891 1. A table associated with \"TableWithHeaderRowsAndColumns\"
892 style will use the following table-cell styles -
893 \"CustomFirstRowTableCell\", \"CustomFirstColumnTableCell\",
894 \"CustomTableCell\" and the following paragraph styles
895 \"CustomFirstRowTableParagraph\",
896 \"CustomFirstColumnTableParagraph\", \"CustomTableParagraph\"
899 2. A table associated with \"TableWithHeaderColumns\" style will
900 use the following table-cell styles -
901 \"CustomFirstColumnTableCell\", \"CustomTableCell\" and the
902 following paragraph styles
903 \"CustomFirstColumnTableParagraph\", \"CustomTableParagraph\"
906 Note that TABLE-TEMPLATE-NAME corresponds to the
907 \"<table:table-template>\" elements contained within
908 \"<office:styles>\". The entries (TABLE-STYLE-NAME
909 TABLE-TEMPLATE-NAME TABLE-CELL-OPTIONS) correspond to
910 \"table:template-name\" and \"table:use-first-row-styles\" etc
911 attributes of \"<table:table>\" element. Refer ODF-1.2
912 specification for more information. Also consult the
913 implementation filed under `org-e-odt-get-table-cell-styles'.
915 The TABLE-STYLE-NAME \"OrgEquation\" is used internally for
916 formatting of numbered display equations. Do not delete this
917 style from the list."
918 :group
'org-export-e-odt
921 (const :tag
"None" nil
)
922 (repeat :tag
"Table Styles"
923 (list :tag
"Table Style Specification"
924 (string :tag
"Table Style Name")
925 (string :tag
"Table Template Name")
926 (alist :options
(use-first-row-styles
928 use-first-column-styles
929 use-last-column-styles
930 use-banding-rows-styles
931 use-banding-columns-styles
)
933 :value-type
(const :tag
"True" t
))))))
937 ;;; Internal functions
941 (defun org-e-odt--date (&optional org-ts fmt
)
944 (and (stringp org-ts
)
945 (string-match org-ts-regexp0 org-ts
)
947 (org-fix-decoded-time
948 (org-parse-time-string (match-string 0 org-ts
) t
)))))
951 (fmt (format-time-string fmt time
))
952 (t (setq date
(format-time-string "%Y-%m-%dT%H:%M:%S%z" time
))
953 (format "%s:%s" (substring date
0 -
2) (substring date -
2)))))))
957 (defun org-e-odt--frame (text width height style
&optional extra
961 (if width
(format " svg:width=\"%0.2fcm\"" width
) "")
962 (if height
(format " svg:height=\"%0.2fcm\"" height
) "")
964 (format " text:anchor-type=\"%s\"" (or anchor-type
"paragraph")))))
966 "\n<draw:frame draw:style-name=\"%s\"%s>\n%s\n</draw:frame>"
969 (let ((title (get-text-property 0 :title text
))
970 (desc (get-text-property 0 :description text
)))
972 (format "<svg:title>%s</svg:title>"
973 (org-e-odt-encode-plain-text title t
)))
975 (format "<svg:desc>%s</svg:desc>"
976 (org-e-odt-encode-plain-text desc t
)))))))))
981 (defun org-e-odt--copy-image-file (path)
982 "Returns the internal name of the file"
983 (let* ((image-type (file-name-extension path
))
984 (media-type (format "image/%s" image-type
))
985 (target-dir "Images/")
987 (format "%s%04d.%s" target-dir
988 (incf org-e-odt-embedded-images-count
) image-type
)))
989 (message "Embedding %s as %s ..."
990 (substring-no-properties path
) target-file
)
992 (when (= 1 org-e-odt-embedded-images-count
)
993 (make-directory (concat org-e-odt-zip-dir target-dir
))
994 (org-e-odt-create-manifest-file-entry "" target-dir
))
996 (copy-file path
(concat org-e-odt-zip-dir target-file
) 'overwrite
)
997 (org-e-odt-create-manifest-file-entry media-type target-file
)
1000 (defun org-e-odt--image-size (file &optional user-width
1001 user-height scale dpi embed-as
)
1002 (let* ((--pixels-to-cms
1003 (function (lambda (pixels dpi
)
1004 (let ((cms-per-inch 2.54)
1005 (inches (/ pixels dpi
)))
1006 (* cms-per-inch inches
)))))
1009 (lambda (size-in-pixels dpi
)
1011 (cons (funcall --pixels-to-cms
(car size-in-pixels
) dpi
)
1012 (funcall --pixels-to-cms
(cdr size-in-pixels
) dpi
))))))
1013 (dpi (or dpi org-e-odt-pixels-per-inch
))
1014 (anchor-type (or embed-as
"paragraph"))
1015 (user-width (and (not scale
) user-width
))
1016 (user-height (and (not scale
) user-height
))
1019 (not (and user-height user-width
))
1022 (and (executable-find "identify")
1023 (let ((size-in-pixels
1024 (let ((dim (shell-command-to-string
1025 (format "identify -format \"%%w:%%h\" \"%s\""
1027 (when (string-match "\\([0-9]+\\):\\([0-9]+\\)" dim
)
1028 (cons (string-to-number (match-string 1 dim
))
1029 (string-to-number (match-string 2 dim
)))))))
1030 (funcall --size-in-cms size-in-pixels dpi
)))
1032 (let ((size-in-pixels
1033 (ignore-errors ; Emacs could be in batch mode
1035 (image-size (create-image file
) 'pixels
))))
1036 (funcall --size-in-cms size-in-pixels dpi
))
1037 ;; Use hard-coded values.
1038 (cdr (assoc-string anchor-type
1039 org-e-odt-default-image-sizes-alist
))
1041 (error "Cannot determine Image size. Aborting ..."))))
1042 (width (car size
)) (height (cdr size
)))
1045 (setq width
(* width scale
) height
(* height scale
)))
1046 ((and user-height user-width
)
1047 (setq width user-width height user-height
))
1049 (setq width
(* user-height
(/ width height
)) height user-height
))
1051 (setq height
(* user-width
(/ height width
)) width user-width
))
1053 ;; ensure that an embedded image fits comfortably within a page
1054 (let ((max-width (car org-e-odt-max-image-size
))
1055 (max-height (cdr org-e-odt-max-image-size
)))
1056 (when (or (> width max-width
) (> height max-height
))
1057 (let* ((scale1 (/ max-width width
))
1058 (scale2 (/ max-height height
))
1059 (scale (min scale1 scale2
)))
1060 (setq width
(* scale width
) height
(* scale height
)))))
1061 (cons width height
)))
1063 (defun org-e-odt-link--inline-image (element info
)
1064 "Return HTML code for an inline image.
1065 LINK is the link pointing to the inline image. INFO is a plist
1066 used as a communication channel."
1068 ((eq (org-element-type element
) 'link
)
1069 (let* ((type (org-element-property :type element
))
1070 (raw-path (org-element-property :path element
)))
1071 (cond ((member type
'("http" "https"))
1072 (concat type
":" raw-path
))
1073 ((file-name-absolute-p raw-path
)
1074 (expand-file-name raw-path
))
1076 ((member (org-element-type element
)
1077 '(latex-fragment latex-environment
))
1078 (let* ((latex-frag (org-remove-indentation
1079 (org-element-property :value element
)))
1080 (formula-link (org-e-odt-format-latex
1081 latex-frag
'dvipng info
)))
1083 (string-match "file:\\([^]]*\\)" formula-link
)
1084 (match-string 1 formula-link
))))
1085 (t (error "what is this?"))))
1086 (src-expanded (if (file-name-absolute-p src
) src
1087 (expand-file-name src
(file-name-directory
1088 (plist-get info
:input-file
)))))
1090 "\n<draw:image xlink:href=\"%s\" xlink:type=\"simple\" xlink:show=\"embed\" xlink:actuate=\"onLoad\"/>"
1091 (org-e-odt--copy-image-file src-expanded
)))
1092 ;; extract attributes from #+ATTR_ODT line.
1093 (attr-from (case (org-element-type element
)
1094 (link (org-export-get-parent-element element
))
1096 ;; convert attributes to a plist.
1097 (attr-plist (org-export-read-attribute :attr_odt attr-from
))
1098 ;; handle `:anchor', `:style' and `:attributes' properties.
1100 (car (assoc-string (plist-get attr-plist
:anchor
)
1101 '(("as-char") ("paragraph") ("page")) t
)))
1103 (and user-frame-anchor
(plist-get attr-plist
:style
)))
1105 (and user-frame-anchor
(plist-get attr-plist
:attributes
)))
1107 (list user-frame-style user-frame-attrs user-frame-anchor
))
1108 ;; (embed-as (or embed-as user-frame-anchor "paragraph"))
1110 ;; handle `:width', `:height' and `:scale' properties.
1111 (size (org-e-odt--image-size
1112 src-expanded
(plist-get attr-plist
:width
)
1113 (plist-get attr-plist
:height
)
1114 (plist-get attr-plist
:scale
) nil
;; embed-as
1117 (width (car size
)) (height (cdr size
))
1119 (case (org-element-type element
)
1120 ((org-e-odt-standalone-image-p element info
) "paragraph")
1121 (latex-fragment "as-char")
1122 (latex-environment "paragraph")
1124 (captions (org-e-odt-format-label element info
'definition
))
1125 (caption (car captions
)) (short-caption (cdr captions
))
1126 (entity (concat (and caption
"Captioned") embed-as
"Image")))
1127 (org-e-odt-format-entity entity href width height
1128 captions user-frame-params
)))
1130 ;;;; Library wrappers
1132 (defun org-e-odt--zip-extract (archive members target
)
1133 (when (atom members
) (setq members
(list members
)))
1134 (mapc (lambda (archive member target
)
1136 (let* ((--quote-file-name
1137 ;; This is shamelessly stolen from `archive-zip-extract'.
1139 (if (or (not (memq system-type
'(windows-nt ms-dos
)))
1140 (and (boundp 'w32-quote-process-args
)
1141 (null w32-quote-process-args
)))
1142 (shell-quote-argument name
)
1144 (target (funcall --quote-file-name target
))
1145 (archive (expand-file-name archive
))
1146 (archive-zip-extract
1147 (list "unzip" "-qq" "-o" "-d" target
))
1148 exit-code command-output
)
1149 (setq command-output
1151 (setq exit-code
(archive-zip-extract archive member
))
1153 (unless (zerop exit-code
)
1154 (message command-output
)
1155 (error "Extraction failed"))))
1161 (defun org-e-odt--target (text id
)
1164 (format "\n<text:bookmark-start text:name=\"OrgXref.%s\"/>" id
)
1165 (format "\n<text:bookmark text:name=\"%s\"/>" id
) text
1166 (format "\n<text:bookmark-end text:name=\"OrgXref.%s\"/>" id
))))
1170 (defun org-e-odt--textbox (text width height style
&optional
1173 (format "\n<draw:text-box %s>%s\n</draw:text-box>"
1174 (concat (format " fo:min-height=\"%0.2fcm\"" (or height
.2))
1176 (format " fo:min-width=\"%0.2fcm\"" (or width
.2))))
1178 width nil style extra anchor-type
))
1182 ;;;; Table of Contents
1184 (defun org-e-odt-begin-toc (index-title depth
)
1187 <text:table-of-content text:style-name=\"Sect2\" text:protected=\"true\" text:name=\"Table of Contents1\">
1188 <text:table-of-content-source text:outline-level=\"%d\">
1189 <text:index-title-template text:style-name=\"Contents_20_Heading\">%s</text:index-title-template>
1190 " depth index-title
)
1192 (let ((levels (number-sequence 1 10)))
1197 <text:table-of-content-entry-template text:outline-level=\"%d\" text:style-name=\"Contents_20_%d\">
1198 <text:index-entry-link-start text:style-name=\"Internet_20_link\"/>
1199 <text:index-entry-chapter/>
1200 <text:index-entry-text/>
1201 <text:index-entry-link-end/>
1202 </text:table-of-content-entry-template>
1203 " level level
)) levels
""))
1206 </text:table-of-content-source>
1209 <text:index-title text:style-name=\"Sect1\" text:name=\"Table of Contents1_Head\">
1210 <text:p text:style-name=\"Contents_20_Heading\">%s</text:p>
1214 (defun org-e-odt-end-toc ()
1217 </text:table-of-content>
1222 (defun* org-e-odt-format-toc-headline
1223 (todo todo-type priority text tags
1224 &key level section-number headline-label
&allow-other-keys
)
1226 (and org-export-with-section-numbers
1227 (concat section-number
". "))
1232 (format "<text:span text:style-name=\"%s\">%s</text:span>"
1235 (setq text
(format "<text:span text:style-name=\"%s\">%s</text:span>"
1237 (format "<text:a xlink:type=\"simple\" xlink:href=\"#%s\">%s</text:a>"
1238 headline-label text
))
1240 (defun org-e-odt-toc (depth info
)
1241 (assert (wholenump depth
))
1242 (let* ((title (org-export-translate "Table of Contents" :utf-8 info
))
1243 (headlines (org-export-collect-headlines
1244 info
(and (wholenump depth
) depth
))))
1247 (org-e-odt-begin-toc title depth
)
1250 (let* ((entry (org-e-odt-format-headline--wrap
1251 headline info
'org-e-odt-format-toc-headline
))
1252 (level (org-export-get-relative-level headline info
))
1253 (style (format "Contents_20_%d" level
)))
1254 (format "\n<text:p text:style-name=\"%s\">%s</text:p>"
1257 (org-e-odt-end-toc)))))
1260 ;;;; Document styles
1262 (defun org-e-odt-add-automatic-style (object-type &optional object-props
)
1263 "Create an automatic style of type OBJECT-TYPE with param OBJECT-PROPS.
1264 OBJECT-PROPS is (typically) a plist created by passing
1265 \"#+ATTR_ODT: \" option of the object in question to
1266 `org-e-odt-parse-block-attributes'.
1268 Use `org-e-odt-object-counters' to generate an automatic
1269 OBJECT-NAME and STYLE-NAME. If OBJECT-PROPS is non-nil, add a
1270 new entry in `org-e-odt-automatic-styles'. Return (OBJECT-NAME
1272 (assert (stringp object-type
))
1273 (let* ((object (intern object-type
))
1275 (seqno (1+ (or (plist-get org-e-odt-object-counters seqvar
) 0)))
1276 (object-name (format "%s%d" object-type seqno
)) style-name
)
1277 (setq org-e-odt-object-counters
1278 (plist-put org-e-odt-object-counters seqvar seqno
))
1280 (setq style-name
(format "Org%s" object-name
))
1281 (setq org-e-odt-automatic-styles
1282 (plist-put org-e-odt-automatic-styles object
1283 (append (list (list style-name object-props
))
1284 (plist-get org-e-odt-automatic-styles object
)))))
1285 (cons object-name style-name
)))
1288 ;;;; Caption and Labels
1291 (defun org-e-odt--wrap-label (element output
)
1292 "Wrap label associated to ELEMENT around OUTPUT, if appropriate.
1293 This function shouldn't be used for floats. See
1294 `org-e-odt--caption/label-string'."
1295 ;; (let ((label (org-element-property :name element)))
1296 ;; (if (or (not output) (not label) (string= output "") (string= label ""))
1298 ;; (concat (format "\\label{%s}\n" label) output)))
1302 (defun org-e-odt--caption/label-string
(caption label info
)
1303 "Return caption and label HTML string for floats.
1305 CAPTION is a cons cell of secondary strings, the car being the
1306 standard caption and the cdr its short form. LABEL is a string
1307 representing the label. INFO is a plist holding contextual
1310 If there's no caption nor label, return the empty string.
1312 For non-floats, see `org-e-odt--wrap-label'."
1313 (setq label nil
) ;; FIXME
1315 (let ((label-str (if label
(format "\\label{%s}" label
) "")))
1317 ((and (not caption
) (not label
)) "")
1318 ((not caption
) (format "\\label{%s}\n" label
))
1319 ;; Option caption format with short name.
1321 (format "\\caption[%s]{%s%s}\n"
1322 (org-export-data (cdr caption
) info
)
1324 (org-export-data (car caption
) info
)))
1325 ;; Standard caption format.
1326 ;; (t (format "\\caption{%s%s}\n"
1328 ;; (org-export-data (car caption) info)))
1329 (t (org-export-data (car caption
) info
)))))
1333 (defun org-e-odt--checkbox (item)
1334 "Return check-box string associated to ITEM."
1335 (let ((checkbox (org-element-property :checkbox item
)))
1336 (if (not checkbox
) ""
1337 (format "<text:span text:style-name=\"%s\">%s</text:span>"
1338 "OrgCode" (case checkbox
1339 (on "[✓] ") ; CHECK MARK
1345 (defun org-e-odt-template (contents info
)
1346 "Return complete document string after HTML conversion.
1347 CONTENTS is the transcoded contents string. RAW-DATA is the
1348 original parsed data. INFO is a plist holding export options."
1350 (let ((title (org-export-data (plist-get info
:title
) info
))
1351 (author (let ((author (plist-get info
:author
)))
1352 (if (not author
) "" (org-export-data author info
))))
1353 (date (org-e-odt--date
1354 (org-export-data (plist-get info
:date
) info
)))
1355 (email (plist-get info
:email
))
1356 (keywords (plist-get info
:keywords
))
1357 (description (plist-get info
:description
)))
1360 "<?xml version=\"1.0\" encoding=\"UTF-8\"?>
1361 <office:document-meta
1362 xmlns:office=\"urn:oasis:names:tc:opendocument:xmlns:office:1.0\"
1363 xmlns:xlink=\"http://www.w3.org/1999/xlink\"
1364 xmlns:dc=\"http://purl.org/dc/elements/1.1/\"
1365 xmlns:meta=\"urn:oasis:names:tc:opendocument:xmlns:meta:1.0\"
1366 xmlns:ooo=\"http://openoffice.org/2004/office\"
1367 office:version=\"1.2\">
1369 (format "<dc:creator>%s</dc:creator>\n" author
)
1370 (format "<meta:initial-creator>%s</meta:initial-creator>\n" author
)
1371 (format "<dc:date>%s</dc:date>\n" date
)
1372 (format "<meta:creation-date>%s</meta:creation-date>\n" date
)
1373 (format "<meta:generator>%s</meta:generator>\n"
1374 (let ((creator-info (plist-get info
:with-creator
)))
1375 (if (or (not creator-info
) (eq creator-info
'comment
)) ""
1376 (plist-get info
:creator
))))
1377 (format "<meta:keyword>%s</meta:keyword>\n" keywords
)
1378 (format "<dc:subject>%s</dc:subject>\n" description
)
1379 (format "<dc:title>%s</dc:title>\n" title
)
1381 " </office:meta>\n" "</office:document-meta>")
1382 nil
(concat org-e-odt-zip-dir
"meta.xml"))
1383 ;; Add meta.xml in to manifest.
1384 (org-e-odt-create-manifest-file-entry "text/xml" "meta.xml"))
1386 ;; Update styles file.
1387 ;; Copy styles.xml. Also dump htmlfontify styles, if there is any.
1388 ;; Write styles file.
1389 (let* ((styles-file (plist-get info
:odt-styles-file
))
1390 (styles-file (and styles-file
(read (org-trim styles-file
))))
1391 ;; Non-availability of styles.xml is not a critical
1392 ;; error. For now throw an error purely for aesthetic
1394 (styles-file (or styles-file
1395 org-e-odt-styles-file
1396 (expand-file-name "OrgOdtStyles.xml"
1397 org-e-odt-styles-dir
)
1398 (error "org-e-odt: Missing styles file?"))))
1400 ((listp styles-file
)
1401 (let ((archive (nth 0 styles-file
))
1402 (members (nth 1 styles-file
)))
1403 (org-e-odt--zip-extract archive members org-e-odt-zip-dir
)
1406 (when (org-file-image-p member
)
1407 (let* ((image-type (file-name-extension member
))
1408 (media-type (format "image/%s" image-type
)))
1409 (org-e-odt-create-manifest-file-entry media-type member
))))
1411 ((and (stringp styles-file
) (file-exists-p styles-file
))
1412 (let ((styles-file-type (file-name-extension styles-file
)))
1414 ((string= styles-file-type
"xml")
1415 (copy-file styles-file
(concat org-e-odt-zip-dir
"styles.xml") t
))
1416 ((member styles-file-type
'("odt" "ott"))
1417 (org-e-odt--zip-extract styles-file
"styles.xml" org-e-odt-zip-dir
)))))
1419 (error (format "Invalid specification of styles.xml file: %S"
1420 org-e-odt-styles-file
))))
1422 ;; create a manifest entry for styles.xml
1423 (org-e-odt-create-manifest-file-entry "text/xml" "styles.xml")
1425 ;; FIXME: Who is opening an empty styles.xml before this point?
1426 (with-current-buffer
1427 (find-file-noselect (concat org-e-odt-zip-dir
"styles.xml") t
)
1430 ;; Write custom styles for source blocks
1431 ;; Save STYLES used for colorizing of source blocks.
1432 ;; Update styles.xml with styles that were collected as part of
1433 ;; `org-e-odt-hfy-face-to-css' callbacks.
1434 (let ((styles (mapconcat (lambda (style) (format " %s\n" (cddr style
)))
1435 hfy-user-sheet-assoc
"")))
1437 (goto-char (point-min))
1438 (when (re-search-forward "</office:styles>" nil t
)
1439 (goto-char (match-beginning 0))
1440 (insert "\n<!-- Org Htmlfontify Styles -->\n" styles
"\n"))))
1442 ;; Update styles.xml - take care of outline numbering
1444 ;; Don't make automatic backup of styles.xml file. This setting
1445 ;; prevents the backed-up styles.xml file from being zipped in to
1446 ;; odt file. This is more of a hackish fix. Better alternative
1447 ;; would be to fix the zip command so that the output odt file
1448 ;; includes only the needed files and excludes any auto-generated
1449 ;; extra files like backups and auto-saves etc etc. Note that
1450 ;; currently the zip command zips up the entire temp directory so
1451 ;; that any auto-generated files created under the hood ends up in
1452 ;; the resulting odt file.
1453 (set (make-local-variable 'backup-inhibited
) t
)
1455 ;; Outline numbering is retained only upto LEVEL.
1456 ;; To disable outline numbering pass a LEVEL of 0.
1458 (goto-char (point-min))
1460 "<text:outline-level-style\\([^>]*\\)text:level=\"\\([^\"]*\\)\"\\([^>]*\\)>")
1462 "<text:outline-level-style\\1text:level=\"\\2\" style:num-format=\"\">"))
1463 (while (re-search-forward regex nil t
)
1464 (unless (let ((sec-num (plist-get info
:section-numbers
))
1465 (level (string-to-number (match-string 2))))
1466 (if (wholenump sec-num
) (<= level sec-num
) sec-num
))
1467 (replace-match replacement t nil
))))
1469 ;; Update content.xml.
1471 (insert-file-contents
1472 (or org-e-odt-content-template-file
1473 (expand-file-name "OrgOdtContentTemplate.xml"
1474 org-e-odt-styles-dir
)))
1475 ;; Write automatic styles.
1476 ;; - Position the cursor.
1477 (goto-char (point-min))
1478 (re-search-forward " </office:automatic-styles>" nil t
)
1479 (goto-char (match-beginning 0))
1480 ;; - Dump automatic table styles
1481 (loop for
(style-name props
) in
1482 (plist-get org-e-odt-automatic-styles
'Table
) do
1483 (when (setq props
(or (plist-get props
:rel-width
) 96))
1484 (insert (format org-e-odt-table-style-format style-name props
))))
1485 ;; Update display level.
1486 ;; - Remove existing sequence decls. Also position the cursor.
1487 (goto-char (point-min))
1488 (when (re-search-forward "<text:sequence-decls" nil t
)
1489 (delete-region (match-beginning 0)
1490 (re-search-forward "</text:sequence-decls>" nil nil
)))
1491 ;; Update sequence decls according to user preference.
1494 "\n<text:sequence-decls>\n%s\n</text:sequence-decls>"
1498 "<text:sequence-decl text:display-outline-level=\"%d\" text:name=\"%s\"/>"
1499 org-e-odt-display-outline-level
(nth 1 x
)))
1500 org-e-odt-category-map-alist
"\n")))
1501 ;; Position the cursor to document body.
1502 (goto-char (point-min))
1503 (re-search-forward "</office:text>" nil nil
)
1504 (goto-char (match-beginning 0))
1506 ;; Preamble - Title, Author, Date etc.
1508 (let* ((title (org-export-data (plist-get info
:title
) info
))
1509 (author (and (plist-get info
:with-author
)
1510 (let ((auth (plist-get info
:author
)))
1511 (and auth
(org-export-data auth info
)))))
1512 (date (org-export-data (plist-get info
:date
) info
))
1513 (iso-date (org-e-odt--date date
))
1514 (date (org-e-odt--date date
"%d %b %Y"))
1515 (email (plist-get info
:email
))
1516 ;; switch on or off above vars based on user settings
1517 (author (and (plist-get info
:with-author
) (or author email
)))
1518 ;; (date (and (plist-get info :time-stamp-file) date))
1519 (email (and (plist-get info
:with-email
) email
)))
1524 (format "\n<text:p text:style-name=\"%s\">%s</text:p>"
1525 "OrgTitle" (format "\n<text:title>%s</text:title>" title
))
1527 "\n<text:p text:style-name=\"OrgTitle\"/>"))
1529 ((and author
(not email
))
1532 (format "\n<text:p text:style-name=\"%s\">%s</text:p>"
1534 (format "<text:initial-creator>%s</text:initial-creator>" author
))
1536 "\n<text:p text:style-name=\"OrgSubtitle\"/>"))
1541 "\n<text:p text:style-name=\"%s\">%s</text:p>"
1544 "<text:a xlink:type=\"simple\" xlink:href=\"%s\">%s</text:a>"
1545 (concat "mailto:" email
)
1546 (format "<text:initial-creator>%s</text:initial-creator>" author
)))
1548 "\n<text:p text:style-name=\"OrgSubtitle\"/>")))
1553 "\n<text:p text:style-name=\"%s\">%s</text:p>"
1556 "\n<text:date style:data-style-name=\"%s\" text:date-value=\"%s\">%s</text:date>"
1558 "OrgDate" iso-date date
))
1560 "<text:p text:style-name=\"OrgSubtitle\"/>")))))
1561 ;; Table of Contents
1562 (let* ((with-toc (plist-get info
:with-toc
))
1563 (depth (and with-toc
(if (wholenump with-toc
)
1565 (plist-get info
:headline-levels
)))))
1566 (when depth
(insert (or (org-e-odt-toc depth info
) ""))))
1570 (buffer-substring-no-properties (point-min) (point-max))))
1574 ;;; Transcode Functions
1578 (defun org-e-odt-bold (bold contents info
)
1579 "Transcode BOLD from Org to ODT.
1580 CONTENTS is the text with bold markup. INFO is a plist holding
1581 contextual information."
1582 (format "<text:span text:style-name=\"%s\">%s</text:span>"
1588 (defun org-e-odt-center-block (center-block contents info
)
1589 "Transcode a CENTER-BLOCK element from Org to ODT.
1590 CONTENTS holds the contents of the center block. INFO is a plist
1591 holding contextual information."
1592 (org-e-odt--wrap-label center-block contents
))
1597 (defun org-e-odt-clock (clock contents info
)
1598 "Transcode a CLOCK element from Org to ODT.
1599 CONTENTS is nil. INFO is a plist used as a communication
1601 (format "<text:span text:style-name=\"%s\">%s</text:span>"
1602 "OrgTimestampWrapper"
1604 (format "<text:span text:style-name=\"%s\">%s</text:span>"
1605 "OrgTimestampKeyword" org-clock-string
)
1606 (format "<text:span text:style-name=\"%s\">%s</text:span>"
1608 (concat (org-translate-time
1609 (org-element-property :value clock
))
1610 (let ((time (org-element-property :time clock
)))
1611 (and time
(format " (%s)" time
))))))))
1616 (defun org-e-odt-code (code contents info
)
1617 "Transcode a CODE object from Org to ODT.
1618 CONTENTS is nil. INFO is a plist used as a communication
1620 (format "<text:span text:style-name=\"%s\">%s</text:span>"
1621 "OrgCode" (org-element-property :value code
)))
1626 ;; Comments are ignored.
1631 ;; Comment Blocks are ignored.
1636 (defun org-e-odt-drawer (drawer contents info
)
1637 "Transcode a DRAWER element from Org to ODT.
1638 CONTENTS holds the contents of the block. INFO is a plist
1639 holding contextual information."
1640 (let* ((name (org-element-property :drawer-name drawer
))
1641 (output (if (functionp org-e-odt-format-drawer-function
)
1642 (funcall org-e-odt-format-drawer-function
1644 ;; If there's no user defined function: simply
1645 ;; display contents of the drawer.
1647 (org-e-odt--wrap-label drawer output
)))
1652 (defun org-e-odt-dynamic-block (dynamic-block contents info
)
1653 "Transcode a DYNAMIC-BLOCK element from Org to ODT.
1654 CONTENTS holds the contents of the block. INFO is a plist
1655 holding contextual information. See `org-export-data'."
1656 (org-e-odt--wrap-label dynamic-block contents
))
1661 (defun org-e-odt-entity (entity contents info
)
1662 "Transcode an ENTITY object from Org to ODT.
1663 CONTENTS are the definition itself. INFO is a plist holding
1664 contextual information."
1665 ;; (let ((ent (org-element-property :latex entity)))
1666 ;; (if (org-element-property :latex-math-p entity)
1667 ;; (format "$%s$" ent)
1669 (org-element-property :utf-8 entity
))
1674 (defun org-e-odt-example-block (example-block contents info
)
1675 "Transcode a EXAMPLE-BLOCK element from Org to ODT.
1676 CONTENTS is nil. INFO is a plist holding contextual information."
1677 (org-e-odt--wrap-label
1678 example-block
(org-e-odt-format-code example-block info
)))
1683 (defun org-e-odt-export-snippet (export-snippet contents info
)
1684 "Transcode a EXPORT-SNIPPET object from Org to ODT.
1685 CONTENTS is nil. INFO is a plist holding contextual information."
1686 (when (eq (org-export-snippet-backend export-snippet
) 'e-odt
)
1687 (org-element-property :value export-snippet
)))
1692 (defun org-e-odt-export-block (export-block contents info
)
1693 "Transcode a EXPORT-BLOCK element from Org to ODT.
1694 CONTENTS is nil. INFO is a plist holding contextual information."
1695 (when (string= (org-element-property :type export-block
) "ODT")
1696 (org-remove-indentation (org-element-property :value export-block
))))
1701 (defun org-e-odt-fixed-width (fixed-width contents info
)
1702 "Transcode a FIXED-WIDTH element from Org to ODT.
1703 CONTENTS is nil. INFO is a plist holding contextual information."
1704 (org-e-odt--wrap-label
1705 fixed-width
(org-e-odt-do-format-code
1706 (org-element-property :value fixed-width
))))
1709 ;;;; Footnote Definition
1711 ;; Footnote Definitions are ignored.
1714 ;;;; Footnote Reference
1716 (defun org-e-odt-footnote-reference (footnote-reference contents info
)
1717 "Transcode a FOOTNOTE-REFERENCE element from Org to ODT.
1718 CONTENTS is nil. INFO is a plist holding contextual information."
1719 (let ((--format-footnote-definition
1722 (setq n
(format "%d" n
))
1723 (let ((id (concat "fn" n
))
1724 (note-class "footnote")
1725 (par-style "Footnote"))
1727 "<text:note text:id=\"%s\" text:note-class=\"%s\">%s</text:note>"
1730 (format "<text:note-citation>%s</text:note-citation>" n
)
1731 (format "<text:note-body>%s</text:note-body>" def
)))))))
1732 (--format-footnote-reference
1735 (setq n
(format "%d" n
))
1736 (let ((note-class "footnote")
1738 (ref-name (concat "fn" n
)))
1740 "<text:span text:style-name=\"%s\">%s</text:span>"
1742 (format "<text:note-ref text:note-class=\"%s\" text:reference-format=\"%s\" text:ref-name=\"%s\">%s</text:note-ref>"
1743 note-class ref-format ref-name n
)))))))
1745 ;; Insert separator between two footnotes in a row.
1746 (let ((prev (org-export-get-previous-element footnote-reference info
)))
1747 (and (eq (org-element-type prev
) 'footnote-reference
)
1748 (format "<text:span text:style-name=\"%s\">%s</text:span>"
1749 "OrgSuperscript" ",")))
1750 ;; Trancode footnote reference.
1751 (let ((n (org-export-get-footnote-number footnote-reference info
)))
1753 ((not (org-export-footnote-first-reference-p footnote-reference info
))
1754 (funcall --format-footnote-reference n
))
1755 ;; Inline definitions are secondary strings.
1756 ;; Non-inline footnotes definitions are full Org data.
1758 (let* ((raw (org-export-get-footnote-definition footnote-reference
1760 (def (let ((def (org-trim (org-export-data raw info
))))
1761 (if (eq (org-element-type raw
) 'org-data
) def
1762 (format "\n<text:p text:style-name=\"%s\">%s</text:p>"
1764 (funcall --format-footnote-definition n def
))))))))
1769 (defun* org-e-odt-format-headline
1770 (todo todo-type priority text tags
1771 &key level section-number headline-label
&allow-other-keys
)
1776 (let ((style (if (member todo org-done-keywords
) "OrgDone" "OrgTodo")))
1777 (format "<text:span text:style-name=\"%s\">%s</text:span>"
1783 (concat "<text:tab/>"
1784 (format "<text:span text:style-name=\"%s\">%s</text:span>"
1785 "OrgTag" (mapconcat 'org-trim tags
" : "))))))
1787 (defun org-e-odt-format-headline--wrap (headline info
1788 &optional format-function
1790 "Transcode an HEADLINE element from Org to ODT.
1791 CONTENTS holds the contents of the headline. INFO is a plist
1792 holding contextual information."
1793 (let* ((level (+ (org-export-get-relative-level headline info
)))
1794 (headline-number (org-export-get-headline-number headline info
))
1795 (section-number (and (org-export-numbered-headline-p headline info
)
1796 (mapconcat 'number-to-string
1797 headline-number
".")))
1798 (todo (and (plist-get info
:with-todo-keywords
)
1799 (let ((todo (org-element-property :todo-keyword headline
)))
1800 (and todo
(org-export-data todo info
)))))
1801 (todo-type (and todo
(org-element-property :todo-type headline
)))
1802 (priority (and (plist-get info
:with-priority
)
1803 (org-element-property :priority headline
)))
1804 (text (org-export-data (org-element-property :title headline
) info
))
1805 (tags (and (plist-get info
:with-tags
)
1806 (org-export-get-tags headline info
)))
1807 (headline-label (concat "sec-" (mapconcat 'number-to-string
1808 headline-number
"-")))
1809 (format-function (cond
1810 ((functionp format-function
) format-function
)
1811 ((functionp org-e-odt-format-headline-function
)
1813 (lambda (todo todo-type priority text tags
1815 (funcall org-e-odt-format-headline-function
1816 todo todo-type priority text tags
))))
1817 (t 'org-e-odt-format-headline
))))
1818 (apply format-function
1819 todo todo-type priority text tags
1820 :headline-label headline-label
:level level
1821 :section-number section-number extra-keys
)))
1823 (defun org-e-odt-headline (headline contents info
)
1824 "Transcode an HEADLINE element from Org to ODT.
1825 CONTENTS holds the contents of the headline. INFO is a plist
1826 holding contextual information."
1827 ;; Case 1: This is a footnote section: ignore it.
1828 (unless (org-element-property :footnote-section-p headline
)
1829 (let* ((text (org-export-data (org-element-property :title headline
) info
))
1830 ;; Create the headline text.
1831 (full-text (org-e-odt-format-headline--wrap headline info
))
1832 ;; Get level relative to current parsed data.
1833 (level (org-export-get-relative-level headline info
))
1834 ;; Get canonical label for the headline.
1835 (id (concat "sec-" (mapconcat 'number-to-string
1836 (org-export-get-headline-number
1837 headline info
) "-")))
1838 ;; Get user-specified labels for the headline.
1839 (extra-ids (list (org-element-property :custom-id headline
)
1840 (org-element-property :id headline
)))
1843 (mapconcat (lambda (x)
1845 (let ((x (if (org-uuidgen-p x
) (concat "ID-" x
) x
)))
1847 "" (org-export-solidify-link-text x
)))))
1850 (anchored-title (org-e-odt--target full-text id
)))
1852 ;; Case 2. This is a deep sub-tree: export it as a list item.
1853 ;; Also export as items headlines for which no section
1854 ;; format has been found.
1855 ((org-export-low-level-p headline info
)
1856 ;; Build the real contents of the sub-tree.
1858 (and (org-export-first-sibling-p headline info
)
1859 (format "\n<text:list text:style-name=\"%s\" %s>"
1860 ;; Choose style based on list type.
1861 (if (org-export-numbered-headline-p headline info
)
1862 "OrgNumberedList" "OrgBulletedList")
1863 ;; If top-level list, re-start numbering. Otherwise,
1864 ;; continue numbering.
1865 (format "text:continue-numbering=\"%s\""
1866 (let* ((parent (org-export-get-parent-headline
1869 (org-export-low-level-p parent info
))
1871 (let* ((headline-has-table-p
1872 (let* ((headline-contents (org-element-contents headline
))
1873 (element (and (eq 'section
1875 (car headline-contents
)))
1876 (car headline-contents
))))
1877 (loop for el in
(org-element-contents element
)
1878 thereis
(eq (org-element-type el
) 'table
))))
1880 (format "\n<text:list-item>\n%s\n%s"
1882 (format "\n<text:p text:style-name=\"%s\">%s</text:p>"
1884 (concat extra-targets anchored-title
))
1886 (if headline-has-table-p
1887 "</text:list-header>"
1888 "</text:list-item>")))
1889 (and (org-export-last-sibling-p headline info
)
1891 ;; Case 3. Standard headline. Export it as a section.
1895 "\n<text:h text:style-name=\"%s\" text:outline-level=\"%s\">%s</text:h>"
1896 (format "Heading_20_%s" level
)
1898 (concat extra-targets anchored-title
))
1902 ;;;; Horizontal Rule
1904 (defun org-e-odt-horizontal-rule (horizontal-rule contents info
)
1905 "Transcode an HORIZONTAL-RULE object from Org to ODT.
1906 CONTENTS is nil. INFO is a plist holding contextual information."
1907 (org-e-odt--wrap-label
1909 (format "\n<text:p text:style-name=\"%s\">%s</text:p>"
1910 "Horizontal_20_Line" "")))
1913 ;;;; Inline Babel Call
1915 ;; Inline Babel Calls are ignored.
1918 ;;;; Inline Src Block
1920 (defun org-e-odt--find-verb-separator (s)
1921 "Return a character not used in string S.
1922 This is used to choose a separator for constructs like \\verb."
1923 (let ((ll "~,./?;':\"|!@#%^&-_=+abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ<>()[]{}"))
1924 (loop for c across ll
1925 when
(not (string-match (regexp-quote (char-to-string c
)) s
))
1926 return
(char-to-string c
))))
1928 (defun org-e-odt-inline-src-block (inline-src-block contents info
)
1929 "Transcode an INLINE-SRC-BLOCK element from Org to ODT.
1930 CONTENTS holds the contents of the item. INFO is a plist holding
1931 contextual information."
1932 (let* ((org-lang (org-element-property :language inline-src-block
))
1933 (code (org-element-property :value inline-src-block
))
1934 (separator (org-e-odt--find-verb-separator code
)))
1940 (defun org-e-odt-inlinetask (inlinetask contents info
)
1941 "Transcode an INLINETASK element from Org to ODT.
1942 CONTENTS holds the contents of the block. INFO is a plist
1943 holding contextual information."
1945 ;; If `org-e-odt-format-inlinetask-function' is provided, call it
1946 ;; with appropriate arguments.
1947 ((functionp org-e-odt-format-inlinetask-function
)
1948 (let ((format-function
1950 (lambda (todo todo-type priority text tags
1951 &key contents
&allow-other-keys
)
1952 (funcall org-e-odt-format-inlinetask-function
1953 todo todo-type priority text tags contents
)))))
1954 (org-e-odt-format-headline--wrap
1955 inlinetask info format-function
:contents contents
)))
1956 ;; Otherwise, use a default template.
1957 (t (org-e-odt--wrap-label
1959 (format "\n<text:p text:style-name=\"%s\">%s</text:p>"
1963 (format "\n<text:p text:style-name=\"%s\">%s</text:p>"
1964 "OrgInlineTaskHeading"
1965 (org-e-odt-format-headline--wrap
1968 nil nil
"OrgInlineTaskFrame" " style:rel-width=\"100%\""))))))
1972 (defun org-e-odt-italic (italic contents info
)
1973 "Transcode ITALIC from Org to ODT.
1974 CONTENTS is the text with italic markup. INFO is a plist holding
1975 contextual information."
1976 (format "<text:span text:style-name=\"%s\">%s</text:span>"
1977 "Emphasis" contents
))
1982 (defun org-e-odt-item (item contents info
)
1983 "Transcode an ITEM element from Org to ODT.
1984 CONTENTS holds the contents of the item. INFO is a plist holding
1985 contextual information."
1986 (let* ((plain-list (org-export-get-parent item
))
1987 (type (org-element-property :type plain-list
))
1988 (counter (org-element-property :counter item
))
1989 (tag (let ((tag (org-element-property :tag item
)))
1991 (concat (org-e-odt--checkbox item
)
1992 (org-export-data tag info
))))))
1994 ((ordered unordered descriptive-1 descriptive-2
)
1995 (format "\n<text:list-item>\n%s\n%s"
1997 (let* ((--element-has-a-table-p
1999 (lambda (element info
)
2000 (loop for el in
(org-element-contents element
)
2001 thereis
(eq (org-element-type el
) 'table
))))))
2003 ((funcall --element-has-a-table-p item info
)
2004 "</text:list-header>")
2005 (t "</text:list-item>")))))
2006 (t (error "Unknown list type: %S" type
)))))
2010 (defun org-e-odt-keyword (keyword contents info
)
2011 "Transcode a KEYWORD element from Org to ODT.
2012 CONTENTS is nil. INFO is a plist holding contextual information."
2013 (let ((key (org-element-property :key keyword
))
2014 (value (org-element-property :value keyword
)))
2016 ((string= key
"ODT") value
)
2017 ((string= key
"INDEX") (format "\\index{%s}" value
))
2018 ((string= key
"TARGET") nil
; FIXME
2019 ;; (format "\\label{%s}" (org-export-solidify-link-text value))
2021 ((string= key
"toc")
2022 (let ((value (downcase value
)))
2024 ((string-match "\\<headlines\\>" value
)
2025 (let ((depth (or (and (string-match "[0-9]+" value
)
2026 (string-to-number (match-string 0 value
)))
2027 (plist-get info
:with-toc
))))
2028 (when (wholenump depth
) (org-e-odt-toc depth info
))))
2029 ((string= "tables" value
) "FIXME")
2030 ((string= "figures" value
) "FIXME")
2031 ((string= "listings" value
)
2033 ;; At the moment, src blocks with a caption are wrapped
2034 ;; into a figure environment.
2038 ;;;; Latex Environment
2041 (eval-after-load 'org-odt
2042 '(ad-deactivate 'org-format-latex-as-mathml
))
2044 ;; (defadvice org-format-latex-as-mathml ; FIXME
2045 ;; (after org-e-odt-protect-latex-fragment activate)
2046 ;; "Encode LaTeX fragment as XML.
2047 ;; Do this when translation to MathML fails."
2048 ;; (when (or (not (> (length ad-return-value) 0))
2049 ;; (get-text-property 0 'org-protected ad-return-value))
2050 ;; (setq ad-return-value
2051 ;; (org-propertize (org-e-odt-encode-plain-text (ad-get-arg 0))
2052 ;; 'org-protected t))))
2054 (defun org-e-odt-format-latex (latex-frag processing-type info
)
2055 (let* ((prefix (case processing-type
2057 (mathml "ltxmathml/")))
2058 (input-file (plist-get info
:input-file
))
2060 (concat prefix
(file-name-sans-extension
2061 (file-name-nondirectory input-file
))))
2062 (cache-dir (file-name-directory input-file
))
2063 (display-msg (case processing-type
2064 (dvipng "Creating LaTeX Image...")
2065 (mathml "Creating MathML snippet..."))))
2068 (org-format-latex cache-subdir cache-dir nil display-msg
2069 nil nil processing-type
)
2072 (defun org-e-odt-latex-environment (latex-environment contents info
)
2073 "Transcode a LATEX-ENVIRONMENT element from Org to ODT.
2074 CONTENTS is nil. INFO is a plist holding contextual information."
2075 (org-e-odt--wrap-label
2078 (org-remove-indentation
2079 (org-element-property :value latex-environment
)))
2080 (processing-type (plist-get info
:LaTeX-fragments
))
2081 (caption (org-element-property :caption latex-environment
))
2082 (short-caption (and (cdr caption
)
2083 (org-export-data (cdr caption
) info
)))
2084 (caption (and (car caption
) (org-export-data (car caption
) info
)))
2085 (label (org-element-property :name latex-environment
))
2087 (label (org-element-property :name latex-environment
)))
2089 (when (memq processing-type
'(t mathjax
))
2090 (unless (and (fboundp 'org-format-latex-mathml-available-p
)
2091 (org-format-latex-mathml-available-p))
2092 (message "LaTeX to MathML converter not available. Trying dvinpng...")
2093 (setq processing-type
'dvipng
)))
2095 (when (eq processing-type
'dvipng
)
2096 (unless (and (org-check-external-command "latex" "" t
)
2097 (org-check-external-command "dvipng" "" t
))
2098 (message "LaTeX to PNG converter not available. Using verbatim.")
2099 (setq processing-type
'verbatim
)))
2101 (case processing-type
2103 (org-e-odt-format-formula latex-environment info
))
2105 (format "\n<text:p text:style-name=\"%s\">%s</text:p>"
2107 (org-e-odt-link--inline-image latex-environment info
)))
2108 (t (org-e-odt-do-format-code latex-frag
))))))
2114 ;; (when latex-frag ; FIXME
2115 ;; (setq href (org-propertize href :title "LaTeX Fragment"
2116 ;; :description latex-frag)))
2118 ;; provide descriptions
2120 (defun org-e-odt-latex-fragment (latex-fragment contents info
)
2121 "Transcode a LATEX-FRAGMENT object from Org to ODT.
2122 CONTENTS is nil. INFO is a plist holding contextual information."
2123 (let* ((latex-frag (org-element-property :value latex-fragment
))
2124 (processing-type (plist-get info
:LaTeX-fragments
)))
2126 ((member processing-type
'(t mathjax
))
2127 (org-e-odt-format-formula latex-fragment info
))
2128 ((eq processing-type
'dvipng
)
2129 (org-e-odt-link--inline-image latex-fragment info
))
2130 (t (org-e-odt-encode-plain-text latex-frag t
)))))
2135 (defun org-e-odt-line-break (line-break contents info
)
2136 "Transcode a LINE-BREAK object from Org to ODT.
2137 CONTENTS is nil. INFO is a plist holding contextual information."
2138 "<text:line-break/>\n")
2145 ;;;; Links :: Generic
2147 ;; (org-lparse-link-description-is-image
2148 ;; (format "\n<draw:a xlink:type=\"simple\" xlink:href=\"%s\">\n%s\n</draw:a>"
2151 ;;;; Links :: Label references
2153 (defun org-e-odt-enumerate-element (element info
&optional predicate n
)
2154 (let* ((--numbered-parent-headline-at-<=-n
2156 (lambda (element n info
)
2157 (loop for x in
(org-export-get-genealogy element
)
2158 thereis
(and (eq (org-element-type x
) 'headline
)
2159 (<= (org-export-get-relative-level x info
) n
)
2160 (org-export-numbered-headline-p x info
)
2164 (lambda (element scope info
&optional predicate
)
2167 (or scope
(plist-get info
:parse-tree
))
2168 (org-element-type element
)
2170 (and (or (not predicate
) (funcall predicate el info
))
2174 info
'first-match
)))))
2175 (scope (funcall --numbered-parent-headline-at-
<=-n
2176 element
(or n org-e-odt-display-outline-level
) info
))
2177 (ordinal (funcall --enumerate element scope info predicate
))
2182 (mapconcat 'number-to-string
2183 (org-export-get-headline-number scope info
) "."))
2187 (number-to-string ordinal
))))
2190 (defun org-e-odt-format-label (element info op
)
2191 (let* ((caption-from
2192 (case (org-element-type element
)
2193 (link (org-export-get-parent-element element
))
2195 ;; get label and caption.
2196 (label (org-element-property :name caption-from
))
2197 (caption (org-element-property :caption caption-from
))
2198 (short-caption (cdr caption
))
2199 ;; transcode captions.
2200 (caption (and (car caption
) (org-export-data (car caption
) info
)))
2201 (short-caption (and short-caption
2202 (org-export-data short-caption info
))))
2203 (when (or label caption
)
2204 (let* ((default-category
2206 ((eq (org-element-type element
) 'table
)
2208 ((org-e-odt-standalone-image-p element info
)
2210 ((member (org-element-type element
)
2211 '(latex-environment latex-fragment
))
2212 (let ((processing-type (plist-get info
:LaTeX-fragments
)))
2214 ((eq processing-type
'dvipng
) "__DvipngImage__")
2215 ((eq processing-type
'mathjax
) "__MathFormula__")
2216 ((eq processing-type
't
) "__MathFormula__")
2217 (t (error "Handle LaTeX:verbatim")))))
2218 ((eq (org-element-type element
) 'src-block
)
2220 (t (error "Handle enumeration of %S" element
))))
2223 ((member (org-element-type element
)
2224 '(table latex-environment src-block
))
2226 ((org-e-odt-standalone-image-p element info
)
2227 'org-e-odt-standalone-image-p
)
2228 (t (error "Handle enumeration of %S" element
))))
2229 (seqno (org-e-odt-enumerate-element
2230 element info predicate
)) ; FIXME
2231 ;; handle label props.
2232 (label-props (assoc default-category org-e-odt-category-map-alist
))
2233 ;; identify opendocument counter
2234 (counter (nth 1 label-props
))
2235 ;; identify label style
2236 (label-style (nth 2 label-props
))
2237 ;; retrieve localized category sting
2238 (category (org-export-translate (nth 3 label-props
) :utf-8 info
)))
2241 ;; assign an internal label, if user has not provided one
2242 (setq label
(or label
(format "%s-%s" default-category seqno
)))
2243 (setq label
(org-export-solidify-link-text label
))
2247 (cadr (assoc-string label-style org-e-odt-label-styles t
))
2250 "<text:sequence text:ref-name=\"%s\" text:name=\"%s\" text:formula=\"ooow:%s+1\" style:num-format=\"1\">%s</text:sequence>"
2251 label counter counter seqno
))
2252 (?c .
,(or caption
""))))
2256 (setq label
(org-export-solidify-link-text label
))
2257 (let* ((fmt (cddr (assoc-string label-style org-e-odt-label-styles t
)))
2260 (format "<text:sequence-ref text:reference-format=\"%s\" text:ref-name=\"%s\">%s</text:sequence-ref>"
2261 fmt1 label
(format-spec fmt2
`((?e .
,category
)
2263 (t (error "Unknow %S on label" op
)))))))
2265 ;;;; Links :: Math formula
2267 (defun org-e-odt-format-formula (element info
)
2269 ((eq (org-element-type element
) 'link
) ; FIXME
2270 (let* ((type (org-element-property :type element
))
2271 (raw-path (org-element-property :path element
)))
2273 ((file-name-absolute-p raw-path
)
2274 (expand-file-name raw-path
))
2276 ((member (org-element-type element
)
2277 '(latex-fragment latex-environment
))
2278 (let* ((latex-frag (org-remove-indentation
2279 (org-element-property :value element
)))
2280 (formula-link (org-e-odt-format-latex
2281 latex-frag
'mathml info
)))
2283 (string-match "file:\\([^]]*\\)" formula-link
)
2284 (match-string 1 formula-link
))))
2285 (t (error "what is this?"))))
2286 (full-src (if (file-name-absolute-p src
) src
2287 (expand-file-name src
(file-name-directory
2288 (plist-get info
:input-file
)))))
2290 (case (org-element-type element
)
2291 (link (org-export-get-parent-element element
))
2293 (captions (org-e-odt-format-label caption-from info
'definition
))
2294 (caption (car captions
))
2296 (format "\n<draw:object %s xlink:href=\"%s\" xlink:type=\"simple\"/>"
2297 " xlink:show=\"embed\" xlink:actuate=\"onLoad\""
2298 (file-name-directory (org-e-odt-copy-formula-file full-src
))))
2299 (embed-as (if caption
'paragraph
'character
))
2302 ((eq embed-as
'character
)
2303 (org-e-odt-format-entity "InlineFormula" href width height
))
2305 (let* ((equation (org-e-odt-format-entity
2306 "CaptionedDisplayFormula" href width height captions
))
2308 (let* ((org-e-odt-category-map-alist
2309 '(("__Table__" "Table" "value")
2310 ("__Figure__" "Illustration" "value")
2311 ("__MathFormula__" "Text" "math-label")
2312 ("__DvipngImage__" "Equation" "value")
2313 ("__Listing__" "Listing" "value"))))
2314 (car (org-e-odt-format-label caption-from info
'definition
))))
2316 (org-element-adopt-elements
2317 (list 'table
'(:type org
:attr_odt
(":style \"OrgEquation\"")))
2318 (org-element-adopt-elements
2319 (list 'table-row
'(:type standard
))
2320 (list 'table-cell nil
"<c8>") (list 'table-cell nil
"<c1>"))
2321 (org-element-adopt-elements
2322 (list 'table-row
'(:type standard
))
2323 (org-element-adopt-elements
2324 (list 'table-cell nil
)
2325 (list 'export-block
(list :type
"ODT" :value equation
)))
2326 (org-element-adopt-elements
2327 (list 'table-cell nil
)
2328 (list 'export-block
(list :type
"ODT" :value label
))))))
2330 (org-export-collect-tree-properties
2331 formula-tree
(org-export-get-environment 'e-odt
))))
2332 (org-export-data formula-tree formula-info
))))))
2334 (defun org-e-odt-copy-formula-file (src-file)
2335 "Returns the internal name of the file"
2336 (let* ((target-dir (format "Formula-%04d/"
2337 (incf org-e-odt-embedded-formulas-count
)))
2338 (target-file (concat target-dir
"content.xml")))
2339 ;; Create a directory for holding formula file. Also enter it in
2341 (make-directory (concat org-e-odt-zip-dir target-dir
))
2342 (org-e-odt-create-manifest-file-entry
2343 "application/vnd.oasis.opendocument.formula" target-dir
"1.2")
2344 ;; Copy over the formula file from user directory to zip
2346 (message "Embedding %s as %s ..." src-file target-file
)
2347 (let ((case-fold-search nil
))
2350 ((string-match "\\.\\(mathml\\|mml\\)\\'" src-file
)
2351 (copy-file src-file
(concat org-e-odt-zip-dir target-file
) 'overwrite
))
2352 ;; Case 2: OpenDocument formula.
2353 ((string-match "\\.odf\\'" src-file
)
2354 (org-e-odt--zip-extract src-file
"content.xml"
2355 (concat org-e-odt-zip-dir target-dir
)))
2356 (t (error "%s is not a formula file" src-file
))))
2357 ;; Enter the formula file in to manifest.
2358 (org-e-odt-create-manifest-file-entry "text/xml" target-file
)
2363 (defun org-e-odt-format-entity (entity href width height
&optional
2364 captions user-frame-params
)
2365 (let* ((caption (car captions
)) (short-caption (cdr captions
))
2366 (entity-style (assoc-string entity org-e-odt-entity-frame-styles t
))
2367 default-frame-params frame-params
2368 (--merge-frame-params
2370 (lambda (default-frame-params user-frame-params
)
2371 (if (not user-frame-params
) default-frame-params
2372 (assert (= (length default-frame-params
) 3))
2373 (assert (= (length user-frame-params
) 3))
2374 (loop for user-frame-param in user-frame-params
2375 for default-frame-param in default-frame-params
2376 collect
(or user-frame-param default-frame-param
)))))))
2379 (setq default-frame-params
(nth 2 entity-style
))
2380 (setq frame-params
(funcall --merge-frame-params
2381 default-frame-params user-frame-params
))
2382 (apply 'org-e-odt--frame href width height frame-params
))
2384 (setq default-frame-params
(nth 3 entity-style
))
2385 (setq frame-params
(funcall --merge-frame-params
2386 default-frame-params user-frame-params
))
2387 (apply 'org-e-odt--textbox
2388 (format "\n<text:p text:style-name=\"%s\">%s</text:p>"
2391 (apply 'org-e-odt--frame href width height
2392 (let ((entity-style-1 (copy-sequence
2393 (nth 2 entity-style
))))
2394 (setcar (cdr entity-style-1
)
2396 (cadr entity-style-1
)
2398 (format " draw:name=\"%s\" "
2402 width height frame-params
)))))
2404 (defun org-e-odt-standalone-image-p (element info
)
2405 "Test if ELEMENT is a standalone image for the purpose ODT export.
2406 INFO is a plist holding contextual information.
2408 Return non-nil, if ELEMENT is of type paragraph and it's sole
2409 content, save for whitespaces, is a link that qualifies as an
2412 Return non-nil, if ELEMENT is of type link and it's containing
2413 paragraph has no other content save for leading and trailing
2416 Return nil, otherwise.
2418 Bind `org-e-odt-standalone-image-predicate' to constrain
2419 paragraph further. For example, to check for only captioned
2420 standalone images, do the following.
2422 \(setq org-e-odt-standalone-image-predicate
2423 \(lambda \(paragraph\)
2424 \(org-element-property :caption paragraph\)\)\)
2426 (let ((--standalone-image-predicate
2427 (function (lambda (paragraph)
2428 (or (org-element-property :caption paragraph
)
2429 (org-element-property :name paragraph
)))))
2430 (paragraph (case (org-element-type element
)
2432 (link (and (org-export-inline-image-p
2433 element org-e-odt-inline-image-rules
)
2434 (org-export-get-parent element
)))
2437 (assert (eq (org-element-type paragraph
) 'paragraph
))
2438 (when (funcall --standalone-image-predicate paragraph
)
2439 (let ((contents (org-element-contents paragraph
)))
2440 (loop for x in contents
2441 with inline-image-count
= 0
2443 ((eq (org-element-type x
) 'plain-text
)
2444 (not (org-string-nw-p x
)))
2445 ((eq (org-element-type x
) 'link
)
2446 (when (org-export-inline-image-p
2447 x org-e-odt-inline-image-rules
)
2448 (= (incf inline-image-count
) 1)))
2452 (defun org-e-odt-get-previous-elements (blob info
)
2453 (let ((parent (org-export-get-parent blob
)))
2454 (cdr (memq blob
(reverse (org-element-contents parent
))))))
2456 (defun org-e-odt-resolve-numbered-paragraph (element info
)
2457 (when (eq (org-element-type element
) 'item
)
2458 (let ((el element
) ordinal
)
2459 (while (eq (org-element-type el
) 'item
)
2460 (push (1+ (length (org-e-odt-get-previous-elements el info
))) ordinal
)
2461 (setq el
(org-export-get-parent (org-export-get-parent el
))))
2465 (defun org-e-odt-link (link desc info
)
2466 "Transcode a LINK object from Org to ODT.
2468 DESC is the description part of the link, or the empty string.
2469 INFO is a plist holding contextual information. See
2471 (let* ((type (org-element-property :type link
))
2472 (raw-path (org-element-property :path link
))
2473 ;; Ensure DESC really exists, or set it to nil.
2474 (desc (and (not (string= desc
"")) desc
))
2475 (imagep (org-export-inline-image-p
2476 link org-e-odt-inline-image-rules
))
2478 ((member type
'("http" "https" "ftp" "mailto"))
2479 (concat type
":" raw-path
))
2480 ((string= type
"file")
2481 (if (file-name-absolute-p raw-path
)
2482 (concat "file://" (expand-file-name raw-path
))
2483 (concat "file://" raw-path
)))
2488 ((and (not desc
) (org-export-inline-image-p
2489 link org-e-odt-inline-image-rules
))
2490 (org-e-odt-link--inline-image link info
))
2491 ;; Radio target: Transcode target's contents and use them as
2492 ;; link's description.
2493 ((string= type
"radio")
2494 (let ((destination (org-export-resolve-radio-link link info
)))
2496 (let ((desc (org-export-data (org-element-contents destination
) info
))
2497 (href (org-export-solidify-link-text path
)))
2499 "<text:bookmark-ref text:reference-format=\"text\" text:ref-name=\"OrgXref.%s\">%s</text:bookmark-ref>"
2501 ;; Links pointing to an headline: Find destination and build
2502 ;; appropriate referencing command.
2503 ((member type
'("custom-id" "fuzzy" "id"))
2504 (let ((destination (if (string= type
"fuzzy")
2505 (org-export-resolve-fuzzy-link link info
)
2506 (org-export-resolve-id-link link info
))))
2507 (case (org-element-type destination
)
2508 ;; Fuzzy link points nowhere.
2510 (format "<text:span text:style-name=\"%s\">%s</text:span>"
2511 "Emphasis" (or desc
(org-export-data
2512 (org-element-property
2513 :raw-link link
) info
))))
2514 ;; Fuzzy link points to an invisible target.
2516 ;; LINK points to an headline. Check if LINK should display
2519 (let* ((headline-no (org-export-get-headline-number destination info
))
2520 (label (format "sec-%s" (mapconcat 'number-to-string
2523 ;; Case 1: Headline is numbered and LINK has no
2524 ;; description or LINK's description matches headline's
2525 ;; title. Display section number.
2526 ((and (org-export-numbered-headline-p destination info
)
2527 (or (not desc
) (string= desc
(org-element-property
2528 :raw-value destination
))))
2530 "<text:bookmark-ref text:reference-format=\"chapter\" text:ref-name=\"OrgXref.%s\">%s</text:bookmark-ref>"
2531 label
(mapconcat 'number-to-string headline-no
".")))
2532 ;; Case 2: Either the headline is un-numbered or
2533 ;; LINK has a custom description. Display LINK's
2534 ;; description or headline's title.
2536 (let ((desc (or desc
(org-export-data
2537 (org-element-property :title destination
)
2540 "<text:bookmark-ref text:reference-format=\"text\" text:ref-name=\"OrgXref.%s\">%s</text:bookmark-ref>"
2542 ;; Fuzzy link points to a target. Do as above.
2544 ;; Identify nearest meaningful container
2546 (loop for parent in
(org-export-get-genealogy destination
)
2549 (org-element-type parent
)
2550 '(footnote-definition footnote-reference headline item
2553 ;; There is a meaningful container
2555 (case (org-element-type container
)
2556 ;; Container is item
2559 "<text:bookmark-ref text:reference-format=\"number-all-superior\" text:ref-name=\"OrgXref.%s\">%s</text:bookmark-ref>"
2560 (org-solidify-link-text path
)
2562 (mapconcat 'number-to-string
2563 (org-e-odt-resolve-numbered-paragraph
2564 container info
) ".")))))))
2568 ;; (setq number (cond
2569 ;; ((org-e-odt-standalone-image-p destination info)
2570 ;; (org-export-get-ordinal
2571 ;; (assoc 'link (org-element-contents destination))
2572 ;; info 'link 'org-e-odt-standalone-image-p))
2573 ;; (t (org-export-get-ordinal destination info))))
2574 ;; (setq desc (when number
2575 ;; (if (atom number) (number-to-string number)
2576 ;; (mapconcat 'number-to-string number ".")))))
2578 (let ((label-reference
2579 (org-e-odt-format-label destination info
'reference
)))
2580 (assert label-reference
)
2581 label-reference
)))))
2582 ;; Coderef: replace link with the reference name or the
2583 ;; equivalent line number.
2584 ((string= type
"coderef")
2585 (let* ((line-no (format "%d" (org-export-resolve-coderef path info
)))
2586 (href (concat "coderef-" path
)))
2588 (org-export-get-coderef-format path desc
)
2590 "<text:bookmark-ref text:reference-format=\"number\" text:ref-name=\"OrgXref.%s\">%s</text:bookmark-ref>"
2592 ;; Link type is handled by a special function.
2593 ((functionp (setq protocol
(nth 2 (assoc type org-link-protocols
))))
2594 (funcall protocol
(org-link-unescape path
) desc
'odt
))
2595 ;; External link with a description part.
2597 (format "<text:a xlink:type=\"simple\" xlink:href=\"%s\">%s</text:a>"
2599 ;; External link without a description part.
2601 (format "<text:a xlink:type=\"simple\" xlink:href=\"%s\">%s</text:a>"
2603 ;; No path, only description. Try to do something useful.
2604 (t (format "<text:span text:style-name=\"%s\">%s</text:span>"
2605 "Emphasis" desc
)))))
2610 (defun org-e-odt-paragraph (paragraph contents info
)
2611 "Transcode a PARAGRAPH element from Org to ODT.
2612 CONTENTS is the contents of the paragraph, as a string. INFO is
2613 the plist used as a communication channel."
2614 (let* ((parent (org-export-get-parent paragraph
))
2615 (parent-type (org-element-type parent
))
2616 (style (case parent-type
2617 (quote-block "Quotations")
2618 (center-block "OrgCenter")
2619 (footnote-definition "Footnote")
2620 (t (or (org-element-property :style paragraph
)
2622 ;; If this paragraph is a leading paragraph in an item and the
2623 ;; item has a checkbox, splice the checkbox and paragraph contents
2625 (when (and (eq (org-element-type parent
) 'item
)
2626 (eq paragraph
(car (org-element-contents parent
))))
2627 (setq contents
(concat (org-e-odt--checkbox parent
) contents
)))
2629 (format "\n<text:p text:style-name=\"%s\">%s</text:p>" style contents
)))
2634 (defun org-e-odt-plain-list (plain-list contents info
)
2635 "Transcode a PLAIN-LIST element from Org to ODT.
2636 CONTENTS is the contents of the list. INFO is a plist holding
2637 contextual information."
2638 (org-e-odt--wrap-label
2640 (format "\n<text:list text:style-name=\"%s\" %s>\n%s</text:list>"
2641 ;; Choose style based on list type.
2642 (case (org-element-property :type plain-list
)
2643 (ordered "OrgNumberedList")
2644 (unordered "OrgBulletedList")
2645 (descriptive-1 "OrgDescriptionList")
2646 (descriptive-2 "OrgDescriptionList"))
2647 ;; If top-level list, re-start numbering. Otherwise,
2648 ;; continue numbering.
2649 (format "text:continue-numbering=\"%s\""
2650 (let* ((parent (org-export-get-parent plain-list
)))
2651 (if (and parent
(eq (org-element-type parent
) 'item
))
2657 (defun org-e-odt-fill-tabs-and-spaces (line)
2658 (replace-regexp-in-string
2659 "\\([\t]\\|\\([ ]+\\)\\)"
2662 ((string= s
"\t") "<text:tab/>")
2663 (t (let ((n (length s
)))
2666 ((> n
1) (concat " " (format "<text:s text:c=\"%d\"/>" (1- n
))))
2670 (defun org-e-odt-encode-plain-text (text &optional no-whitespace-filling
)
2673 (setq text
(replace-regexp-in-string (car pair
) (cdr pair
) text t t
)))
2674 '(("&" .
"&") ("<" .
"<") (">" .
">")))
2675 (if no-whitespace-filling text
2676 (org-e-odt-fill-tabs-and-spaces text
)))
2678 (defun org-e-odt--quotation-marks (text info
)
2679 "Export quotation marks depending on language conventions.
2680 TEXT is a string containing quotation marks to be replaced. INFO
2681 is a plist used as a communication channel."
2684 (while (setq start
(string-match (car l
) text start
))
2685 (let ((new-quote (concat (match-string 1 text
) (cdr l
))))
2686 (setq text
(replace-match new-quote t t text
))))))
2687 (cdr (or (assoc (plist-get info
:language
) org-e-odt-quotes
)
2688 ;; Falls back on English.
2689 (assoc "en" org-e-odt-quotes
))))
2692 (defun org-e-odt-plain-text (text info
)
2693 "Transcode a TEXT string from Org to ODT.
2694 TEXT is the string to transcode. INFO is a plist holding
2695 contextual information."
2696 ;; Protect &, < and >.
2697 (setq text
(org-e-odt-encode-plain-text text t
))
2698 ;; Handle quotation marks
2699 (setq text
(org-e-odt--quotation-marks text info
))
2700 ;; Convert special strings.
2701 (when (plist-get info
:with-special-strings
)
2704 (setq text
(replace-regexp-in-string (car pair
) (cdr pair
) text t nil
)))
2705 org-e-odt-special-string-regexps
))
2706 ;; Handle break preservation if required.
2707 (when (plist-get info
:preserve-breaks
)
2708 (setq text
(replace-regexp-in-string
2709 "\\(\\\\\\\\\\)?[ \t]*\n" "<text:line-break/>\n" text t
)))
2716 (defun org-e-odt-planning (planning contents info
)
2717 "Transcode a PLANNING element from Org to ODT.
2718 CONTENTS is nil. INFO is a plist used as a communication
2720 (format "<text:span text:style-name=\"%s\">%s</text:span>"
2721 "OrgTimestampWrapper"
2723 (let ((closed (org-element-property :closed planning
)))
2726 (format "<text:span text:style-name=\"%s\">%s</text:span>"
2727 "OrgTimestampKeyword" org-closed-string
)
2728 (format "<text:span text:style-name=\"%s\">%s</text:span>"
2729 "OrgTimestamp" (org-translate-time closed
)))))
2730 (let ((deadline (org-element-property :deadline planning
)))
2733 (format "<text:span text:style-name=\"%s\">%s</text:span>"
2734 "OrgTimestampKeyword" org-deadline-string
)
2735 (format "<text:span text:style-name=\"%s\">%s</text:span>"
2736 "OrgTimestamp" (org-translate-time deadline
)))))
2737 (let ((scheduled (org-element-property :scheduled planning
)))
2740 (format "<text:span text:style-name=\"%s\">%s</text:span>"
2741 "OrgTimestampKeyword" org-scheduled-string
)
2742 (format "<text:span text:style-name=\"%s\">%s</text:span>"
2743 "OrgTimestamp" (org-translate-time scheduled
))))))))
2746 ;;;; Property Drawer
2748 (defun org-e-odt-property-drawer (property-drawer contents info
)
2749 "Transcode a PROPERTY-DRAWER element from Org to ODT.
2750 CONTENTS is nil. INFO is a plist holding contextual
2752 ;; The property drawer isn't exported but we want separating blank
2753 ;; lines nonetheless.
2759 (defun org-e-odt-quote-block (quote-block contents info
)
2760 "Transcode a QUOTE-BLOCK element from Org to ODT.
2761 CONTENTS holds the contents of the block. INFO is a plist
2762 holding contextual information."
2763 (org-e-odt--wrap-label quote-block contents
))
2768 (defun org-e-odt-quote-section (quote-section contents info
)
2769 "Transcode a QUOTE-SECTION element from Org to ODT.
2770 CONTENTS is nil. INFO is a plist holding contextual information."
2771 (let ((value (org-remove-indentation
2772 (org-element-property :value quote-section
))))
2773 (when value
(org-e-odt-do-format-code value
))))
2778 (defun org-e-odt-format-section (text style
&optional name
)
2779 (let ((default-name (car (org-e-odt-add-automatic-style "Section"))))
2780 (format "\n<text:section text:style-name=\"%s\" %s>\n%s\n</text:section>"
2782 (format "text:name=\"%s\"" (or name default-name
))
2786 (defun org-e-odt-section (section contents info
) ; FIXME
2787 "Transcode a SECTION element from Org to ODT.
2788 CONTENTS holds the contents of the section. INFO is a plist
2789 holding contextual information."
2794 (defun org-e-odt-radio-target (radio-target text info
)
2795 "Transcode a RADIO-TARGET object from Org to ODT.
2796 TEXT is the text of the target. INFO is a plist holding
2797 contextual information."
2799 text
(org-export-solidify-link-text
2800 (org-element-property :value radio-target
))))
2805 (defun org-e-odt-special-block (special-block contents info
)
2806 "Transcode a SPECIAL-BLOCK element from Org to ODT.
2807 CONTENTS holds the contents of the block. INFO is a plist
2808 holding contextual information."
2809 (let ((type (downcase (org-element-property :type special-block
)))
2810 (attributes (org-export-read-attribute :attr_odt special-block
)))
2811 (org-e-odt--wrap-label
2815 ((string= type
"annotation")
2816 (let ((author (or (plist-get attributes
:author
)
2817 (let ((author (plist-get info
:author
)))
2818 (and author
(org-export-data author info
)))))
2819 (date (or (plist-get attributes
:date
)
2820 (plist-get info
:date
))))
2822 (format "\n<text:p text:style-name=\"%s\">%s</text:p>"
2824 (format "<office:annotation>\n%s\n</office:annotation>"
2827 (format "<dc:creator>%s</dc:creator>" author
))
2829 (format "<dc:date>%s</dc:date>"
2830 (org-e-odt--date date
)))
2833 ((string= type
"textbox")
2834 (let ((width (plist-get attributes
:width
))
2835 (height (plist-get attributes
:height
))
2836 (style (plist-get attributes
:style
))
2837 (extra (plist-get attributes
:extra
))
2838 (anchor (plist-get attributes
:anchor
)))
2839 (format "\n<text:p text:style-name=\"%s\">%s</text:p>"
2840 "Text_20_body" (org-e-odt--textbox contents width height
2841 style extra anchor
))))
2847 (defun org-e-odt-hfy-face-to-css (fn)
2848 "Create custom style for face FN.
2849 When FN is the default face, use it's foreground and background
2850 properties to create \"OrgSrcBlock\" paragraph style. Otherwise
2851 use it's color attribute to create a character style whose name
2852 is obtained from FN. Currently all attributes of FN other than
2855 The style name for a face FN is derived using the following
2856 operations on the face name in that order - de-dash, CamelCase
2857 and prefix with \"OrgSrc\". For example,
2858 `font-lock-function-name-face' is associated with
2859 \"OrgSrcFontLockFunctionNameFace\"."
2860 (let* ((css-list (hfy-face-to-style fn
))
2861 (style-name ((lambda (fn)
2864 'capitalize
(split-string
2865 (hfy-face-or-def-to-name fn
) "-")
2867 (color-val (cdr (assoc "color" css-list
)))
2868 (background-color-val (cdr (assoc "background" css-list
)))
2869 (style (and org-e-odt-create-custom-styles-for-srcblocks
2872 (format org-e-odt-src-block-paragraph-format
2873 background-color-val color-val
))
2877 <style:style style:name=\"%s\" style:family=\"text\">
2878 <style:text-properties fo:color=\"%s\"/>
2879 </style:style>" style-name color-val
))))))
2880 (cons style-name style
)))
2882 (defun org-e-odt-htmlfontify-string (line)
2883 (let* ((hfy-html-quote-regex "\\([<\"&> ]\\)")
2884 (hfy-html-quote-map '(("\"" """)
2889 (" " "<text:tab/>")))
2890 (hfy-face-to-css 'org-e-odt-hfy-face-to-css
)
2891 (hfy-optimisations-1 (copy-seq hfy-optimisations
))
2892 (hfy-optimisations (add-to-list 'hfy-optimisations-1
2894 (hfy-begin-span-handler
2895 (lambda (style text-block text-id text-begins-block-p
)
2896 (insert (format "<text:span text:style-name=\"%s\">" style
))))
2897 (hfy-end-span-handler (lambda nil
(insert "</text:span>"))))
2898 (with-no-warnings (htmlfontify-string line
))))
2900 (defun org-e-odt-do-format-code
2901 (code &optional lang refs retain-labels num-start
)
2902 (let* ((lang (or (assoc-default lang org-src-lang-modes
) lang
))
2903 (lang-mode (and lang
(intern (format "%s-mode" lang
))))
2904 (code-lines (org-split-string code
"\n"))
2905 (code-length (length code-lines
))
2906 (use-htmlfontify-p (and (functionp lang-mode
)
2907 org-e-odt-fontify-srcblocks
2908 (require 'htmlfontify nil t
)
2909 (fboundp 'htmlfontify-string
)))
2910 (code (if (not use-htmlfontify-p
) code
2914 (font-lock-fontify-buffer)
2916 (fontifier (if use-htmlfontify-p
'org-e-odt-htmlfontify-string
2917 'org-e-odt-encode-plain-text
))
2918 (par-style (if use-htmlfontify-p
"OrgSrcBlock"
2919 "OrgFixedWidthBlock"))
2921 (assert (= code-length
(length (org-split-string code
"\n"))))
2923 (org-export-format-code
2925 (lambda (loc line-num ref
)
2927 (concat par-style
(and (= (incf i
) code-length
) "LastLine")))
2929 (setq loc
(concat loc
(and ref retain-labels
(format " (%s)" ref
))))
2930 (setq loc
(funcall fontifier loc
))
2932 (setq loc
(org-e-odt--target loc
(concat "coderef-" ref
))))
2934 (setq loc
(format "\n<text:p text:style-name=\"%s\">%s</text:p>"
2936 (if (not line-num
) loc
2937 (format "\n<text:list-item>%s\n</text:list-item>" loc
)))
2940 ((not num-start
) code
)
2943 "\n<text:list text:style-name=\"OrgSrcBlockNumberedLine\"%s>%s</text:list>"
2944 " text:continue-numbering=\"false\"" code
))
2947 "\n<text:list text:style-name=\"OrgSrcBlockNumberedLine\"%s>%s</text:list>"
2948 " text:continue-numbering=\"true\"" code
)))))
2950 (defun org-e-odt-format-code (element info
)
2951 (let* ((lang (org-element-property :language element
))
2952 ;; Extract code and references.
2953 (code-info (org-export-unravel-code element
))
2954 (code (car code-info
))
2955 (refs (cdr code-info
))
2956 ;; Does the src block contain labels?
2957 (retain-labels (org-element-property :retain-labels element
))
2958 ;; Does it have line numbers?
2959 (num-start (case (org-element-property :number-lines element
)
2960 (continued (org-export-get-loc element info
))
2962 (org-e-odt-do-format-code code lang refs retain-labels num-start
)))
2964 (defun org-e-odt-src-block (src-block contents info
)
2965 "Transcode a SRC-BLOCK element from Org to ODT.
2966 CONTENTS holds the contents of the item. INFO is a plist holding
2967 contextual information."
2968 (let* ((lang (org-element-property :language src-block
))
2969 (caption (org-element-property :caption src-block
))
2970 (short-caption (and (cdr caption
)
2971 (org-export-data (cdr caption
) info
)))
2972 (caption (and (car caption
) (org-export-data (car caption
) info
)))
2973 (label (org-element-property :name src-block
))
2974 (attributes (org-export-read-attribute :attr_odt src-block
)))
2975 ;; FIXME: Handle caption
2976 ;; caption-str (when caption)
2977 ;; (main (org-export-data (car caption) info))
2978 ;; (secondary (org-export-data (cdr caption) info))
2979 ;; (caption-str (org-e-odt--caption/label-string caption label info))
2980 (let* ((captions (org-e-odt-format-label src-block info
'definition
))
2981 (caption (car captions
)) (short-caption (cdr captions
)))
2984 (format "\n<text:p text:style-name=\"%s\">%s</text:p>"
2986 (let ((--src-block (org-e-odt-format-code src-block info
)))
2987 (if (not (plist-get attributes
:textbox
)) --src-block
2988 (format "\n<text:p text:style-name=\"%s\">%s</text:p>"
2990 (org-e-odt--textbox --src-block nil nil nil
))))))))
2993 ;;;; Statistics Cookie
2995 (defun org-e-odt-statistics-cookie (statistics-cookie contents info
)
2996 "Transcode a STATISTICS-COOKIE object from Org to ODT.
2997 CONTENTS is nil. INFO is a plist holding contextual information."
2998 (let ((cookie-value (org-element-property :value statistics-cookie
)))
2999 (format "<text:span text:style-name=\"%s\">%s</text:span>"
3000 "OrgCode" cookie-value
)))
3005 (defun org-e-odt-strike-through (strike-through contents info
)
3006 "Transcode STRIKE-THROUGH from Org to ODT.
3007 CONTENTS is the text with strike-through markup. INFO is a plist
3008 holding contextual information."
3009 (format "<text:span text:style-name=\"%s\">%s</text:span>"
3010 "Strikethrough" contents
))
3015 (defun org-e-odt-subscript (subscript contents info
)
3016 "Transcode a SUBSCRIPT object from Org to ODT.
3017 CONTENTS is the contents of the object. INFO is a plist holding
3018 contextual information."
3019 (format "<text:span text:style-name=\"%s\">%s</text:span>"
3020 "OrgSubscript" contents
))
3025 (defun org-e-odt-superscript (superscript contents info
)
3026 "Transcode a SUPERSCRIPT object from Org to ODT.
3027 CONTENTS is the contents of the object. INFO is a plist holding
3028 contextual information."
3029 (format "<text:span text:style-name=\"%s\">%s</text:span>"
3030 "OrgSuperscript" contents
))
3035 (defun org-e-odt-table-style-spec (element info
)
3036 (let* ((table (org-export-get-parent-table element
))
3037 (table-attributes (org-export-read-attribute :attr_odt table
))
3038 (table-style (plist-get table-attributes
:style
)))
3039 (assoc table-style org-e-odt-table-styles
)))
3041 (defun org-e-odt-get-table-cell-styles (table-cell info
)
3042 "Retrieve styles applicable to a table cell.
3043 R and C are (zero-based) row and column numbers of the table
3044 cell. STYLE-SPEC is an entry in `org-e-odt-table-styles'
3045 applicable to the current table. It is `nil' if the table is not
3046 associated with any style attributes.
3048 Return a cons of (TABLE-CELL-STYLE-NAME . PARAGRAPH-STYLE-NAME).
3050 When STYLE-SPEC is nil, style the table cell the conventional way
3051 - choose cell borders based on row and column groupings and
3052 choose paragraph alignment based on `org-col-cookies' text
3054 `org-e-odt-get-paragraph-style-cookie-for-table-cell'.
3056 When STYLE-SPEC is non-nil, ignore the above cookie and return
3057 styles congruent with the ODF-1.2 specification."
3058 (let* ((table-cell-address (org-export-table-cell-address table-cell info
))
3059 (r (car table-cell-address
)) (c (cdr table-cell-address
))
3060 (style-spec (org-e-odt-table-style-spec table-cell info
))
3061 (table-dimensions (org-export-table-dimensions
3062 (org-export-get-parent-table table-cell
)
3065 ;; LibreOffice - particularly the Writer - honors neither table
3066 ;; templates nor custom table-cell styles. Inorder to retain
3067 ;; inter-operability with LibreOffice, only automatic styles are
3068 ;; used for styling of table-cells. The current implementation is
3069 ;; congruent with ODF-1.2 specification and hence is
3070 ;; future-compatible.
3072 ;; Additional Note: LibreOffice's AutoFormat facility for tables -
3073 ;; which recognizes as many as 16 different cell types - is much
3074 ;; richer. Unfortunately it is NOT amenable to easy configuration
3076 (let* ((template-name (nth 1 style-spec
))
3077 (cell-style-selectors (nth 2 style-spec
))
3080 ((and (cdr (assoc 'use-first-column-styles cell-style-selectors
))
3081 (= c
0)) "FirstColumn")
3082 ((and (cdr (assoc 'use-last-column-styles cell-style-selectors
))
3083 (= (1+ c
) (cdr table-dimensions
)))
3085 ((and (cdr (assoc 'use-first-row-styles cell-style-selectors
))
3086 (= r
0)) "FirstRow")
3087 ((and (cdr (assoc 'use-last-row-styles cell-style-selectors
))
3088 (= (1+ r
) (car table-dimensions
)))
3090 ((and (cdr (assoc 'use-banding-rows-styles cell-style-selectors
))
3091 (= (% r
2) 1)) "EvenRow")
3092 ((and (cdr (assoc 'use-banding-rows-styles cell-style-selectors
))
3093 (= (% r
2) 0)) "OddRow")
3094 ((and (cdr (assoc 'use-banding-columns-styles cell-style-selectors
))
3095 (= (% c
2) 1)) "EvenColumn")
3096 ((and (cdr (assoc 'use-banding-columns-styles cell-style-selectors
))
3097 (= (% c
2) 0)) "OddColumn")
3099 (concat template-name cell-type
)))))
3101 (defun org-e-odt-table-cell (table-cell contents info
)
3102 "Transcode a TABLE-CELL element from Org to ODT.
3103 CONTENTS is nil. INFO is a plist used as a communication
3105 (let* ((table-cell-address (org-export-table-cell-address table-cell info
))
3106 (r (car table-cell-address
))
3107 (c (cdr table-cell-address
))
3108 (horiz-span (or (org-export-table-cell-width table-cell info
) 0))
3109 (table-row (org-export-get-parent table-cell
))
3110 (custom-style-prefix (org-e-odt-get-table-cell-styles
3114 (and custom-style-prefix
3115 (format "%sTableParagraph" custom-style-prefix
))
3118 ((and (= 1 (org-export-table-row-group table-row info
))
3119 (org-export-table-has-header-p
3120 (org-export-get-parent-table table-row
) info
))
3122 ((let* ((table (org-export-get-parent-table table-cell
))
3123 (table-attrs (org-export-read-attribute :attr_odt table
))
3124 (table-header-columns (plist-get table-attrs
3126 (<= c
(cond ((wholenump table-header-columns
)
3127 (- table-header-columns
1))
3128 (table-header-columns 0)
3131 (t "OrgTableContents"))
3132 (capitalize (symbol-name (org-export-table-cell-alignment
3133 table-cell info
))))))
3136 (and custom-style-prefix
(format "%sTableCell"
3137 custom-style-prefix
))
3140 (when (or (org-export-table-row-starts-rowgroup-p table-row info
)
3142 (when (org-export-table-row-ends-rowgroup-p table-row info
) "B")
3143 (when (and (org-export-table-cell-starts-colgroup-p table-cell info
)
3144 (not (zerop c
)) ) "L"))))
3147 (format " table:style-name=\"%s\"" cell-style-name
)
3148 (and (> horiz-span
0)
3149 (format " table:number-columns-spanned=\"%d\""
3150 (1+ horiz-span
))))))
3151 (unless contents
(setq contents
""))
3153 (assert paragraph-style
)
3154 (format "\n<table:table-cell%s>\n%s\n</table:table-cell>"
3156 (format "\n<text:p text:style-name=\"%s\">%s</text:p>"
3157 paragraph-style contents
))
3159 (dotimes (i horiz-span s
)
3160 (setq s
(concat s
"\n<table:covered-table-cell/>"))))
3166 (defun org-e-odt-table-row (table-row contents info
)
3167 "Transcode a TABLE-ROW element from Org to ODT.
3168 CONTENTS is the contents of the row. INFO is a plist used as a
3169 communication channel."
3170 ;; Rules are ignored since table separators are deduced from
3171 ;; borders of the current row.
3172 (when (eq (org-element-property :type table-row
) 'standard
)
3173 (let* ((rowgroup-tags
3174 (if (and (= 1 (org-export-table-row-group table-row info
))
3175 (org-export-table-has-header-p
3176 (org-export-get-parent-table table-row
) info
))
3177 ;; If the row belongs to the first rowgroup and the
3178 ;; table has more than one row groups, then this row
3179 ;; belongs to the header row group.
3180 '("\n<table:table-header-rows>" .
"\n</table:table-header-rows>")
3181 ;; Otherwise, it belongs to non-header row group.
3182 '("\n<table:table-rows>" .
"\n</table:table-rows>"))))
3184 ;; Does this row begin a rowgroup?
3185 (when (org-export-table-row-starts-rowgroup-p table-row info
)
3186 (car rowgroup-tags
))
3188 (format "\n<table:table-row>\n%s\n</table:table-row>" contents
)
3189 ;; Does this row end a rowgroup?
3190 (when (org-export-table-row-ends-rowgroup-p table-row info
)
3191 (cdr rowgroup-tags
))))))
3196 (defun org-e-odt-table-first-row-data-cells (table info
)
3201 (unless (eq (org-element-property :type row
) 'rule
) row
))
3203 (special-column-p (org-export-table-has-special-column-p table
)))
3204 (if (not special-column-p
) (org-element-contents table-row
)
3205 (cdr (org-element-contents table-row
)))))
3207 (defun org-e-odt--table (table contents info
)
3208 "Transcode a TABLE element from Org to ODT.
3209 CONTENTS is the contents of the table. INFO is a plist holding
3210 contextual information."
3211 (case (org-element-property :type table
)
3212 ;; Case 1: table.el doesn't support export to OD format. Strip
3213 ;; such tables from export.
3218 "(org-e-odt): Found table.el-type table in the source Org file."
3219 " table.el doesn't support export to ODT format."
3220 " Stripping the table from export."))))
3221 ;; Case 2: Native Org tables.
3223 (let* ((captions (org-e-odt-format-label table info
'definition
))
3224 (caption (car captions
)) (short-caption (cdr captions
))
3225 (attributes (org-export-read-attribute :attr_odt table
))
3226 (custom-table-style (nth 1 (org-e-odt-table-style-spec table info
)))
3229 (lambda (table info
)
3230 (let* ((table-style (or custom-table-style
"OrgTable"))
3231 (column-style (format "%sColumn" table-style
)))
3233 (lambda (table-cell)
3234 (let ((width (1+ (or (org-export-table-cell-width
3235 table-cell info
) 0)))
3237 "\n<table:table-column table:style-name=\"%s\"/>"
3240 (dotimes (i width out
) (setq out
(concat s out
)))))
3241 (org-e-odt-table-first-row-data-cells table info
) "\n"))))))
3245 (format "\n<text:p text:style-name=\"%s\">%s</text:p>"
3248 (let* ((automatic-name
3249 (org-e-odt-add-automatic-style "Table" attributes
)))
3251 "\n<table:table table:name=\"%s\" table:style-name=\"%s\">"
3252 (or short-caption
(car automatic-name
))
3253 (or custom-table-style
(cdr automatic-name
) "OrgTable")))
3254 ;; column specification.
3255 (funcall table-column-specs table info
)
3259 "</table:table>")))))
3261 (defun org-e-odt-table (table contents info
)
3262 "Transcode a TABLE element from Org to ODT.
3263 CONTENTS is the contents of the table. INFO is a plist holding
3264 contextual information.
3266 Use `org-e-odt--table' to typeset the table. Handle details
3267 pertaining to indentation here."
3268 (let* ((--get-previous-elements
3271 (let ((parent (org-export-get-parent blob
)))
3272 (cdr (memq blob
(reverse (org-element-contents parent
))))))))
3273 (--element-preceded-by-table-p
3275 (lambda (element info
)
3276 (loop for el in
(funcall --get-previous-elements element info
)
3277 thereis
(eq (org-element-type el
) 'table
)))))
3278 (--walk-list-genealogy-and-collect-tags
3280 (lambda (table info
)
3281 (let* ((genealogy (org-export-get-genealogy table
))
3283 (when (eq (org-element-type (car genealogy
)) 'item
)
3284 (loop for el in genealogy
3285 when
(memq (org-element-type el
)
3290 (loop for el in genealogy
3291 when
(and (eq (org-element-type el
) 'headline
)
3292 (org-export-low-level-p el info
))
3296 (org-element-contents
3297 (org-export-get-parent el
)))))))
3300 ;; Handle list genealogy.
3301 (loop for el in list-genealogy collect
3302 (case (org-element-type el
)
3304 (setq parent-list el
)
3305 (cons "</text:list>"
3306 (format "\n<text:list text:style-name=\"%s\" %s>"
3307 (case (org-element-property :type el
)
3308 (ordered "OrgNumberedList")
3309 (unordered "OrgBulletedList")
3310 (descriptive-1 "OrgDescriptionList")
3311 (descriptive-2 "OrgDescriptionList"))
3312 "text:continue-numbering=\"true\"")))
3316 (if (funcall --element-preceded-by-table-p table info
)
3317 '("</text:list-header>" .
"<text:list-header>")
3318 '("</text:list-item>" .
"<text:list-header>")))
3319 ((funcall --element-preceded-by-table-p
3321 '("</text:list-header>" .
"<text:list-header>"))
3322 (t '("</text:list-item>" .
"<text:list-item>"))))))
3323 ;; Handle low-level headlines.
3324 (loop for el in llh-genealogy
3325 with step
= 'item collect
3328 (setq step
'item
) ; Flip-flop
3329 (setq parent-list el
)
3330 (cons "</text:list>"
3331 (format "\n<text:list text:style-name=\"%s\" %s>"
3332 (if (org-export-numbered-headline-p
3336 "text:continue-numbering=\"true\"")))
3338 (setq step
'plain-list
) ; Flip-flop
3341 (if (funcall --element-preceded-by-table-p table info
)
3342 '("</text:list-header>" .
"<text:list-header>")
3343 '("</text:list-item>" .
"<text:list-header>")))
3344 ((funcall --element-preceded-by-table-p
3346 '("</text:list-header>" .
"<text:list-header>"))
3348 '("</text:list-item>" .
"<text:list-item>")))))))))))
3349 (close-open-tags (funcall --walk-list-genealogy-and-collect-tags
3351 ;; OpenDocument schema does not permit table to occur within a
3354 ;; One solution - the easiest and lightweight, in terms of
3355 ;; implementation - is to put the table in an indented text box
3356 ;; and make the text box part of the list-item. Unfortunately if
3357 ;; the table is big and spans multiple pages, the text box could
3358 ;; overflow. In this case, the following attribute will come
3361 ;; ,---- From OpenDocument-v1.1.pdf
3362 ;; | 15.27.28 Overflow behavior
3364 ;; | For text boxes contained within text document, the
3365 ;; | style:overflow-behavior property specifies the behavior of text
3366 ;; | boxes where the containing text does not fit into the text
3369 ;; | If the attribute's value is clip, the text that does not fit
3370 ;; | into the text box is not displayed.
3372 ;; | If the attribute value is auto-create-new-frame, a new frame
3373 ;; | will be created on the next page, with the same position and
3374 ;; | dimensions of the original frame.
3376 ;; | If the style:overflow-behavior property's value is
3377 ;; | auto-create-new-frame and the text box has a minimum width or
3378 ;; | height specified, then the text box will grow until the page
3379 ;; | bounds are reached before a new frame is created.
3382 ;; Unfortunately, LibreOffice-3.4.6 doesn't honor
3383 ;; auto-create-new-frame property and always resorts to clipping
3384 ;; the text box. This results in table being truncated.
3386 ;; So we solve the problem the hard (and fun) way using list
3389 ;; The problem only becomes more interesting if you take in to
3390 ;; account the following facts:
3392 ;; - Description lists are simulated as plain lists.
3393 ;; - Low-level headlines can be listified.
3394 ;; - In Org-mode, a table can occur not only as a regular list
3395 ;; item, but also within description lists and low-level
3398 ;; See `org-e-odt-translate-description-lists' and
3399 ;; `org-e-odt-translate-low-level-headlines' for how this is
3403 ;; Discontinue the list.
3404 (mapconcat 'car close-open-tags
"\n")
3405 ;; Put the table in an indented section.
3406 (let* ((table (org-e-odt--table table contents info
))
3407 (level (/ (length (mapcar 'car close-open-tags
)) 2))
3408 (style (format "OrgIndentedSection-Level-%d" level
)))
3409 (when table
(org-e-odt-format-section table style
)))
3410 ;; Continue the list.
3411 (mapconcat 'cdr
(nreverse close-open-tags
) "\n"))))
3416 (defun org-e-odt-target (target contents info
)
3417 "Transcode a TARGET object from Org to ODT.
3418 CONTENTS is nil. INFO is a plist holding contextual
3420 (let ((value (org-element-property :value target
)))
3421 (org-e-odt--target "" (org-export-solidify-link-text value
))))
3426 (defun org-e-odt-timestamp (timestamp contents info
)
3427 "Transcode a TIMESTAMP object from Org to ODT.
3428 CONTENTS is nil. INFO is a plist used as a communication
3430 (let ((timestamp-1 (org-element-property :value timestamp
))
3431 (timestamp-2 (org-element-property :range-end timestamp
)))
3432 (format "<text:span text:style-name=\"%s\">%s</text:span>"
3433 "OrgTimestampWrapper"
3435 (format "<text:span text:style-name=\"%s\">%s</text:span>"
3436 "OrgTimestamp" (org-translate-time timestamp-1
))
3439 (format "<text:span text:style-name=\"%s\">%s</text:span>"
3440 "OrgTimestamp" (org-translate-time timestamp-2
)))))))
3445 (defun org-e-odt-underline (underline contents info
)
3446 "Transcode UNDERLINE from Org to ODT.
3447 CONTENTS is the text with underline markup. INFO is a plist
3448 holding contextual information."
3449 (format "<text:span text:style-name=\"%s\">%s</text:span>"
3450 "Underline" contents
))
3455 (defun org-e-odt-verbatim (verbatim contents info
)
3456 "Transcode a VERBATIM object from Org to ODT.
3457 CONTENTS is nil. INFO is a plist used as a communication
3459 (format "<text:span text:style-name=\"%s\">%s</text:span>"
3460 "OrgCode" (org-element-property :value verbatim
)))
3465 (defun org-e-odt-verse-block (verse-block contents info
)
3466 "Transcode a VERSE-BLOCK element from Org to ODT.
3467 CONTENTS is verse block contents. INFO is a plist holding
3468 contextual information."
3469 ;; Add line breaks to each line of verse.
3470 (setq contents
(replace-regexp-in-string
3471 "\\(<text:line-break/>\\)?[ \t]*\n"
3472 "<text:line-break/>" contents
))
3473 ;; Replace tabs and spaces.
3474 (setq contents
(org-e-odt-fill-tabs-and-spaces contents
))
3475 ;; Surround it in a verse environment.
3476 (org-e-odt--wrap-label
3478 (format "\n<text:p text:style-name=\"%s\">%s</text:p>"
3479 "OrgVerse" contents
)))
3485 ;;;; Description lists
3487 ;; This translator is necessary to handle indented tables in a uniform
3488 ;; manner. See comment in `org-e-odt--table'.
3490 (add-to-list 'org-export-filter-parse-tree-functions
3491 'org-e-odt--translate-description-lists
)
3493 (defun org-e-odt--translate-description-lists (tree backend info
)
3494 ;; OpenDocument has no notion of a description list. So simulate it
3495 ;; using plain lists. Description lists in the exported document
3496 ;; are typeset in the same manner as they are in a typical HTML
3499 ;; Specifically, a description list like this:
3502 ;; | - term-1 :: definition-1
3503 ;; | - term-2 :: definition-2
3506 ;; gets translated in to the following form:
3515 ;; Further effect is achieved by fixing the OD styles as below:
3517 ;; 1. Set the :type property of the simulated lists to
3518 ;; `descriptive-1' and `descriptive-2'. Map these to list-styles
3519 ;; that has *no* bullets whatsoever.
3521 ;; 2. The paragraph containing the definition term is styled to be
3524 (when (eq backend
'e-odt
)
3528 (when (equal (org-element-property :type el
) 'descriptive
)
3529 (org-element-set-element
3531 (apply 'org-element-adopt-elements
3532 (list 'plain-list
(list :type
'descriptive-1
))
3535 (org-element-adopt-elements
3536 (list 'item
(list :checkbox
(org-element-property
3538 (list 'paragraph
(list :style
"Text_20_body_20_bold")
3539 (or (org-element-property :tag item
) "(no term)"))
3540 (org-element-adopt-elements
3541 (list 'plain-list
(list :type
'descriptive-2
))
3542 (apply 'org-element-adopt-elements
3544 (org-element-contents item
)))))
3545 (org-element-contents el
)))))
3551 ;;; Interactive functions
3553 (defun org-e-odt-create-manifest-file-entry (&rest args
)
3554 (push args org-e-odt-manifest-file-entries
))
3556 (defun org-e-odt-write-manifest-file ()
3557 (make-directory (concat org-e-odt-zip-dir
"META-INF"))
3558 (let ((manifest-file (concat org-e-odt-zip-dir
"META-INF/manifest.xml")))
3559 (with-current-buffer
3560 (let ((nxml-auto-insert-xml-declaration-flag nil
))
3561 (find-file-noselect manifest-file t
))
3563 "<?xml version=\"1.0\" encoding=\"UTF-8\"?>
3564 <manifest:manifest xmlns:manifest=\"urn:oasis:names:tc:opendocument:xmlns:manifest:1.0\" manifest:version=\"1.2\">\n")
3566 (lambda (file-entry)
3567 (let* ((version (nth 2 file-entry
))
3568 (extra (if (not version
) ""
3569 (format " manifest:version=\"%s\"" version
))))
3571 (format org-e-odt-manifest-file-entry-tag
3572 (nth 0 file-entry
) (nth 1 file-entry
) extra
))))
3573 org-e-odt-manifest-file-entries
)
3574 (insert "\n</manifest:manifest>"))))
3576 (defmacro org-e-odt--export-wrap
(out-file &rest body
)
3577 `(let* ((--out-file ,out-file
)
3578 (out-file-type (file-name-extension --out-file
))
3579 (org-e-odt-xml-files '("META-INF/manifest.xml" "content.xml"
3580 "meta.xml" "styles.xml"))
3581 ;; Initialize workarea. All files that end up in the
3582 ;; exported get created here.
3583 (org-e-odt-zip-dir (file-name-as-directory
3584 (make-temp-file (format "%s-" out-file-type
) t
)))
3585 (org-e-odt-manifest-file-entries nil
)
3586 (--cleanup-xml-buffers
3589 ;; Kill all XML buffers.
3590 (mapc (lambda (file)
3591 (let ((buf (get-file-buffer
3592 (concat org-e-odt-zip-dir file
))))
3594 (set-buffer-modified-p nil
)
3595 (kill-buffer buf
))))
3596 org-e-odt-xml-files
)
3597 ;; Delete temporary directory and also other embedded
3598 ;; files that get copied there.
3599 (delete-directory org-e-odt-zip-dir t
)))))
3600 (org-condition-case-unless-debug
3603 (unless (executable-find "zip")
3604 ;; Not at all OSes ship with zip by default
3605 (error "Executable \"zip\" needed for creating OpenDocument files"))
3606 ;; Do export. This creates a bunch of xml files ready to be
3607 ;; saved and zipped.
3609 ;; Create a manifest entry for content.xml.
3610 (org-e-odt-create-manifest-file-entry "text/xml" "content.xml")
3612 ;; Write mimetype file
3614 '(("odt" .
"application/vnd.oasis.opendocument.text")
3615 ("odf" .
"application/vnd.oasis.opendocument.formula")))
3616 (mimetype (cdr (assoc-string out-file-type mimetypes t
))))
3618 (error "Unknown OpenDocument backend %S" out-file-type
))
3619 (write-region mimetype nil
(concat org-e-odt-zip-dir
"mimetype"))
3620 (org-e-odt-create-manifest-file-entry mimetype
"/" "1.2"))
3621 ;; Write out the manifest entries before zipping
3622 (org-e-odt-write-manifest-file)
3623 ;; Save all XML files.
3624 (mapc (lambda (file)
3625 (let ((buf (get-file-buffer (concat org-e-odt-zip-dir file
))))
3627 (with-current-buffer buf
3628 ;; Prettify output if needed.
3629 (when org-e-odt-prettify-xml
3630 (indent-region (point-min) (point-max)))
3632 org-e-odt-xml-files
)
3634 (let* ((target --out-file
)
3635 (target-name (file-name-nondirectory target
))
3636 (target-dir (file-name-directory target
))
3637 (cmds `(("zip" "-mX0" ,target-name
"mimetype")
3638 ("zip" "-rmTq" ,target-name
"."))))
3639 ;; If a file with same name as the desired output file
3640 ;; exists, remove it.
3641 (when (file-exists-p target
)
3642 (delete-file target
))
3643 ;; Zip up the xml files.
3644 (let ((coding-system-for-write 'no-conversion
) exitcode err-string
)
3645 (message "Creating ODT file...")
3646 ;; Switch temporarily to content.xml. This way Zip
3647 ;; process will inherit `org-e-odt-zip-dir' as the current
3649 (with-current-buffer
3650 (find-file-noselect (concat org-e-odt-zip-dir
"content.xml") t
)
3653 (message "Running %s" (mapconcat 'identity cmd
" "))
3655 (with-output-to-string
3657 (apply 'call-process
(car cmd
)
3658 nil standard-output nil
(cdr cmd
)))))
3659 (or (zerop exitcode
)
3660 (error (concat "Unable to create OpenDocument file."
3661 (format " Zip failed with error (%s)"
3664 ;; Zip file is now in the rightful place.
3665 (rename-file target-name target
)))
3666 (message "Created %s" target
)
3667 ;; Cleanup work directory and work files.
3668 (funcall --cleanup-xml-buffers
)
3669 ;; Open the OpenDocument file in archive-mode for
3671 (find-file-noselect target t
)
3672 ;; Return exported file.
3674 ;; Case 1: Conversion desired on exported file. Run the
3675 ;; converter on the OpenDocument file. Return the
3677 (org-e-odt-preferred-output-format
3678 (or (org-e-odt-convert target org-e-odt-preferred-output-format
)
3680 ;; Case 2: No further conversion. Return exported
3681 ;; OpenDocument file.
3684 ;; Cleanup work directory and work files.
3685 (funcall --cleanup-xml-buffers
)
3686 (message "OpenDocument export failed: %s"
3687 (error-message-string err
))))))
3690 ;;;; Export to OpenDocument formula
3693 (defun org-e-odt-export-as-odf (latex-frag &optional odf-file
)
3694 "Export LATEX-FRAG as OpenDocument formula file ODF-FILE.
3695 Use `org-create-math-formula' to convert LATEX-FRAG first to
3696 MathML. When invoked as an interactive command, use
3697 `org-latex-regexps' to infer LATEX-FRAG from currently active
3698 region. If no LaTeX fragments are found, prompt for it. Push
3699 MathML source to kill ring, if `org-export-copy-to-kill-ring' is
3703 (setq frag
(and (setq frag
(and (region-active-p)
3704 (buffer-substring (region-beginning)
3706 (loop for e in org-latex-regexps
3707 thereis
(when (string-match (nth 1 e
) frag
)
3708 (match-string (nth 2 e
) frag
)))))
3709 (read-string "LaTeX Fragment: " frag nil frag
))
3710 ,(let ((odf-filename (expand-file-name
3712 (file-name-sans-extension
3713 (or (file-name-nondirectory buffer-file-name
)))
3715 (file-name-directory buffer-file-name
))))
3716 (read-file-name "ODF filename: " nil odf-filename nil
3717 (file-name-nondirectory odf-filename
)))))
3718 (let ((filename (or odf-file
3721 (file-name-sans-extension
3722 (or (file-name-nondirectory buffer-file-name
)))
3724 (file-name-directory buffer-file-name
)))))
3725 (org-e-odt--export-wrap
3727 (let* ((buffer (progn
3728 (require 'nxml-mode
)
3729 (let ((nxml-auto-insert-xml-declaration-flag nil
))
3730 (find-file-noselect (concat org-e-odt-zip-dir
3731 "content.xml") t
))))
3732 (coding-system-for-write 'utf-8
)
3733 (save-buffer-coding-system 'utf-8
))
3735 (set-buffer-file-coding-system coding-system-for-write
)
3736 (let ((mathml (org-create-math-formula latex-frag
)))
3737 (unless mathml
(error "No Math formula created"))
3739 ;; Add MathML to kill ring, if needed.
3740 (when org-export-copy-to-kill-ring
3741 (org-kill-new (buffer-string))))))))
3744 (defun org-e-odt-export-as-odf-and-open ()
3745 "Export LaTeX fragment as OpenDocument formula and immediately open it.
3746 Use `org-e-odt-export-as-odf' to read LaTeX fragment and OpenDocument
3749 (org-open-file (call-interactively 'org-e-odt-export-as-odf
)))
3752 ;;;; Export to OpenDocument Text
3755 (defun org-e-odt-export-to-odt
3756 (&optional subtreep visible-only body-only ext-plist pub-dir
)
3757 "Export current buffer to a HTML file.
3759 If narrowing is active in the current buffer, only export its
3762 If a region is active, export that region.
3764 When optional argument SUBTREEP is non-nil, export the sub-tree
3765 at point, extracting information from the headline properties
3768 When optional argument VISIBLE-ONLY is non-nil, don't export
3769 contents of hidden elements.
3771 When optional argument BODY-ONLY is non-nil, only write code
3772 between \"\\begin{document}\" and \"\\end{document}\".
3774 EXT-PLIST, when provided, is a property list with external
3775 parameters overriding Org default settings, but still inferior to
3776 file-local settings.
3778 When optional argument PUB-DIR is set, use it as the publishing
3781 Return output file's name."
3783 (org-e-odt--export-wrap
3784 (org-export-output-file-name ".odt" subtreep pub-dir
)
3785 (let* ((org-e-odt-embedded-images-count 0)
3786 (org-e-odt-embedded-formulas-count 0)
3787 (org-e-odt-automatic-styles nil
)
3788 (org-e-odt-object-counters nil
)
3789 ;; Let `htmlfontify' know that we are interested in collecting
3791 (hfy-user-sheet-assoc nil
))
3792 ;; Initialize content.xml and kick-off the export process.
3793 (let ((out-buf (progn
3794 (require 'nxml-mode
)
3795 (let ((nxml-auto-insert-xml-declaration-flag nil
))
3797 (concat org-e-odt-zip-dir
"content.xml") t
)))))
3798 (org-export-to-buffer 'e-odt out-buf subtreep visible-only body-only
)))))
3801 ;;;; Convert between OpenDocument and other formats
3803 (defun org-e-odt-reachable-p (in-fmt out-fmt
)
3804 "Return non-nil if IN-FMT can be converted to OUT-FMT."
3806 (let ((reachable-formats (org-e-odt-do-reachable-formats in-fmt
)))
3807 (dolist (e reachable-formats
)
3808 (let ((out-fmt-spec (assoc out-fmt
(cdr e
))))
3810 (throw 'done
(cons (car e
) out-fmt-spec
))))))))
3812 (defun org-e-odt-do-convert (in-file out-fmt
&optional prefix-arg
)
3813 "Workhorse routine for `org-e-odt-convert'."
3814 (require 'browse-url
)
3815 (let* ((in-file (expand-file-name (or in-file buffer-file-name
)))
3816 (dummy (or (file-readable-p in-file
)
3817 (error "Cannot read %s" in-file
)))
3818 (in-fmt (file-name-extension in-file
))
3819 (out-fmt (or out-fmt
(error "Output format unspecified")))
3820 (how (or (org-e-odt-reachable-p in-fmt out-fmt
)
3821 (error "Cannot convert from %s format to %s format?"
3823 (convert-process (car how
))
3824 (out-file (concat (file-name-sans-extension in-file
) "."
3825 (nth 1 (or (cdr how
) out-fmt
))))
3826 (extra-options (or (nth 2 (cdr how
)) ""))
3827 (out-dir (file-name-directory in-file
))
3828 (cmd (format-spec convert-process
3829 `((?i .
,(shell-quote-argument in-file
))
3830 (?I .
,(browse-url-file-url in-file
))
3833 (?O .
,(browse-url-file-url out-file
))
3834 (?d .
, (shell-quote-argument out-dir
))
3835 (?D .
,(browse-url-file-url out-dir
))
3836 (?x .
,extra-options
)))))
3837 (when (file-exists-p out-file
)
3838 (delete-file out-file
))
3840 (message "Executing %s" cmd
)
3841 (let ((cmd-output (shell-command-to-string cmd
)))
3842 (message "%s" cmd-output
))
3845 ((file-exists-p out-file
)
3846 (message "Exported to %s" out-file
)
3848 (message "Opening %s..." out-file
)
3849 (org-open-file out-file
))
3852 (message "Export to %s failed" out-file
)
3855 (defun org-e-odt-do-reachable-formats (in-fmt)
3856 "Return verbose info about formats to which IN-FMT can be converted.
3857 Return a list where each element is of the
3858 form (CONVERTER-PROCESS . OUTPUT-FMT-ALIST). See
3859 `org-e-odt-convert-processes' for CONVERTER-PROCESS and see
3860 `org-e-odt-convert-capabilities' for OUTPUT-FMT-ALIST."
3862 (and org-e-odt-convert-process
3863 (cadr (assoc-string org-e-odt-convert-process
3864 org-e-odt-convert-processes t
))))
3866 (and org-e-odt-convert-process
3867 (cadr (assoc-string org-e-odt-convert-process
3868 org-e-odt-convert-processes t
))
3869 org-e-odt-convert-capabilities
))
3872 (dolist (c capabilities
)
3873 (when (member in-fmt
(nth 1 c
))
3874 (push (cons converter
(nth 2 c
)) reachable-formats
))))
3877 (defun org-e-odt-reachable-formats (in-fmt)
3878 "Return list of formats to which IN-FMT can be converted.
3879 The list of the form (OUTPUT-FMT-1 OUTPUT-FMT-2 ...)."
3881 (mapc (lambda (e) (add-to-list 'l e
))
3882 (apply 'append
(mapcar
3883 (lambda (e) (mapcar 'car
(cdr e
)))
3884 (org-e-odt-do-reachable-formats in-fmt
))))
3887 (defun org-e-odt-convert-read-params ()
3888 "Return IN-FILE and OUT-FMT params for `org-e-odt-do-convert'.
3889 This is a helper routine for interactive use."
3890 (let* ((input (if (featurep 'ido
) 'ido-completing-read
'completing-read
))
3891 (in-file (read-file-name "File to be converted: "
3892 nil buffer-file-name t
))
3893 (in-fmt (file-name-extension in-file
))
3894 (out-fmt-choices (org-e-odt-reachable-formats in-fmt
))
3896 (or (and out-fmt-choices
3897 (funcall input
"Output format: "
3898 out-fmt-choices nil nil nil
))
3900 "No known converter or no known output formats for %s files"
3902 (list in-file out-fmt
)))
3905 (defun org-e-odt-convert (&optional in-file out-fmt prefix-arg
)
3906 "Convert IN-FILE to format OUT-FMT using a command line converter.
3907 IN-FILE is the file to be converted. If unspecified, it defaults
3908 to variable `buffer-file-name'. OUT-FMT is the desired output
3909 format. Use `org-e-odt-convert-process' as the converter.
3910 If PREFIX-ARG is non-nil then the newly converted file is opened
3911 using `org-open-file'."
3913 (append (org-e-odt-convert-read-params) current-prefix-arg
))
3914 (org-e-odt-do-convert in-file out-fmt prefix-arg
))
3916 ;;; Library Initializations
3920 ;; Let Org open all OpenDocument files using system-registered app
3921 (add-to-list 'org-file-apps
3922 (cons (concat "\\." (car desc
) "\\'") 'system
))
3923 ;; Let Emacs open all OpenDocument files in archive mode
3924 (add-to-list 'auto-mode-alist
3925 (cons (concat "\\." (car desc
) "\\'") 'archive-mode
)))
3926 org-e-odt-file-extensions
)
3928 (provide 'org-e-odt
)
3930 ;;; org-e-odt.el ends here