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 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/>.
35 (defvar org-e-odt-translate-alist
36 '((babel-call . org-e-odt-babel-call
)
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 (comment . org-e-odt-comment
)
42 (comment-block . org-e-odt-comment-block
)
43 (drawer . org-e-odt-drawer
)
44 (dynamic-block . org-e-odt-dynamic-block
)
45 (entity . org-e-odt-entity
)
46 (example-block . org-e-odt-example-block
)
47 (export-block . org-e-odt-export-block
)
48 (export-snippet . org-e-odt-export-snippet
)
49 (fixed-width . org-e-odt-fixed-width
)
50 (footnote-definition . org-e-odt-footnote-definition
)
51 (footnote-reference . org-e-odt-footnote-reference
)
52 (headline . org-e-odt-headline
)
53 (horizontal-rule . org-e-odt-horizontal-rule
)
54 (inline-babel-call . org-e-odt-inline-babel-call
)
55 (inline-src-block . org-e-odt-inline-src-block
)
56 (inlinetask . org-e-odt-inlinetask
)
57 (italic . org-e-odt-italic
)
58 (item . org-e-odt-item
)
59 (keyword . org-e-odt-keyword
)
60 (latex-environment . org-e-odt-latex-environment
)
61 (latex-fragment . org-e-odt-latex-fragment
)
62 (line-break . org-e-odt-line-break
)
63 (link . org-e-odt-link
)
64 (macro . org-e-odt-macro
)
65 (paragraph . org-e-odt-paragraph
)
66 (plain-list . org-e-odt-plain-list
)
67 (plain-text . org-e-odt-plain-text
)
68 (planning . org-e-odt-planning
)
69 (property-drawer . org-e-odt-property-drawer
)
70 (quote-block . org-e-odt-quote-block
)
71 (quote-section . org-e-odt-quote-section
)
72 (radio-target . org-e-odt-radio-target
)
73 (section . org-e-odt-section
)
74 (special-block . org-e-odt-special-block
)
75 (src-block . org-e-odt-src-block
)
76 (statistics-cookie . org-e-odt-statistics-cookie
)
77 (strike-through . org-e-odt-strike-through
)
78 (subscript . org-e-odt-subscript
)
79 (superscript . org-e-odt-superscript
)
80 (table . org-e-odt-table
)
81 (table-cell . org-e-odt-table-cell
)
82 (table-row . org-e-odt-table-row
)
83 (target . org-e-odt-target
)
84 (template . org-e-odt-template
)
85 (timestamp . org-e-odt-timestamp
)
86 (underline . org-e-odt-underline
)
87 (verbatim . org-e-odt-verbatim
)
88 (verse-block . org-e-odt-verse-block
))
89 "Alist between element or object types and translators.")
91 (defconst org-e-odt-options-alist
93 ;; (:agenda-style nil nil org-agenda-export-html-style)
94 ;; (:convert-org-links nil nil org-e-odt-link-org-files-as-html)
95 ;; ;; FIXME Use (org-xml-encode-org-text-skip-links s) ??
96 ;; ;; (:expand-quoted-html nil "@" org-e-odt-expand)
97 ;; (:inline-images nil nil org-e-odt-inline-images)
98 ;; ;; (:link-home nil nil org-e-odt-link-home) FIXME
99 ;; ;; (:link-up nil nil org-e-odt-link-up) FIXME
100 ;; (:style nil nil org-e-odt-style)
101 ;; (:style-extra nil nil org-e-odt-style-extra)
102 ;; (:style-include-default nil nil org-e-odt-style-include-default)
103 ;; (:style-include-scripts nil nil org-e-odt-style-include-scripts)
104 ;; ;; (:timestamp nil nil org-e-odt-with-timestamp)
105 ;; (:html-extension nil nil org-e-odt-extension)
106 ;; (:html-postamble nil nil org-e-odt-postamble)
107 ;; (:html-preamble nil nil org-e-odt-preamble)
108 ;; (:html-table-tag nil nil org-e-odt-table-tag)
109 ;; (:xml-declaration nil nil org-e-odt-xml-declaration)
110 (:odt-styles-file
"ODT_STYLES_FILE" nil nil t
)
111 (:LaTeX-fragments nil
"LaTeX" org-export-with-LaTeX-fragments
))
112 "Alist between ODT export properties and ways to set them.
113 See `org-export-options-alist' for more information on the
114 structure of the values.")
118 ;; org-e-odt-preprocess-latex-fragments
119 ;; org-export-as-e-odt-and-open
120 ;; org-export-as-e-odt-batch
121 ;; org-export-as-e-odt
123 (defun org-e-odt-get-style-name-for-entity (category &optional entity
)
124 (let ((entity (or entity
'default
)))
126 (cdr (assoc entity
(cdr (assoc category
127 org-e-odt-org-styles-alist
))))
128 (cdr (assoc entity
(cdr (assoc category
129 org-e-odt-default-org-styles-alist
))))
130 (error "Cannot determine style name for entity %s of type %s"
133 ;; Following variable is let bound when `org-do-lparse' is in
134 ;; progress. See org-html.el.
136 (defun org-e-odt-format-preamble (info)
137 (let* ((title (org-export-data (plist-get info
:title
) info
))
138 (author (and (plist-get info
:with-author
)
139 (let ((auth (plist-get info
:author
)))
140 (and auth
(org-export-data auth info
)))))
141 (date (plist-get info
:date
))
142 (iso-date (org-e-odt-format-date date
))
143 (date (org-e-odt-format-date date
"%d %b %Y"))
144 (email (plist-get info
:email
))
145 ;; switch on or off above vars based on user settings
146 (author (and (plist-get info
:with-author
) (or author email
)))
147 ;; (date (and (plist-get info :time-stamp-file) date))
148 (email (and (plist-get info
:with-email
) email
)))
153 (org-e-odt-format-stylized-paragraph
154 'title
(format "\n<text:title>%s</text:title>" title
))
156 "\n<text:p text:style-name=\"OrgTitle\"/>"))
158 ((and author
(not email
))
161 (org-e-odt-format-stylized-paragraph
163 (format "<text:initial-creator>%s</text:initial-creator>" author
))
165 "\n<text:p text:style-name=\"OrgSubtitle\"/>"))
169 (org-e-odt-format-stylized-paragraph
171 (org-e-odt-format-link
172 (format "<text:initial-creator>%s</text:initial-creator>" author
)
173 (concat "mailto:" email
)))
175 "\n<text:p text:style-name=\"OrgSubtitle\"/>")))
179 (org-e-odt-format-stylized-paragraph
181 (org-e-odt-format-tags
182 '("<text:date style:data-style-name=\"%s\" text:date-value=\"%s\">"
184 date
"N75" iso-date
))
186 "<text:p text:style-name=\"OrgSubtitle\"/>")))))
188 (defun org-e-odt-begin-section (style &optional name
)
189 (let ((default-name (car (org-e-odt-add-automatic-style "Section"))))
190 (format "<text:section text:style-name=\"%s\" text:name=\"%s\">"
191 style
(or name default-name
))))
193 (defun org-e-odt-end-section ()
196 (defun org-e-odt-begin-paragraph (&optional style
)
197 (format "<text:p%s>" (org-e-odt-get-extra-attrs-for-paragraph-style style
)))
199 (defun org-e-odt-end-paragraph ()
202 (defun org-e-odt-get-extra-attrs-for-paragraph-style (style)
206 ((stringp style
) style
)
207 ((symbolp style
) (org-e-odt-get-style-name-for-entity
210 (error "Don't know how to handle paragraph style %s" style
))
211 (format " text:style-name=\"%s\"" style-name
)))
213 (defun org-e-odt-format-stylized-paragraph (style text
)
214 (format "\n<text:p%s>%s</text:p>"
215 (org-e-odt-get-extra-attrs-for-paragraph-style style
)
218 (defun org-e-odt-format-author (&optional author
)
219 (when (setq author
(or author
(plist-get org-lparse-opt-plist
:author
)))
220 (format "<dc:creator>%s</dc:creator>" author
)))
222 (defun org-e-odt-format-date (&optional org-ts fmt
)
225 (and (stringp org-ts
)
226 (string-match org-ts-regexp0 org-ts
)
228 (org-fix-decoded-time
229 (org-parse-time-string (match-string 0 org-ts
) t
)))))
232 (fmt (format-time-string fmt time
))
233 (t (setq date
(format-time-string "%Y-%m-%dT%H:%M:%S%z" time
))
234 (format "%s:%s" (substring date
0 -
2) (substring date -
2)))))))
236 (defun org-e-odt-begin-annotation (&optional author date
)
238 "<office:annotation>\n"
239 (and author
(org-e-odt-format-author author
))
240 (org-e-odt-format-tags
241 '("<dc:date>" .
"</dc:date>")
242 (org-e-odt-format-date
243 (or date
(plist-get org-lparse-opt-plist
:date
))))
244 (org-e-odt-begin-paragraph)))
246 (defun org-e-odt-end-annotation ()
247 "</office:annotation>")
249 (defun org-e-odt-begin-plain-list (ltype)
250 (let* ((style-name (org-e-odt-get-style-name-for-entity 'list ltype
))
252 ;; (if (or org-lparse-list-table-p
253 ;; (and (= 1 (length org-lparse-list-stack))
254 ;; (null org-e-odt-list-stack-stashed)))
255 ;; " text:continue-numbering=\"false\""
256 ;; " text:continue-numbering=\"true\"")
258 " text:continue-numbering=\"true\""
261 (format " text:style-name=\"%s\"" style-name
)))))
263 ((ordered unordered descriptive
)
265 ;; (org-e-odt-end-paragraph)
266 (format "<text:list%s>" extra
)))
267 (t (error "Unknown list type: %s" ltype
)))))
269 (defun org-e-odt-end-plain-list (ltype)
270 (if ltype
"</text:list>"
271 (error "Unknown list type: %s" ltype
)))
273 (defun org-e-odt-begin-list-item (ltype &optional arg headline
)
276 (assert (not headline
) t
)
277 (let* ((counter arg
) (extra ""))
278 (concat "<text:list-item>" ;; (org-e-odt-begin-paragraph)
280 ;; (if (= (length org-lparse-list-stack)
281 ;; (length org-e-odt-list-stack-stashed))
282 ;; "<text:list-header>" "<text:list-item>")
285 (let* ((id arg
) (extra ""))
288 ;; (org-e-odt-begin-paragraph)
289 (if headline
(org-e-odt-format-target headline id
)
290 (org-e-odt-format-bookmark "" id
)))
291 ;; (if (= (length org-lparse-list-stack)
292 ;; (length org-e-odt-list-stack-stashed))
293 ;; "<text:list-header>" "<text:list-item>")
296 (assert (not headline
) t
)
297 (let ((term (or arg
"(no term)")))
299 (org-e-odt-format-tags
300 '("<text:list-item>" .
"</text:list-item>")
301 (org-e-odt-format-stylized-paragraph 'definition-term term
))
302 (org-e-odt-begin-list-item 'unordered
)
303 (org-e-odt-begin-plain-list 'descriptive
)
304 (org-e-odt-begin-list-item 'unordered
))))
305 (t (error "Unknown list type"))))
307 (defun org-e-odt-end-list-item (ltype)
310 ;; (org-lparse-insert-tag
311 ;; (if (= (length org-lparse-list-stack)
312 ;; (length org-e-odt-list-stack-stashed))
313 ;; (prog1 "</text:list-header>"
314 ;; (setq org-e-odt-list-stack-stashed nil))
315 ;; "</text:list-item>")
321 (org-e-odt-end-list-item 'unordered
)
322 (org-e-odt-end-plain-list 'descriptive
)
323 (org-e-odt-end-list-item 'unordered
)
325 (t (error "Unknown list type"))))
327 (defun org-e-odt-write-automatic-styles ()
328 "Write automatic styles to \"content.xml\"."
330 (find-file-noselect (expand-file-name "content.xml") t
)
331 ;; position the cursor
332 (goto-char (point-min))
333 (re-search-forward " </office:automatic-styles>" nil t
)
334 (goto-char (match-beginning 0))
335 ;; write automatic table styles
336 (loop for
(style-name props
) in
337 (plist-get org-e-odt-automatic-styles
'Table
) do
338 (when (setq props
(or (plist-get props
:rel-width
) 96))
339 (insert (format org-e-odt-table-style-format style-name props
))))))
341 (defun org-e-odt-update-display-level (&optional level
)
343 (find-file-noselect (expand-file-name "content.xml") t
)
344 ;; position the cursor.
345 (goto-char (point-min))
346 ;; remove existing sequence decls.
347 (when (re-search-forward "<text:sequence-decls" nil t
)
348 (delete-region (match-beginning 0)
349 (re-search-forward "</text:sequence-decls>" nil nil
)))
352 <text:sequence-decls>")
353 (loop for x in org-e-odt-category-map-alist
355 <text:sequence-decl text:display-outline-level=\"%d\" text:name=\"%s\"/>"
358 </text:sequence-decls>")))
360 (defun org-e-odt-add-automatic-style (object-type &optional object-props
)
361 "Create an automatic style of type OBJECT-TYPE with param OBJECT-PROPS.
362 OBJECT-PROPS is (typically) a plist created by passing
363 \"#+ATTR_ODT: \" option of the object in question to
364 `org-e-odt-parse-block-attributes'.
366 Use `org-e-odt-object-counters' to generate an automatic
367 OBJECT-NAME and STYLE-NAME. If OBJECT-PROPS is non-nil, add a
368 new entry in `org-e-odt-automatic-styles'. Return (OBJECT-NAME
370 (assert (stringp object-type
))
371 (let* ((object (intern object-type
))
373 (seqno (1+ (or (plist-get org-e-odt-object-counters seqvar
) 0)))
374 (object-name (format "%s%d" object-type seqno
)) style-name
)
375 (setq org-e-odt-object-counters
376 (plist-put org-e-odt-object-counters seqvar seqno
))
378 (setq style-name
(format "Org%s" object-name
))
379 (setq org-e-odt-automatic-styles
380 (plist-put org-e-odt-automatic-styles object
381 (append (list (list style-name object-props
))
382 (plist-get org-e-odt-automatic-styles object
)))))
383 (cons object-name style-name
)))
385 (defun org-e-odt-begin-toc (lang-specific-heading max-level
)
388 <text:table-of-content text:style-name=\"Sect2\" text:protected=\"true\" text:name=\"Table of Contents1\">
389 <text:table-of-content-source text:outline-level=\"%d\">
390 <text:index-title-template text:style-name=\"Contents_20_Heading\">%s</text:index-title-template>
391 " max-level lang-specific-heading
)
393 (let ((entry-templates ""))
394 (loop for level from
1 upto
10
395 do
(setq entry-templates
396 (concat entry-templates
399 <text:table-of-content-entry-template text:outline-level=\"%d\" text:style-name=\"Contents_20_%d\">
400 <text:index-entry-link-start text:style-name=\"Internet_20_link\"/>
401 <text:index-entry-chapter/>
402 <text:index-entry-text/>
403 <text:index-entry-link-end/>
404 </text:table-of-content-entry-template>
409 </text:table-of-content-source>
412 <text:index-title text:style-name=\"Sect1\" text:name=\"Table of Contents1_Head\">
413 <text:p text:style-name=\"Contents_20_Heading\">%s</text:p>
415 " lang-specific-heading
)))
417 (defun org-e-odt-end-toc ()
420 </text:table-of-content>
423 (defun org-e-odt-format-toc-entry (snumber todo headline tags href
)
426 (setq headline
(concat
427 (and org-export-with-section-numbers
428 (concat snumber
". "))
432 (org-e-odt-format-spaces 3)
433 (org-e-odt-format-fontify tags
"tag")))))
435 (setq headline
(org-e-odt-format-fontify headline
"todo")))
437 (let ((org-e-odt-suppress-xref t
))
438 (org-e-odt-format-link headline
(concat "#" href
))))
440 (defun org-e-odt-format-toc-item (toc-entry level org-last-level
)
441 (let ((style (format "Contents_20_%d" level
)))
442 (concat "\n" (org-e-odt-format-stylized-paragraph style toc-entry
) "\n")))
444 ;; Following variable is let bound during 'ORG-LINK callback. See
447 (defun org-e-odt-format-link (desc href
&optional attr
)
449 ((and (= (string-to-char href
) ?
#) (not org-e-odt-suppress-xref
))
450 (setq href
(substring href
1))
451 (let ((xref-format "text"))
453 (setq desc
(format "%d" desc
) xref-format
"number"))
455 (setq desc
(mapconcat 'identity desc
".") xref-format
"chapter"))
456 (setq href
(concat org-e-odt-bookmark-prefix href
))
457 (org-e-odt-format-tags-simple
458 '("<text:bookmark-ref text:reference-format=\"%s\" text:ref-name=\"%s\">" .
459 "</text:bookmark-ref>")
460 desc xref-format href
)))
461 (org-lparse-link-description-is-image
462 (org-e-odt-format-tags
463 '("<draw:a xlink:type=\"simple\" xlink:href=\"%s\" %s>" .
"</draw:a>")
464 desc href
(or attr
"")))
466 (org-e-odt-format-tags-simple
467 '("<text:a xlink:type=\"simple\" xlink:href=\"%s\" %s>" .
"</text:a>")
468 desc href
(or attr
"")))))
470 (defun org-e-odt-format-spaces (n)
474 " " (org-e-odt-format-tags "<text:s text:c=\"%d\"/>" "" (1- n
))))
477 (defun org-e-odt-format-tabs (&optional n
)
478 (let ((tab "<text:tab/>")
482 (defun org-e-odt-format-line-break ()
483 (org-e-odt-format-tags "<text:line-break/>" ""))
485 (defun org-e-odt-format-horizontal-line ()
486 (org-e-odt-format-stylized-paragraph 'horizontal-line
""))
488 (defun org-e-odt-encode-plain-text (line &optional no-whitespace-filling
)
489 (setq line
(org-e-html-encode-plain-text line
))
490 (if no-whitespace-filling line
491 (org-e-odt-fill-tabs-and-spaces line
)))
493 (defun org-e-odt-format-line (line)
494 (case org-lparse-dyn-current-environment
496 (org-e-odt-format-stylized-paragraph
497 'fixedwidth
(org-e-odt-encode-plain-text line
)) "\n"))
498 (t (concat line
"\n"))))
500 (defun org-e-odt-format-comment (fmt &rest args
)
501 (let ((comment (apply 'format fmt args
)))
502 (format "\n<!-- %s -->\n" comment
)))
504 (defun org-e-odt-format-org-entity (wd)
505 (org-entity-get-representation wd
'utf8
))
507 (defun org-e-odt-fill-tabs-and-spaces (line)
508 (replace-regexp-in-string
509 "\\([\t]\\|\\([ ]+\\)\\)" (lambda (s)
511 ((string= s
"\t") (org-e-odt-format-tabs))
512 (t (org-e-odt-format-spaces (length s
))))) line
))
514 (defun org-e-odt-hfy-face-to-css (fn)
515 "Create custom style for face FN.
516 When FN is the default face, use it's foreground and background
517 properties to create \"OrgSrcBlock\" paragraph style. Otherwise
518 use it's color attribute to create a character style whose name
519 is obtained from FN. Currently all attributes of FN other than
522 The style name for a face FN is derived using the following
523 operations on the face name in that order - de-dash, CamelCase
524 and prefix with \"OrgSrc\". For example,
525 `font-lock-function-name-face' is associated with
526 \"OrgSrcFontLockFunctionNameFace\"."
527 (let* ((css-list (hfy-face-to-style fn
))
528 (style-name ((lambda (fn)
531 'capitalize
(split-string
532 (hfy-face-or-def-to-name fn
) "-")
534 (color-val (cdr (assoc "color" css-list
)))
535 (background-color-val (cdr (assoc "background" css-list
)))
536 (style (and org-e-odt-create-custom-styles-for-srcblocks
539 (format org-src-block-paragraph-format
540 background-color-val color-val
))
544 <style:style style:name=\"%s\" style:family=\"text\">
545 <style:text-properties fo:color=\"%s\"/>
546 </style:style>" style-name color-val
))))))
547 (cons style-name style
)))
549 (defun org-e-odt-insert-custom-styles-for-srcblocks (styles)
550 "Save STYLES used for colorizing of source blocks.
551 Update styles.xml with styles that were collected as part of
552 `org-e-odt-hfy-face-to-css' callbacks."
555 (find-file-noselect (expand-file-name "styles.xml") t
)
556 (goto-char (point-min))
557 (when (re-search-forward "</office:styles>" nil t
)
558 (goto-char (match-beginning 0))
559 (insert "\n<!-- Org Htmlfontify Styles -->\n" styles
"\n")))))
561 (defun org-e-odt-remap-stylenames (style-name)
563 (cdr (assoc style-name
'(("timestamp-wrapper" .
"OrgTimestampWrapper")
564 ("timestamp" .
"OrgTimestamp")
565 ("timestamp-kwd" .
"OrgTimestampKeyword")
569 ("target" .
"OrgTarget"))))
572 (defun org-e-odt-format-fontify (text style
&optional id
)
576 (org-e-odt-remap-stylenames style
))
578 (org-e-odt-get-style-name-for-entity 'character style
))
580 (assert (< 1 (length style
)))
581 (let ((parent-style (pop style
)))
582 (mapconcat (lambda (s)
583 ;; (assert (stringp s) t)
584 (org-e-odt-remap-stylenames s
)) style
"")
585 (org-e-odt-remap-stylenames parent-style
)))
586 (t (error "Don't how to handle style %s" style
)))))
587 (org-e-odt-format-tags-simple
588 '("<text:span text:style-name=\"%s\">" .
"</text:span>")
591 (defun org-e-odt-relocate-relative-path (path dir
)
592 (if (file-name-absolute-p path
) path
593 (file-relative-name (expand-file-name path dir
)
594 (expand-file-name "eyecandy" dir
))))
596 (defun org-e-odt-format-formula (element info
)
598 ((eq (org-element-type element
) 'link
) ; FIXME
599 (let* ((type (org-element-property :type element
))
600 (raw-path (org-element-property :path element
)))
602 ((file-name-absolute-p raw-path
)
603 (expand-file-name raw-path
))
605 ((member (org-element-type element
)
606 '(latex-fragment latex-environment
))
607 (let* ((latex-frag (org-remove-indentation
608 (org-element-property
610 (formula-link (org-e-odt-format-latex
611 latex-frag
'mathml
)))
613 (string-match "file:\\([^]]*\\)" formula-link
)
614 (match-string 1 formula-link
))))
615 (t (error "what is this?"))))
617 (case (org-element-type element
)
618 (link (org-export-get-parent-paragraph element info
))
620 (captions (org-e-odt-format-label caption-from info
'definition
))
621 (caption (car captions
))
623 (org-e-odt-format-tags
624 "<draw:object xlink:href=\"%s\" xlink:type=\"simple\" xlink:show=\"embed\" xlink:actuate=\"onLoad\"/>" ""
625 (file-name-directory (org-e-odt-copy-formula-file src
))))
626 (embed-as (if caption
'paragraph
'character
))
629 ((eq embed-as
'character
)
630 (org-e-odt-format-entity "InlineFormula" href width height
))
632 (let ((table-info nil
)
634 '(:alignment
["c" "c"]
635 :column-groups
[nil nil
]
637 :special-column-p nil
:width
[8 1]))
638 (org-lparse-table-ncols 2)) ; FIXME
639 (org-e-odt-list-table ; FIXME
642 (org-e-odt-format-entity
643 "CaptionedDisplayFormula" href width height captions
)
644 (let* ((org-e-odt-category-map-alist
645 '(("__Table__" "Table" "value")
646 ("__Figure__" "Illustration" "value")
647 ("__MathFormula__" "Text" "math-label")
648 ("__DvipngImage__" "Equation" "value")
649 ("__Listing__" "Listing" "value"))))
650 (car (org-e-odt-format-label caption-from info
'definition
)))))
651 '(table (:attr_odt
(":style \"OrgEquation\""))) info
))))))
653 (defun org-e-odt-copy-formula-file (path)
654 "Returns the internal name of the file"
655 (let* ((src-file (expand-file-name
656 path
(file-name-directory org-current-export-file
)))
657 (target-dir (format "Formula-%04d/"
658 (incf org-e-odt-embedded-formulas-count
)))
659 (target-file (concat target-dir
"content.xml")))
660 (message "Embedding %s as %s ..."
661 (substring-no-properties path
) target-file
)
663 (make-directory target-dir
)
664 (org-e-odt-create-manifest-file-entry
665 "application/vnd.oasis.opendocument.formula" target-dir
"1.2")
667 (case (org-e-odt-is-formula-link-p src-file
)
669 (copy-file src-file target-file
'overwrite
))
671 (org-e-odt-zip-extract-one src-file
"content.xml" target-dir
))
673 (error "%s is not a formula file" src-file
)))
675 (org-e-odt-create-manifest-file-entry "text/xml" target-file
)
678 (defun org-e-odt-is-formula-link-p (file)
679 (let ((case-fold-search nil
))
681 ((string-match "\\.\\(mathml\\|mml\\)\\'" file
)
683 ((string-match "\\.odf\\'" file
)
686 (defun org-e-odt-format-org-link (opt-plist type-1 path fragment desc attr
688 "Make a OpenDocument link.
689 OPT-PLIST is an options list.
690 TYPE-1 is the device-type of the link (THIS://foo.html).
691 PATH is the path of the link (http://THIS#location).
692 FRAGMENT is the fragment part of the link, if any (foo.html#THIS).
693 DESC is the link description, if any.
694 ATTR is a string of other attributes of the a element."
695 (declare (special org-lparse-par-open
))
698 (and (member type-1
'("http" "https" "file"))
699 (org-lparse-should-inline-p path descp
)
701 (type (if (equal type-1
"id") "file" type-1
))
705 ;; check for inlined images
706 ((and (member type
'("file"))
709 filename org-e-odt-inline-image-extensions
)
711 (org-e-odt-format-inline-image thefile
))
712 ;; check for embedded formulas
713 ((and (member type
'("file"))
715 (org-e-odt-is-formula-link-p filename
)
717 (org-e-odt-format-formula thefile
))
718 ((string= type
"coderef")
719 (let* ((ref fragment
)
720 (lineno-or-ref (cdr (assoc ref org-export-code-refs
)))
721 (desc (and descp desc
))
722 (org-e-odt-suppress-xref nil
)
723 (href (org-xml-format-href (concat "#coderef-" ref
))))
725 ((and (numberp lineno-or-ref
) (not desc
))
726 (org-e-odt-format-link lineno-or-ref href
))
727 ((and (numberp lineno-or-ref
) desc
728 (string-match (regexp-quote (concat "(" ref
")")) desc
))
729 (format (replace-match "%s" t t desc
)
730 (org-e-odt-format-link lineno-or-ref href
)))
733 (if (and desc
(string-match
734 (regexp-quote (concat "(" ref
")"))
736 (replace-match "%s" t t desc
)
739 (org-e-odt-format-link (org-xml-format-desc desc
) href
)))))
741 (when (string= type
"file")
744 ((file-name-absolute-p path
)
745 (concat "file://" (expand-file-name path
)))
746 (t (org-e-odt-relocate-relative-path
747 thefile org-current-export-file
)))))
749 (when (and (member type
'("" "http" "https" "file")) fragment
)
750 (setq thefile
(concat thefile
"#" fragment
)))
752 (setq thefile
(org-xml-format-href thefile
))
754 (when (not (member type
'("" "file")))
755 (setq thefile
(concat type
":" thefile
)))
757 (let ((org-e-odt-suppress-xref nil
))
758 (org-e-odt-format-link
759 (org-xml-format-desc desc
) thefile attr
)))))))
761 (defun org-e-odt-format-anchor (text name
&optional class
)
762 (org-e-odt-format-target text name
))
764 (defun org-e-odt-format-bookmark (text id
)
766 (org-e-odt-format-tags "<text:bookmark text:name=\"%s\"/>" text id
)
769 (defun org-e-odt-format-target (text id
)
770 (let ((name (concat org-e-odt-bookmark-prefix id
)))
772 (and id
(org-e-odt-format-tags
773 "<text:bookmark-start text:name=\"%s\"/>" "" name
))
774 (org-e-odt-format-bookmark text id
)
775 (and id
(org-e-odt-format-tags
776 "<text:bookmark-end text:name=\"%s\"/>" "" name
)))))
778 (defun org-e-odt-format-footnote (n def
)
779 (setq n
(format "%d" n
))
780 (let ((id (concat "fn" n
))
781 (note-class "footnote")
782 (par-style "Footnote"))
783 (org-e-odt-format-tags-simple
784 '("<text:note text:id=\"%s\" text:note-class=\"%s\">" .
"</text:note>")
786 (org-e-odt-format-tags-simple
787 '("<text:note-citation>" .
"</text:note-citation>") n
)
788 (org-e-odt-format-tags-simple
789 '("<text:note-body>" .
"</text:note-body>") def
))
792 (defun org-e-odt-format-footnote-reference (n def refcnt
)
794 (org-e-odt-format-footnote n def
)
795 (org-e-odt-format-footnote-ref n
)))
797 (defun org-e-odt-format-footnote-ref (n)
798 (setq n
(format "%d" n
))
799 (let ((note-class "footnote")
801 (ref-name (concat "fn" n
)))
802 (org-e-odt-format-tags-simple
803 '("<text:span text:style-name=\"%s\">" .
"</text:span>")
804 (org-e-odt-format-tags-simple
805 '("<text:note-ref text:note-class=\"%s\" text:reference-format=\"%s\" text:ref-name=\"%s\">" .
"</text:note-ref>")
806 n note-class ref-format ref-name
)
809 (defun org-e-odt-element-attributes (element info
)
810 (let* ((raw-attr (org-element-property :attr_odt element
))
811 (raw-attr (and raw-attr
812 (org-trim (mapconcat #'identity raw-attr
" ")))))
813 (unless (and raw-attr
(string-match "\\`(.*)\\'" raw-attr
))
814 (setq raw-attr
(format "(%s)" raw-attr
)))
815 (ignore-errors (read raw-attr
))))
817 (defun org-e-odt-format-object-description (title description
)
818 (concat (and title
(org-e-odt-format-tags
819 '("<svg:title>" .
"</svg:title>")
820 (org-e-odt-encode-plain-text title t
)))
821 (and description
(org-e-odt-format-tags
822 '("<svg:desc>" .
"</svg:desc>")
823 (org-e-odt-encode-plain-text description t
)))))
825 (defun org-e-odt-format-frame (text width height style
&optional
829 (if width
(format " svg:width=\"%0.2fcm\"" width
) "")
830 (if height
(format " svg:height=\"%0.2fcm\"" height
) "")
832 (format " text:anchor-type=\"%s\"" (or anchor-type
"paragraph")))))
833 (org-e-odt-format-tags
834 '("<draw:frame draw:style-name=\"%s\"%s>" .
"</draw:frame>")
835 (concat text
(org-e-odt-format-object-description
836 (get-text-property 0 :title text
)
837 (get-text-property 0 :description text
)))
840 (defun org-e-odt-format-textbox (text width height style
&optional
842 (org-e-odt-format-frame
843 (org-e-odt-format-tags
844 '("<draw:text-box %s>" .
"</draw:text-box>")
845 text
(concat (format " fo:min-height=\"%0.2fcm\"" (or height
.2))
847 (format " fo:min-width=\"%0.2fcm\"" (or width
.2)))))
848 width nil style extra anchor-type
))
850 (defun org-e-odt-merge-frame-params(default-frame-params user-frame-params
)
851 (if (not user-frame-params
) default-frame-params
852 (assert (= (length default-frame-params
) 3))
853 (assert (= (length user-frame-params
) 3))
854 (loop for user-frame-param in user-frame-params
855 for default-frame-param in default-frame-params
856 collect
(or user-frame-param default-frame-param
))))
858 (defun org-e-odt-copy-image-file (path)
859 "Returns the internal name of the file"
860 (let* ((image-type (file-name-extension path
))
861 (media-type (format "image/%s" image-type
))
862 (src-file (expand-file-name
863 path
(file-name-directory org-current-export-file
)))
864 (target-dir "Images/")
866 (format "%s%04d.%s" target-dir
867 (incf org-e-odt-embedded-images-count
) image-type
)))
868 (message "Embedding %s as %s ..."
869 (substring-no-properties path
) target-file
)
871 (when (= 1 org-e-odt-embedded-images-count
)
872 (make-directory target-dir
)
873 (org-e-odt-create-manifest-file-entry "" target-dir
))
875 (copy-file src-file target-file
'overwrite
)
876 (org-e-odt-create-manifest-file-entry media-type target-file
)
879 (defun org-e-odt-do-image-size (probe-method file
&optional dpi anchor-type
)
880 (setq dpi
(or dpi org-e-odt-pixels-per-inch
))
881 (setq anchor-type
(or anchor-type
"paragraph"))
882 (flet ((size-in-cms (size-in-pixels)
883 (flet ((pixels-to-cms (pixels)
884 (let* ((cms-per-inch 2.54)
885 (inches (/ pixels dpi
)))
886 (* cms-per-inch inches
))))
888 (cons (pixels-to-cms (car size-in-pixels
))
889 (pixels-to-cms (cdr size-in-pixels
)))))))
892 (size-in-cms (ignore-errors ; Emacs could be in batch mode
894 (image-size (create-image file
) 'pixels
))))
897 (let ((dim (shell-command-to-string
898 (format "identify -format \"%%w:%%h\" \"%s\"" file
))))
899 (when (string-match "\\([0-9]+\\):\\([0-9]+\\)" dim
)
900 (cons (string-to-number (match-string 1 dim
))
901 (string-to-number (match-string 2 dim
)))))))
903 (cdr (assoc-string anchor-type
904 org-e-odt-default-image-sizes-alist
))))))
906 (defun org-e-odt-image-size-from-file (file &optional user-width
907 user-height scale dpi embed-as
)
908 (unless (file-name-absolute-p file
)
909 (setq file
(expand-file-name
910 file
(file-name-directory org-current-export-file
))))
911 (let* (size width height
)
912 (unless (and user-height user-width
)
913 (loop for probe-method in org-e-odt-image-size-probe-method
915 do
(setq size
(org-e-odt-do-image-size
916 probe-method file dpi embed-as
)))
917 (or size
(error "Cannot determine Image size. Aborting ..."))
918 (setq width
(car size
) height
(cdr size
)))
921 (setq width
(* width scale
) height
(* height scale
)))
922 ((and user-height user-width
)
923 (setq width user-width height user-height
))
925 (setq width
(* user-height
(/ width height
)) height user-height
))
927 (setq height
(* user-width
(/ height width
)) width user-width
))
929 ;; ensure that an embedded image fits comfortably within a page
930 (let ((max-width (car org-e-odt-max-image-size
))
931 (max-height (cdr org-e-odt-max-image-size
)))
932 (when (or (> width max-width
) (> height max-height
))
933 (let* ((scale1 (/ max-width width
))
934 (scale2 (/ max-height height
))
935 (scale (min scale1 scale2
)))
936 (setq width
(* scale width
) height
(* scale height
)))))
937 (cons width height
)))
939 (defun org-e-odt-format-label (element info op
)
941 (case (org-element-type element
)
942 (link (org-export-get-parent-paragraph element info
))
944 ;; get label and caption.
945 (label (org-element-property :name caption-from
))
946 (caption (org-element-property :caption caption-from
))
947 (short-caption (cdr caption
))
948 ;; transcode captions.
949 (caption (and (car caption
) (org-export-data (car caption
) info
)))
950 (short-caption (and short-caption
951 (org-export-data short-caption info
))))
952 (when (or label caption
)
953 (let* ((default-category
955 ((eq (org-element-type element
) 'table
)
957 ((org-e-odt-standalone-image-p element info
)
959 ((member (org-element-type element
)
960 '(latex-environment latex-fragment
))
961 (let ((processing-type (plist-get info
:LaTeX-fragments
)))
963 ((eq processing-type
'dvipng
) "__DvipngImage__")
964 ((eq processing-type
'mathjax
) "__MathFormula__")
965 ((eq processing-type
't
) "__MathFormula__")
966 (t (error "Handle LaTeX:verbatim")))))
967 ((eq (org-element-type element
) 'src-block
)
969 (t (error "Handle enumeration of %S" element
))))
972 ((member (org-element-type element
)
973 '(table latex-environment src-block
))
975 ((org-e-odt-standalone-image-p element info
)
976 'org-e-odt-standalone-image-p
)
977 (t (error "Handle enumeration of %S" element
))))
978 (seqno (org-e-odt-enumerate-element
979 element info predicate
)) ; FIXME
980 ;; handle label props.
981 (label-props (assoc default-category org-e-odt-category-map-alist
))
982 ;; identify opendocument counter
983 (counter (nth 1 label-props
))
984 ;; identify label style
985 (label-style (nth 2 label-props
))
986 ;; grok language setting
987 (en-strings (assoc-default "en" org-e-odt-category-strings
))
988 (lang (plist-get info
:language
)) ; FIXME
989 (lang-strings (assoc-default lang org-e-odt-category-strings
))
990 ;; retrieve localized category sting
991 (pos (- (length org-e-odt-category-map-alist
)
992 (length (memq label-props org-e-odt-category-map-alist
))))
993 (category (or (nth pos lang-strings
) (nth pos en-strings
))))
996 ;; assign an internal label, if user has not provided one
997 (setq label
(or label
(format "%s-%s" default-category seqno
)))
998 (setq label
(org-solidify-link-text label
))
1002 (cadr (assoc-string label-style org-e-odt-label-styles t
))
1004 (?n .
,(org-e-odt-format-tags-simple
1005 '("<text:sequence text:ref-name=\"%s\" text:name=\"%s\" text:formula=\"ooow:%s+1\" style:num-format=\"1\">" .
"</text:sequence>")
1006 seqno label counter counter
))
1007 (?c .
,(or caption
""))))
1011 (setq label
(org-solidify-link-text label
))
1012 (let* ((fmt (cddr (assoc-string label-style org-e-odt-label-styles t
)))
1015 (org-e-odt-format-tags-simple
1016 '("<text:sequence-ref text:reference-format=\"%s\" text:ref-name=\"%s\">"
1017 .
"</text:sequence-ref>")
1018 (format-spec fmt2
`((?e .
,category
)
1019 (?n .
,seqno
))) fmt1 label
)))
1020 (t (error "Unknow %S on label" op
)))))))
1022 (defun org-e-odt-format-tags-1 (tag text prefix suffix
&rest args
)
1025 (concat prefix
(apply 'format
(car tag
) args
) text suffix
1026 (format (cdr tag
))))
1027 ((stringp tag
) ; singleton tag
1028 (concat prefix
(apply 'format tag args
) text
))))
1030 (defun org-e-odt-format-tags (tag text
&rest args
)
1031 (apply 'org-e-odt-format-tags-1 tag text
"\n" "\n" args
))
1033 (defun org-e-odt-format-tags-simple (tag text
&rest args
)
1034 (apply 'org-e-odt-format-tags-1 tag text nil nil args
))
1036 (defun org-e-odt-init-outfile ()
1037 (unless (executable-find "zip")
1038 ;; Not at all OSes ship with zip by default
1039 (error "Executable \"zip\" needed for creating OpenDocument files"))
1041 (let* ((outdir (make-temp-file
1042 (format org-e-odt-tmpdir-prefix
'odt
) t
)) ; FIXME
1043 (content-file (expand-file-name "content.xml" outdir
)))
1046 (setq org-e-odt-manifest-file-entries nil
1047 org-e-odt-embedded-images-count
0
1048 org-e-odt-embedded-formulas-count
0
1049 org-e-odt-section-count
0
1050 org-e-odt-list-stack-stashed nil
1051 org-e-odt-automatic-styles nil
1052 org-e-odt-object-counters nil
)
1054 ;; let `htmlfontify' know that we are interested in collecting
1057 (setq hfy-user-sheet-assoc nil
)
1060 (require 'nxml-mode
)
1061 (with-current-buffer
1062 (let ((nxml-auto-insert-xml-declaration-flag nil
))
1063 (find-file-noselect content-file t
))
1066 (defun org-e-odt-save-as-outfile (target opt-plist
)
1067 ;; write automatic styles
1068 (org-e-odt-write-automatic-styles)
1070 ;; update display levels
1071 (org-e-odt-update-display-level org-e-odt-display-outline-level
)
1073 ;; create mimetype file
1074 (let ((mimetype (org-e-odt-write-mimetype-file ;; org-lparse-backend FIXME
1076 (org-e-odt-create-manifest-file-entry mimetype
"/" "1.2"))
1078 ;; create a manifest entry for content.xml
1079 (org-e-odt-create-manifest-file-entry "text/xml" "content.xml")
1081 ;; write out the manifest entries before zipping
1082 (org-e-odt-write-manifest-file)
1084 (let ((xml-files '("mimetype" "META-INF/manifest.xml" "content.xml"
1086 (zipdir default-directory
))
1087 (when (or t
(equal org-lparse-backend
'odt
)) ; FIXME
1088 (push "styles.xml" xml-files
))
1089 (message "Switching to directory %s" (expand-file-name zipdir
))
1091 ;; save all xml files
1092 (mapc (lambda (file)
1093 (with-current-buffer
1094 (find-file-noselect (expand-file-name file
) t
)
1095 ;; prettify output if needed
1096 (when org-e-odt-prettify-xml
1097 (indent-region (point-min) (point-max)))
1101 (let* ((target-name (file-name-nondirectory target
))
1102 (target-dir (file-name-directory target
))
1103 (cmds `(("zip" "-mX0" ,target-name
"mimetype")
1104 ("zip" "-rmTq" ,target-name
"."))))
1105 (when (file-exists-p target
)
1106 ;; FIXME: If the file is locked this throws a cryptic error
1107 (delete-file target
))
1109 (let ((coding-system-for-write 'no-conversion
) exitcode err-string
)
1110 (message "Creating odt file...")
1113 (message "Running %s" (mapconcat 'identity cmd
" "))
1115 (with-output-to-string
1117 (apply 'call-process
(car cmd
)
1118 nil standard-output nil
(cdr cmd
)))))
1119 (or (zerop exitcode
)
1120 (ignore (message "%s" err-string
))
1121 (error "Unable to create odt file (%S)" exitcode
)))
1124 ;; move the file from outdir to target-dir
1125 (rename-file target-name target-dir
)
1127 ;; kill all xml buffers
1128 (mapc (lambda (file)
1130 (find-file-noselect (expand-file-name file zipdir
) t
)))
1133 (delete-directory zipdir
)))
1134 (message "Created %s" target
)
1135 (set-buffer (find-file-noselect target t
)))
1137 (defun org-e-odt-create-manifest-file-entry (&rest args
)
1138 (push args org-e-odt-manifest-file-entries
))
1140 (defun org-e-odt-write-manifest-file ()
1141 (make-directory "META-INF")
1142 (let ((manifest-file (expand-file-name "META-INF/manifest.xml")))
1143 (with-current-buffer
1144 (let ((nxml-auto-insert-xml-declaration-flag nil
))
1145 (find-file-noselect manifest-file t
))
1147 "<?xml version=\"1.0\" encoding=\"UTF-8\"?>
1148 <manifest:manifest xmlns:manifest=\"urn:oasis:names:tc:opendocument:xmlns:manifest:1.0\" manifest:version=\"1.2\">\n")
1150 (lambda (file-entry)
1151 (let* ((version (nth 2 file-entry
))
1153 (format " manifest:version=\"%s\"" version
)
1156 (format org-e-odt-manifest-file-entry-tag
1157 (nth 0 file-entry
) (nth 1 file-entry
) extra
))))
1158 org-e-odt-manifest-file-entries
)
1159 (insert "\n</manifest:manifest>"))))
1161 (defun org-e-odt-update-meta-file (info) ; FIXME opt-plist
1162 (let ((title (org-export-data (plist-get info
:title
) info
))
1163 (author (or (let ((auth (plist-get info
:author
)))
1164 (and auth
(org-export-data auth info
))) ""))
1165 (date (org-e-odt-format-date (plist-get info
:date
)))
1166 (email (plist-get info
:email
))
1167 (keywords (plist-get info
:keywords
))
1168 (description (plist-get info
:description
)))
1171 "<?xml version=\"1.0\" encoding=\"UTF-8\"?>
1172 <office:document-meta
1173 xmlns:office=\"urn:oasis:names:tc:opendocument:xmlns:office:1.0\"
1174 xmlns:xlink=\"http://www.w3.org/1999/xlink\"
1175 xmlns:dc=\"http://purl.org/dc/elements/1.1/\"
1176 xmlns:meta=\"urn:oasis:names:tc:opendocument:xmlns:meta:1.0\"
1177 xmlns:ooo=\"http://openoffice.org/2004/office\"
1178 office:version=\"1.2\">
1180 (org-e-odt-format-author author
) "\n"
1181 (format "<meta:initial-creator>%s</meta:initial-creator>\n" author
)
1182 (format "<dc:date>%s</dc:date>\n" date
)
1183 (format "<meta:creation-date>%s</meta:creation-date>\n" date
)
1184 (format "<meta:generator>%s</meta:generator>\n"
1185 (concat (and org-export-creator-info org-export-creator-string
)))
1186 (format "<meta:keyword>%s</meta:keyword>\n" keywords
)
1187 (format "<dc:subject>%s</dc:subject>\n" description
)
1188 (format "<dc:title>%s</dc:title>\n" title
)
1190 " </office:meta>\n" "</office:document-meta>")
1191 nil
(expand-file-name "meta.xml")))
1193 ;; create a manifest entry for meta.xml
1194 (org-e-odt-create-manifest-file-entry "text/xml" "meta.xml"))
1196 (defun org-e-odt-update-styles-file (info)
1197 ;; write styles file
1198 (let ((styles-file (plist-get info
:odt-styles-file
)))
1199 (org-e-odt-copy-styles-file (and styles-file
1200 (read (org-trim styles-file
))))
1202 ;; FIXME: Who is opening an empty styles.xml before this point?
1203 (with-current-buffer
1204 (find-file-noselect (expand-file-name "styles.xml") t
)
1205 (revert-buffer t t
)))
1207 ;; Write custom styles for source blocks
1208 (org-e-odt-insert-custom-styles-for-srcblocks
1211 (format " %s\n" (cddr style
)))
1212 hfy-user-sheet-assoc
"")))
1214 (defun org-e-odt-write-mimetype-file (format)
1215 ;; create mimetype file
1218 (odt "application/vnd.oasis.opendocument.text")
1219 (odf "application/vnd.oasis.opendocument.formula")
1220 (t (error "Unknown OpenDocument backend %S" org-lparse-backend
)))))
1221 (write-region mimetype nil
(expand-file-name "mimetype"))
1224 (declare-function org-create-math-formula
"org"
1225 (latex-frag &optional mathml-file
))
1227 (defun org-e-odt-do-preprocess-latex-fragments ()
1228 "Convert LaTeX fragments to images."
1229 (let* ((latex-frag-opt (plist-get org-lparse-opt-plist
:LaTeX-fragments
))
1230 (latex-frag-opt ; massage the options
1231 (or (and (member latex-frag-opt
'(mathjax t
))
1232 (not (and (fboundp 'org-format-latex-mathml-available-p
)
1233 (org-format-latex-mathml-available-p)))
1234 (prog1 org-lparse-latex-fragment-fallback
1237 "LaTeX to MathML converter not available. "
1238 (format "Using %S instead."
1239 org-lparse-latex-fragment-fallback
)))))
1241 cache-dir display-msg
)
1243 ((eq latex-frag-opt
'dvipng
)
1244 (setq cache-dir
"ltxpng/")
1245 (setq display-msg
"Creating LaTeX image %s"))
1246 ((member latex-frag-opt
'(mathjax t
))
1247 (setq latex-frag-opt
'mathml
)
1248 (setq cache-dir
"ltxmathml/")
1249 (setq display-msg
"Creating MathML formula %s")))
1250 (when (and org-current-export-file
)
1252 (concat cache-dir
(file-name-sans-extension
1253 (file-name-nondirectory org-current-export-file
)))
1254 org-current-export-dir nil display-msg
1255 nil nil latex-frag-opt
))))
1257 (eval-after-load 'org-odt
1258 '(ad-deactivate 'org-format-latex-as-mathml
))
1262 ;; (defadvice org-format-latex-as-mathml ; FIXME
1263 ;; (after org-e-odt-protect-latex-fragment activate)
1264 ;; "Encode LaTeX fragment as XML.
1265 ;; Do this when translation to MathML fails."
1266 ;; (when (or (not (> (length ad-return-value) 0))
1267 ;; (get-text-property 0 'org-protected ad-return-value))
1268 ;; (setq ad-return-value
1269 ;; (org-propertize (org-e-odt-encode-plain-text (ad-get-arg 0))
1270 ;; 'org-protected t))))
1272 (defun org-e-odt-zip-extract-one (archive member
&optional target
)
1274 (let* ((target (or target default-directory
))
1275 (archive (expand-file-name archive
))
1276 (archive-zip-extract
1277 (list "unzip" "-qq" "-o" "-d" target
))
1278 exit-code command-output
)
1279 (setq command-output
1281 (setq exit-code
(archive-zip-extract archive member
))
1283 (unless (zerop exit-code
)
1284 (message command-output
)
1285 (error "Extraction failed"))))
1287 (defun org-e-odt-zip-extract (archive members
&optional target
)
1288 (when (atom members
) (setq members
(list members
)))
1289 (mapc (lambda (member)
1290 (org-e-odt-zip-extract-one archive member target
))
1293 (defun org-e-odt-copy-styles-file (&optional styles-file
)
1294 ;; Non-availability of styles.xml is not a critical error. For now
1295 ;; throw an error purely for aesthetic reasons.
1296 (setq styles-file
(or styles-file
1297 org-e-odt-styles-file
1298 (expand-file-name "OrgOdtStyles.xml"
1299 org-e-odt-styles-dir
)
1300 (error "org-e-odt: Missing styles file?")))
1302 ((listp styles-file
)
1303 (let ((archive (nth 0 styles-file
))
1304 (members (nth 1 styles-file
)))
1305 (org-e-odt-zip-extract archive members
)
1308 (when (org-file-image-p member
)
1309 (let* ((image-type (file-name-extension member
))
1310 (media-type (format "image/%s" image-type
)))
1311 (org-e-odt-create-manifest-file-entry media-type member
))))
1313 ((and (stringp styles-file
) (file-exists-p styles-file
))
1314 (let ((styles-file-type (file-name-extension styles-file
)))
1316 ((string= styles-file-type
"xml")
1317 (copy-file styles-file
(expand-file-name "styles.xml") t
))
1318 ((member styles-file-type
'("odt" "ott"))
1319 (org-e-odt-zip-extract styles-file
"styles.xml")))))
1321 (error (format "Invalid specification of styles.xml file: %S"
1322 org-e-odt-styles-file
))))
1324 ;; create a manifest entry for styles.xml
1325 (org-e-odt-create-manifest-file-entry "text/xml" "styles.xml"))
1327 (defun org-e-odt-configure-outline-numbering ()
1328 "Outline numbering is retained only upto LEVEL.
1329 To disable outline numbering pass a LEVEL of 0."
1330 (goto-char (point-min))
1332 "<text:outline-level-style\\([^>]*\\)text:level=\"\\([^\"]*\\)\"\\([^>]*\\)>")
1334 "<text:outline-level-style\\1text:level=\"\\2\" style:num-format=\"\">"))
1335 (while (re-search-forward regex nil t
)
1336 (unless (let ((sec-num (plist-get info
:section-numbers
))
1337 (level (string-to-number (match-string 2))))
1338 (if (wholenump sec-num
) (<= level sec-num
) sec-num
))
1339 (replace-match replacement t nil
))))
1343 (defun org-export-as-odf (latex-frag &optional odf-file
)
1344 "Export LATEX-FRAG as OpenDocument formula file ODF-FILE.
1345 Use `org-create-math-formula' to convert LATEX-FRAG first to
1346 MathML. When invoked as an interactive command, use
1347 `org-latex-regexps' to infer LATEX-FRAG from currently active
1348 region. If no LaTeX fragments are found, prompt for it. Push
1349 MathML source to kill ring, if `org-export-copy-to-kill-ring' is
1353 (setq frag
(and (setq frag
(and (region-active-p)
1354 (buffer-substring (region-beginning)
1356 (loop for e in org-latex-regexps
1357 thereis
(when (string-match (nth 1 e
) frag
)
1358 (match-string (nth 2 e
) frag
)))))
1359 (read-string "LaTeX Fragment: " frag nil frag
))
1360 ,(let ((odf-filename (expand-file-name
1362 (file-name-sans-extension
1363 (or (file-name-nondirectory buffer-file-name
)))
1365 (file-name-directory buffer-file-name
))))
1366 (read-file-name "ODF filename: " nil odf-filename nil
1367 (file-name-nondirectory odf-filename
)))))
1368 (let* ((org-lparse-backend 'odf
)
1369 org-lparse-opt-plist
1370 (filename (or odf-file
1373 (file-name-sans-extension
1374 (or (file-name-nondirectory buffer-file-name
)))
1376 (file-name-directory buffer-file-name
))))
1377 (buffer (find-file-noselect (org-e-odt-init-outfile filename
)))
1378 (coding-system-for-write 'utf-8
)
1379 (save-buffer-coding-system 'utf-8
))
1381 (set-buffer-file-coding-system coding-system-for-write
)
1382 (let ((mathml (org-create-math-formula latex-frag
)))
1383 (unless mathml
(error "No Math formula created"))
1385 (or (org-export-push-to-kill-ring
1386 (upcase (symbol-name org-lparse-backend
)))
1387 (message "Exporting... done")))
1388 (org-e-odt-save-as-outfile filename nil
; FIXME
1392 (defun org-export-as-odf-and-open ()
1393 "Export LaTeX fragment as OpenDocument formula and immediately open it.
1394 Use `org-export-as-odf' to read LaTeX fragment and OpenDocument
1397 (org-lparse-and-open
1398 nil nil nil
(call-interactively 'org-export-as-odf
)))
1403 ;;; Driver Starts here
1406 (require 'format-spec
)
1407 (eval-when-compile (require 'cl
) (require 'table
))
1413 ;; FIXME: it already exists in org-e-odt.el
1414 ;;; Function Declarations
1416 (declare-function org-element-property
"org-element" (property element
))
1417 (declare-function org-element-normalize-string
"org-element" (s))
1419 (declare-function org-export-data
"org-export" (data info
))
1420 (declare-function org-export-directory
"org-export" (type plist
))
1421 (declare-function org-export-expand-macro
"org-export" (macro info
))
1422 (declare-function org-export-first-sibling-p
"org-export" (headline info
))
1423 (declare-function org-export-footnote-first-reference-p
"org-export"
1424 (footnote-reference info
))
1425 (declare-function org-export-get-coderef-format
"org-export" (path desc
))
1426 (declare-function org-export-get-footnote-definition
"org-export"
1427 (footnote-reference info
))
1428 (declare-function org-export-get-footnote-number
"org-export" (footnote info
))
1429 (declare-function org-export-get-previous-element
"org-export" (blob info
))
1430 (declare-function org-export-get-relative-level
"org-export" (headline info
))
1431 (declare-function org-export-handle-code
1432 "org-export" (element info
&optional num-fmt ref-fmt delayed
))
1433 (declare-function org-export-included-file
"org-export" (keyword backend info
))
1434 (declare-function org-export-inline-image-p
"org-export"
1435 (link &optional extensions
))
1436 (declare-function org-export-last-sibling-p
"org-export" (headline info
))
1437 (declare-function org-export-low-level-p
"org-export" (headline info
))
1438 (declare-function org-export-output-file-name
1439 "org-export" (extension &optional subtreep pub-dir
))
1440 (declare-function org-export-resolve-coderef
"org-export" (ref info
))
1441 (declare-function org-export-resolve-fuzzy-link
"org-export" (link info
))
1442 (declare-function org-export-resolve-radio-link
"org-export" (link info
))
1443 (declare-function org-export-solidify-link-text
"org-export" (s))
1445 org-export-to-buffer
"org-export"
1446 (backend buffer
&optional subtreep visible-only body-only ext-plist
))
1448 org-export-to-file
"org-export"
1449 (backend file
&optional subtreep visible-only body-only ext-plist
))
1451 (declare-function org-id-find-id-file
"org-id" (id))
1452 (declare-function htmlize-region
"ext:htmlize" (beg end
))
1453 (declare-function org-pop-to-buffer-same-window
1454 "org-compat" (&optional buffer-or-name norecord label
))
1460 (declare-function hfy-face-to-style
"htmlfontify" (fn))
1461 (declare-function hfy-face-or-def-to-name
"htmlfontify" (fn))
1462 (declare-function archive-zip-extract
"arc-mode.el" (archive name
))
1464 ;;; Internal Variables
1466 ;;;; ODT Internal Variables
1468 (defconst org-e-odt-lib-dir
1469 (file-name-directory load-file-name
)
1470 "Location of ODT exporter.
1471 Use this to infer values of `org-e-odt-styles-dir' and
1472 `org-e-odt-schema-dir'.")
1474 (defvar org-e-odt-data-dir
1475 (expand-file-name "../../etc/" org-e-odt-lib-dir
)
1476 "Data directory for ODT exporter.
1477 Use this to infer values of `org-e-odt-styles-dir' and
1478 `org-e-odt-schema-dir'.")
1480 (defconst org-e-odt-special-string-regexps
1481 '(("\\\\-" .
"­\\1") ; shy
1482 ("---\\([^-]\\)" .
"—\\1") ; mdash
1483 ("--\\([^-]\\)" .
"–\\1") ; ndash
1484 ("\\.\\.\\." .
"…")) ; hellip
1485 "Regular expressions for special string conversion.")
1487 (defconst org-e-odt-schema-dir-list
1489 (and org-e-odt-data-dir
1490 (expand-file-name "./schema/" org-e-odt-data-dir
)) ; bail out
1492 (and (boundp 'org-e-odt-data-dir
) org-e-odt-data-dir
; see make install
1493 (expand-file-name "./schema/" org-e-odt-data-dir
))))
1494 "List of directories to search for OpenDocument schema files.
1495 Use this list to set the default value of
1496 `org-e-odt-schema-dir'. The entries in this list are
1497 populated heuristically based on the values of `org-e-odt-lib-dir'
1498 and `org-e-odt-data-dir'.")
1500 (defconst org-e-odt-styles-dir-list
1502 (and org-e-odt-data-dir
1503 (expand-file-name "./styles/" org-e-odt-data-dir
)) ; bail out
1505 (and (boundp 'org-e-odt-data-dir
) org-e-odt-data-dir
; see make install
1506 (expand-file-name "./styles/" org-e-odt-data-dir
)))
1507 (expand-file-name "../../etc/styles/" org-e-odt-lib-dir
) ; git
1508 (expand-file-name "./etc/styles/" org-e-odt-lib-dir
) ; elpa
1509 (expand-file-name "./org/" data-directory
) ; system
1511 "List of directories to search for OpenDocument styles files.
1512 See `org-e-odt-styles-dir'. The entries in this list are populated
1513 heuristically based on the values of `org-e-odt-lib-dir' and
1514 `org-e-odt-data-dir'.")
1516 (defconst org-e-odt-styles-dir
1519 (message "Debug (org-e-odt): Searching for OpenDocument styles files...")
1520 (mapc (lambda (styles-dir)
1522 (message "Debug (org-e-odt): Trying %s..." styles-dir
)
1523 (when (and (file-readable-p
1525 "OrgOdtContentTemplate.xml" styles-dir
))
1528 "OrgOdtStyles.xml" styles-dir
)))
1529 (message "Debug (org-e-odt): Using styles under %s"
1531 (throw 'styles-dir styles-dir
))))
1532 org-e-odt-styles-dir-list
)
1535 (error "Error (org-e-odt): Cannot find factory styles files. Aborting."))
1537 "Directory that holds auxiliary XML files used by the ODT exporter.
1539 This directory contains the following XML files -
1540 \"OrgOdtStyles.xml\" and \"OrgOdtContentTemplate.xml\". These
1541 XML files are used as the default values of
1542 `org-e-odt-styles-file' and
1543 `org-e-odt-content-template-file'.
1545 The default value of this variable varies depending on the
1546 version of org in use and is initialized from
1547 `org-e-odt-styles-dir-list'. Note that the user could be using org
1548 from one of: org's own private git repository, GNU ELPA tar or
1551 (defconst org-e-odt-tmpdir-prefix
"%s-")
1552 (defconst org-e-odt-bookmark-prefix
"OrgXref.")
1554 (defconst org-e-odt-manifest-file-entry-tag
1556 <manifest:file-entry manifest:media-type=\"%s\" manifest:full-path=\"%s\"%s/>")
1560 (defvar org-lparse-dyn-first-heading-pos
) ; let bound during org-do-lparse
1562 (defvar org-e-odt-suppress-xref nil
)
1563 (defvar org-e-odt-file-extensions
1564 '(("odt" .
"OpenDocument Text")
1565 ("ott" .
"OpenDocument Text Template")
1566 ("odm" .
"OpenDocument Master Document")
1567 ("ods" .
"OpenDocument Spreadsheet")
1568 ("ots" .
"OpenDocument Spreadsheet Template")
1569 ("odg" .
"OpenDocument Drawing (Graphics)")
1570 ("otg" .
"OpenDocument Drawing Template")
1571 ("odp" .
"OpenDocument Presentation")
1572 ("otp" .
"OpenDocument Presentation Template")
1573 ("odi" .
"OpenDocument Image")
1574 ("odf" .
"OpenDocument Formula")
1575 ("odc" .
"OpenDocument Chart")))
1577 (defconst org-e-odt-default-org-styles-alist
1578 '((paragraph .
((default .
"Text_20_body")
1579 (fixedwidth .
"OrgFixedWidthBlock")
1580 (verse .
"OrgVerse")
1581 (quote .
"Quotations")
1582 (blockquote .
"Quotations")
1583 (center .
"OrgCenter")
1585 (right .
"OrgRight")
1586 (title .
"OrgTitle")
1587 (subtitle .
"OrgSubtitle")
1588 (footnote .
"Footnote")
1589 (src .
"OrgSrcBlock")
1590 (illustration .
"Illustration")
1592 (listing .
"Listing")
1593 (definition-term .
"Text_20_body_20_bold")
1594 (horizontal-line .
"Horizontal_20_Line")))
1595 (character .
((bold .
"Bold")
1596 (italic .
"Emphasis")
1598 (verbatim .
"OrgCode")
1599 (strike .
"Strikethrough")
1600 (underline .
"Underline")
1601 (subscript .
"OrgSubscript")
1602 (superscript .
"OrgSuperscript")))
1603 (list .
((ordered .
"OrgNumberedList")
1604 (unordered .
"OrgBulletedList")
1605 (descriptive .
"OrgDescriptionList"))))
1606 "Default styles for various entities.")
1608 (defvar org-e-odt-org-styles-alist org-e-odt-default-org-styles-alist
)
1611 ;;;_. control callbacks
1612 ;;;_ , document body
1614 (defvar org-lparse-opt-plist
) ; bound during org-do-lparse
1615 (defvar org-lparse-list-stack
) ; dynamically bound in org-do-lparse
1616 (defvar org-e-odt-list-stack-stashed
)
1617 (defvar org-lparse-table-ncols
)
1619 (defvar org-e-odt-table-style nil
1620 "Table style specified by \"#+ATTR_ODT: <style-name>\" line.
1621 This is set during `org-e-odt-begin-table'.")
1623 (defvar org-e-odt-table-style-spec nil
1624 "Entry for `org-e-odt-table-style' in `org-e-odt-table-styles'.")
1627 (defvar org-e-odt-table-style-format
1629 <style:style style:name=\"%s\" style:family=\"table\">
1630 <style:table-properties style:rel-width=\"%d%%\" fo:margin-top=\"0cm\" fo:margin-bottom=\"0.20cm\" table:align=\"center\"/>
1633 "Template for auto-generated Table styles.")
1635 (defvar org-e-odt-automatic-styles
'()
1636 "Registry of automatic styles for various OBJECT-TYPEs.
1637 The variable has the following form:
1639 \(\(OBJECT-NAME-A.1 OBJECT-PROPS-A.1\)
1640 \(OBJECT-NAME-A.2 OBJECT-PROPS-A.2\) ...\)\)
1642 \(\(OBJECT-NAME-B.1 OBJECT-PROPS-B.1\)
1643 \(OBJECT-NAME-B.2 OBJECT-PROPS-B.2\) ...\)\)
1646 OBJECT-TYPEs could be \"Section\", \"Table\", \"Figure\" etc.
1647 OBJECT-PROPS is (typically) a plist created by passing
1648 \"#+ATTR_ODT: \" option to `org-e-odt-parse-block-attributes'.
1650 Use `org-e-odt-add-automatic-style' to add update this variable.'")
1652 (defvar org-e-odt-object-counters nil
1653 "Running counters for various OBJECT-TYPEs.
1654 Use this to generate automatic names and style-names. See
1655 `org-e-odt-add-automatic-style'.")
1657 (defvar org-e-odt-table-indentedp nil
)
1658 (defvar org-lparse-link-description-is-image nil
)
1661 (defvar org-src-block-paragraph-format
1662 "<style:style style:name=\"OrgSrcBlock\" style:family=\"paragraph\" style:parent-style-name=\"Preformatted_20_Text\">
1663 <style:paragraph-properties fo:background-color=\"%s\" fo:padding=\"0.049cm\" fo:border=\"0.51pt solid #000000\" style:shadow=\"none\">
1664 <style:background-image/>
1665 </style:paragraph-properties>
1666 <style:text-properties fo:color=\"%s\"/>
1668 "Custom paragraph style for colorized source and example blocks.
1669 This style is much the same as that of \"OrgFixedWidthBlock\"
1670 except that the foreground and background colors are set
1671 according to the default face identified by the `htmlfontify'.")
1673 (defvar hfy-optimisations
)
1674 (defvar org-e-odt-embedded-formulas-count
0)
1675 (defvar org-e-odt-entity-frame-styles
1676 '(("As-CharImage" "__Figure__" ("OrgInlineImage" nil
"as-char"))
1677 ("ParagraphImage" "__Figure__" ("OrgDisplayImage" nil
"paragraph"))
1678 ("PageImage" "__Figure__" ("OrgPageImage" nil
"page"))
1679 ("CaptionedAs-CharImage" "__Figure__"
1680 ("OrgCaptionedImage"
1681 " style:rel-width=\"100%\" style:rel-height=\"scale\"" "paragraph")
1682 ("OrgInlineImage" nil
"as-char"))
1683 ("CaptionedParagraphImage" "__Figure__"
1684 ("OrgCaptionedImage"
1685 " style:rel-width=\"100%\" style:rel-height=\"scale\"" "paragraph")
1686 ("OrgImageCaptionFrame" nil
"paragraph"))
1687 ("CaptionedPageImage" "__Figure__"
1688 ("OrgCaptionedImage"
1689 " style:rel-width=\"100%\" style:rel-height=\"scale\"" "paragraph")
1690 ("OrgPageImageCaptionFrame" nil
"page"))
1691 ("InlineFormula" "__MathFormula__" ("OrgInlineFormula" nil
"as-char"))
1692 ("DisplayFormula" "__MathFormula__" ("OrgDisplayFormula" nil
"as-char"))
1693 ("CaptionedDisplayFormula" "__MathFormula__"
1694 ("OrgCaptionedFormula" nil
"paragraph")
1695 ("OrgFormulaCaptionFrame" nil
"as-char"))))
1697 (defvar org-e-odt-embedded-images-count
0)
1699 (defvar org-e-odt-image-size-probe-method
1700 (append (and (executable-find "identify") '(imagemagick)) ; See Bug#10675
1702 "Ordered list of methods for determining image sizes.")
1704 (defvar org-e-odt-default-image-sizes-alist
1705 '(("as-char" .
(5 .
0.4))
1706 ("paragraph" .
(5 .
5)))
1707 "Hardcoded image dimensions one for each of the anchor
1710 ;; A4 page size is 21.0 by 29.7 cms
1711 ;; The default page settings has 2cm margin on each of the sides. So
1712 ;; the effective text area is 17.0 by 25.7 cm
1713 (defvar org-e-odt-max-image-size
'(17.0 .
20.0)
1714 "Limiting dimensions for an embedded image.")
1716 (defvar org-e-odt-label-styles
1717 '(("math-formula" "%c" "text" "(%n)")
1718 ("math-label" "(%n)" "text" "(%n)")
1719 ("category-and-value" "%e %n: %c" "category-and-value" "%e %n")
1720 ("value" "%e %n: %c" "value" "%n"))
1721 "Specify how labels are applied and referenced.
1722 This is an alist where each element is of the
1723 form (LABEL-STYLE-NAME LABEL-ATTACH-FMT LABEL-REF-MODE
1726 LABEL-ATTACH-FMT controls how labels and captions are attached to
1727 an entity. It may contain following specifiers - %e, %n and %c.
1728 %e is replaced with the CATEGORY-NAME. %n is replaced with
1729 \"<text:sequence ...> SEQNO </text:sequence>\". %c is replaced
1730 with CAPTION. See `org-e-odt-format-label-definition'.
1732 LABEL-REF-MODE and LABEL-REF-FMT controls how label references
1733 are generated. The following XML is generated for a label
1734 reference - \"<text:sequence-ref
1735 text:reference-format=\"LABEL-REF-MODE\" ...> LABEL-REF-FMT
1736 </text:sequence-ref>\". LABEL-REF-FMT may contain following
1737 specifiers - %e and %n. %e is replaced with the CATEGORY-NAME.
1738 %n is replaced with SEQNO. See
1739 `org-e-odt-format-label-reference'.")
1741 (defcustom org-e-odt-category-strings
1742 '(("en" "Table" "Figure" "Equation" "Equation" "Listing"))
1743 "Specify category strings for various captionable entities.
1744 Captionable entity can be one of a Table, an Embedded Image, a
1745 LaTeX fragment (generated with dvipng) or a Math Formula.
1747 For example, when `org-export-default-language' is \"en\", an
1748 embedded image will be captioned as \"Figure 1: Orgmode Logo\".
1749 If you want the images to be captioned instead as \"Illustration
1750 1: Orgmode Logo\", then modify the entry for \"en\" as shown
1753 \(setq org-e-odt-category-strings
1754 '\(\(\"en\" \"Table\" \"Illustration\"
1755 \"Equation\" \"Equation\"\)\)\)"
1756 :group
'org-export-e-odt
1758 :type
'(repeat (list (string :tag
"Language tag")
1759 (choice :tag
"Table"
1760 (const :tag
"Use Default" nil
)
1761 (string :tag
"Category string"))
1762 (choice :tag
"Figure"
1763 (const :tag
"Use Default" nil
)
1764 (string :tag
"Category string"))
1765 (choice :tag
"Math Formula"
1766 (const :tag
"Use Default" nil
)
1767 (string :tag
"Category string"))
1768 (choice :tag
"Dvipng Image"
1769 (const :tag
"Use Default" nil
)
1770 (string :tag
"Category string"))
1771 (choice :tag
"Listing"
1772 (const :tag
"Use Default" nil
)
1773 (string :tag
"Category string")))))
1775 (defvar org-e-odt-category-map-alist
1776 '(("__Table__" "Table" "value")
1777 ("__Figure__" "Illustration" "value")
1778 ("__MathFormula__" "Text" "math-formula")
1779 ("__DvipngImage__" "Equation" "value")
1780 ("__Listing__" "Listing" "value")
1781 ;; ("__Table__" "Table" "category-and-value")
1782 ;; ("__Figure__" "Figure" "category-and-value")
1783 ;; ("__DvipngImage__" "Equation" "category-and-value")
1785 "Map a CATEGORY-HANDLE to OD-VARIABLE and LABEL-STYLE.
1786 This is a list where each entry is of the form \\(CATEGORY-HANDLE
1787 OD-VARIABLE LABEL-STYLE\\). CATEGORY_HANDLE identifies the
1788 captionable entity in question. OD-VARIABLE is the OpenDocument
1789 sequence counter associated with the entity. These counters are
1791 \"<text:sequence-decls>...</text:sequence-decls>\" block of
1792 `org-e-odt-content-template-file'. LABEL-STYLE is a key
1793 into `org-e-odt-label-styles' and specifies how a given entity
1794 should be captioned and referenced.
1796 The position of a CATEGORY-HANDLE in this list is used as an
1797 index in to per-language entry for
1798 `org-e-odt-category-strings' to retrieve a CATEGORY-NAME.
1799 This CATEGORY-NAME is then used for qualifying the user-specified
1800 captions on export.")
1802 (defvar org-e-odt-manifest-file-entries nil
)
1803 (defvar hfy-user-sheet-assoc
) ; bound during org-do-lparse
1804 (defvar org-lparse-latex-fragment-fallback
) ; set by org-do-lparse
1807 ;;;; HTML Internal Variables
1809 (defvar html-table-tag nil
) ; dynamically scoped into this.
1811 ;; FIXME: it already exists in org-e-odt.el
1812 (defconst org-e-odt-cvt-link-fn
1814 "Function to convert link URLs to exportable URLs.
1815 Takes two arguments, TYPE and PATH.
1816 Returns exportable url as (TYPE PATH), or nil to signal that it
1817 didn't handle this case.
1818 Intended to be locally bound around a call to `org-export-as-html'." )
1821 (defvar org-e-odt-headline-formatter
1822 (lambda (level snumber todo todo-type priority
1823 title tags target extra-targets extra-class
)
1824 (concat snumber
" " title
)))
1828 ;;; User Configuration Variables
1830 (defgroup org-export-e-odt nil
1831 "Options for exporting Org mode files to ODT."
1832 :tag
"Org Export ODT"
1835 (defcustom org-e-odt-protect-char-alist
1839 "Alist of characters to be converted by `org-e-html-protect'."
1840 :group
'org-export-e-html
1841 :type
'(repeat (cons (string :tag
"Character")
1842 (string :tag
"ODT equivalent"))))
1843 (defcustom org-e-odt-schema-dir
1846 (message "Debug (org-e-odt): Searching for OpenDocument schema files...")
1848 (lambda (schema-dir)
1850 (message "Debug (org-e-odt): Trying %s..." schema-dir
)
1851 (when (and (file-readable-p
1852 (expand-file-name "od-manifest-schema-v1.2-cs01.rnc"
1855 (expand-file-name "od-schema-v1.2-cs01.rnc"
1858 (expand-file-name "schemas.xml" schema-dir
)))
1859 (message "Debug (org-e-odt): Using schema files under %s"
1861 (throw 'schema-dir schema-dir
))))
1862 org-e-odt-schema-dir-list
)
1863 (message "Debug (org-e-odt): No OpenDocument schema files installed")
1866 "Directory that contains OpenDocument schema files.
1868 This directory contains:
1869 1. rnc files for OpenDocument schema
1870 2. a \"schemas.xml\" file that specifies locating rules needed
1871 for auto validation of OpenDocument XML files.
1873 Use the customize interface to set this variable. This ensures
1874 that `rng-schema-locating-files' is updated and auto-validation
1875 of OpenDocument XML takes place based on the value
1876 `rng-nxml-auto-validate-flag'.
1878 The default value of this variable varies depending on the
1879 version of org in use and is initialized from
1880 `org-e-odt-schema-dir-list'. The OASIS schema files are available
1881 only in the org's private git repository. It is *not* bundled
1882 with GNU ELPA tar or standard Emacs distribution."
1884 (const :tag
"Not set" nil
)
1885 (directory :tag
"Schema directory"))
1886 :group
'org-export-e-odt
1890 "Set `org-e-odt-schema-dir'.
1891 Also add it to `rng-schema-locating-files'."
1892 (let ((schema-dir value
))
1896 (expand-file-name "od-manifest-schema-v1.2-cs01.rnc" schema-dir
))
1898 (expand-file-name "od-schema-v1.2-cs01.rnc" schema-dir
))
1900 (expand-file-name "schemas.xml" schema-dir
)))
1903 (message "Error (org-e-odt): %s has no OpenDocument schema files"
1906 (when org-e-odt-schema-dir
1907 (eval-after-load 'rng-loc
1908 '(add-to-list 'rng-schema-locating-files
1909 (expand-file-name "schemas.xml"
1910 org-e-odt-schema-dir
))))))
1912 (defcustom org-e-odt-content-template-file nil
1913 "Template file for \"content.xml\".
1914 The exporter embeds the exported content just before
1915 \"</office:text>\" element.
1917 If unspecified, the file named \"OrgOdtContentTemplate.xml\"
1918 under `org-e-odt-styles-dir' is used."
1920 :group
'org-export-e-odt
1923 (defcustom org-e-odt-styles-file nil
1924 "Default styles file for use with ODT export.
1925 Valid values are one of:
1927 2. path to a styles.xml file
1928 3. path to a *.odt or a *.ott file
1929 4. list of the form (ODT-OR-OTT-FILE (FILE-MEMBER-1 FILE-MEMBER-2
1932 In case of option 1, an in-built styles.xml is used. See
1933 `org-e-odt-styles-dir' for more information.
1935 In case of option 3, the specified file is unzipped and the
1936 styles.xml embedded therein is used.
1938 In case of option 4, the specified ODT-OR-OTT-FILE is unzipped
1939 and FILE-MEMBER-1, FILE-MEMBER-2 etc are copied in to the
1940 generated odt file. Use relative path for specifying the
1941 FILE-MEMBERS. styles.xml must be specified as one of the
1944 Use options 1, 2 or 3 only if styles.xml alone suffices for
1945 achieving the desired formatting. Use option 4, if the styles.xml
1946 references additional files like header and footer images for
1947 achieving the desired formatting.
1949 Use \"#+ODT_STYLES_FILE: ...\" directive to set this variable on
1950 a per-file basis. For example,
1952 #+ODT_STYLES_FILE: \"/path/to/styles.xml\" or
1953 #+ODT_STYLES_FILE: (\"/path/to/file.ott\" (\"styles.xml\" \"image/hdr.png\"))."
1954 :group
'org-export-e-odt
1958 (const :tag
"Factory settings" nil
)
1959 (file :must-match t
:tag
"styles.xml")
1960 (file :must-match t
:tag
"ODT or OTT file")
1961 (list :tag
"ODT or OTT file + Members"
1962 (file :must-match t
:tag
"ODF Text or Text Template file")
1963 (cons :tag
"Members"
1964 (file :tag
" Member" "styles.xml")
1965 (repeat (file :tag
"Member"))))))
1968 (defcustom org-e-odt-inline-image-extensions
1969 '("png" "jpeg" "jpg" "gif")
1970 "Extensions of image files that can be inlined into HTML."
1971 :type
'(repeat (string :tag
"Extension"))
1972 :group
'org-export-e-odt
1975 (defcustom org-e-odt-pixels-per-inch display-pixels-per-inch
1976 "Scaling factor for converting images pixels to inches.
1977 Use this for sizing of embedded images. See Info node `(org)
1978 Images in ODT export' for more information."
1980 :group
'org-export-e-odt
1983 (defcustom org-e-odt-create-custom-styles-for-srcblocks t
1984 "Whether custom styles for colorized source blocks be automatically created.
1985 When this option is turned on, the exporter creates custom styles
1986 for source blocks based on the advice of `htmlfontify'. Creation
1987 of custom styles happen as part of `org-e-odt-hfy-face-to-css'.
1989 When this option is turned off exporter does not create such
1992 Use the latter option if you do not want the custom styles to be
1993 based on your current display settings. It is necessary that the
1994 styles.xml already contains needed styles for colorizing to work.
1996 This variable is effective only if
1997 `org-e-odt-fontify-srcblocks' is turned on."
1998 :group
'org-export-e-odt
2002 (defcustom org-e-odt-preferred-output-format nil
2003 "Automatically post-process to this format after exporting to \"odt\".
2004 Interactive commands `org-export-as-e-odt' and
2005 `org-export-as-e-odt-and-open' export first to \"odt\" format and
2006 then use `org-e-odt-convert-process' to convert the
2007 resulting document to this format. During customization of this
2008 variable, the list of valid values are populated based on
2009 `org-e-odt-convert-capabilities'."
2010 :group
'org-export-e-odt
2012 :type
'(choice :convert-widget
2014 (apply 'widget-convert
(widget-type w
)
2015 (eval (car (widget-get w
:args
)))))
2016 `((const :tag
"None" nil
)
2017 ,@(mapcar (lambda (c)
2018 `(const :tag
,c
,c
))
2019 (org-e-odt-reachable-formats "odt")))))
2021 (defcustom org-e-odt-table-styles
2022 '(("OrgEquation" "OrgEquation"
2023 ((use-first-column-styles . t
)
2024 (use-last-column-styles . t
))))
2025 "Specify how Table Styles should be derived from a Table Template.
2026 This is a list where each element is of the
2027 form (TABLE-STYLE-NAME TABLE-TEMPLATE-NAME TABLE-CELL-OPTIONS).
2029 TABLE-STYLE-NAME is the style associated with the table through
2030 `org-e-odt-table-style'.
2032 TABLE-TEMPLATE-NAME is a set of - upto 9 - automatic
2033 TABLE-CELL-STYLE-NAMEs and PARAGRAPH-STYLE-NAMEs (as defined
2034 below) that is included in
2035 `org-e-odt-content-template-file'.
2037 TABLE-CELL-STYLE-NAME := TABLE-TEMPLATE-NAME + TABLE-CELL-TYPE +
2039 PARAGRAPH-STYLE-NAME := TABLE-TEMPLATE-NAME + TABLE-CELL-TYPE +
2041 TABLE-CELL-TYPE := \"FirstRow\" | \"LastColumn\" |
2042 \"FirstRow\" | \"LastRow\" |
2043 \"EvenRow\" | \"OddRow\" |
2044 \"EvenColumn\" | \"OddColumn\" | \"\"
2045 where \"+\" above denotes string concatenation.
2047 TABLE-CELL-OPTIONS is an alist where each element is of the
2048 form (TABLE-CELL-STYLE-SELECTOR . ON-OR-OFF).
2049 TABLE-CELL-STYLE-SELECTOR := `use-first-row-styles' |
2050 `use-last-row-styles' |
2051 `use-first-column-styles' |
2052 `use-last-column-styles' |
2053 `use-banding-rows-styles' |
2054 `use-banding-columns-styles' |
2055 `use-first-row-styles'
2056 ON-OR-OFF := `t' | `nil'
2058 For example, with the following configuration
2060 \(setq org-e-odt-table-styles
2061 '\(\(\"TableWithHeaderRowsAndColumns\" \"Custom\"
2062 \(\(use-first-row-styles . t\)
2063 \(use-first-column-styles . t\)\)\)
2064 \(\"TableWithHeaderColumns\" \"Custom\"
2065 \(\(use-first-column-styles . t\)\)\)\)\)
2067 1. A table associated with \"TableWithHeaderRowsAndColumns\"
2068 style will use the following table-cell styles -
2069 \"CustomFirstRowTableCell\", \"CustomFirstColumnTableCell\",
2070 \"CustomTableCell\" and the following paragraph styles
2071 \"CustomFirstRowTableParagraph\",
2072 \"CustomFirstColumnTableParagraph\", \"CustomTableParagraph\"
2075 2. A table associated with \"TableWithHeaderColumns\" style will
2076 use the following table-cell styles -
2077 \"CustomFirstColumnTableCell\", \"CustomTableCell\" and the
2078 following paragraph styles
2079 \"CustomFirstColumnTableParagraph\", \"CustomTableParagraph\"
2082 Note that TABLE-TEMPLATE-NAME corresponds to the
2083 \"<table:table-template>\" elements contained within
2084 \"<office:styles>\". The entries (TABLE-STYLE-NAME
2085 TABLE-TEMPLATE-NAME TABLE-CELL-OPTIONS) correspond to
2086 \"table:template-name\" and \"table:use-first-row-styles\" etc
2087 attributes of \"<table:table>\" element. Refer ODF-1.2
2088 specification for more information. Also consult the
2089 implementation filed under `org-e-odt-get-table-cell-styles'.
2091 The TABLE-STYLE-NAME \"OrgEquation\" is used internally for
2092 formatting of numbered display equations. Do not delete this
2093 style from the list."
2094 :group
'org-export-e-odt
2097 (const :tag
"None" nil
)
2098 (repeat :tag
"Table Styles"
2099 (list :tag
"Table Style Specification"
2100 (string :tag
"Table Style Name")
2101 (string :tag
"Table Template Name")
2102 (alist :options
(use-first-row-styles
2104 use-first-column-styles
2105 use-last-column-styles
2106 use-banding-rows-styles
2107 use-banding-columns-styles
)
2109 :value-type
(const :tag
"True" t
))))))
2110 (defcustom org-e-odt-fontify-srcblocks t
2111 "Specify whether or not source blocks need to be fontified.
2112 Turn this option on if you want to colorize the source code
2113 blocks in the exported file. For colorization to work, you need
2114 to make available an enhanced version of `htmlfontify' library."
2116 :group
'org-export-e-odt
2119 (defcustom org-e-odt-prettify-xml t
; FIXME
2120 "Specify whether or not the xml output should be prettified.
2121 When this option is turned on, `indent-region' is run on all
2122 component xml buffers before they are saved. Turn this off for
2123 regular use. Turn this on if you need to examine the xml
2125 :group
'org-export-e-odt
2129 (defcustom org-e-odt-convert-processes
2131 "soffice --headless --convert-to %f%x --outdir %d %i")
2133 "unoconv -f %f -o %d %i"))
2134 "Specify a list of document converters and their usage.
2135 The converters in this list are offered as choices while
2136 customizing `org-e-odt-convert-process'.
2138 This variable is a list where each element is of the
2139 form (CONVERTER-NAME CONVERTER-CMD). CONVERTER-NAME is the name
2140 of the converter. CONVERTER-CMD is the shell command for the
2141 converter and can contain format specifiers. These format
2142 specifiers are interpreted as below:
2144 %i input file name in full
2145 %I input file name as a URL
2146 %f format of the output file
2147 %o output file name in full
2148 %O output file name as a URL
2149 %d output dir in full
2150 %D output dir as a URL.
2151 %x extra options as set in `org-e-odt-convert-capabilities'."
2152 :group
'org-export-e-odt
2156 (const :tag
"None" nil
)
2157 (alist :tag
"Converters"
2158 :key-type
(string :tag
"Converter Name")
2159 :value-type
(group (string :tag
"Command line")))))
2161 (defcustom org-e-odt-convert-process
"LibreOffice"
2162 "Use this converter to convert from \"odt\" format to other formats.
2163 During customization, the list of converter names are populated
2164 from `org-e-odt-convert-processes'."
2165 :group
'org-export-e-odt
2167 :type
'(choice :convert-widget
2169 (apply 'widget-convert
(widget-type w
)
2170 (eval (car (widget-get w
:args
)))))
2171 `((const :tag
"None" nil
)
2172 ,@(mapcar (lambda (c)
2173 `(const :tag
,(car c
) ,(car c
)))
2174 org-e-odt-convert-processes
))))
2176 (defcustom org-e-odt-convert-capabilities
2178 ("odt" "ott" "doc" "rtf" "docx")
2179 (("pdf" "pdf") ("odt" "odt") ("rtf" "rtf") ("ott" "ott")
2180 ("doc" "doc" ":\"MS Word 97\"") ("docx" "docx") ("html" "html")))
2183 (("pdf" "pdf") ("odt" "odt") ("html" "html")))
2185 ("ods" "ots" "xls" "csv" "xlsx")
2186 (("pdf" "pdf") ("ots" "ots") ("html" "html") ("csv" "csv") ("ods" "ods")
2187 ("xls" "xls") ("xlsx" "xlsx")))
2189 ("odp" "otp" "ppt" "pptx")
2190 (("pdf" "pdf") ("swf" "swf") ("odp" "odp") ("otp" "otp") ("ppt" "ppt")
2191 ("pptx" "pptx") ("odg" "odg"))))
2192 "Specify input and output formats of `org-e-odt-convert-process'.
2193 More correctly, specify the set of input and output formats that
2194 the user is actually interested in.
2196 This variable is an alist where each element is of the
2197 form (DOCUMENT-CLASS INPUT-FMT-LIST OUTPUT-FMT-ALIST).
2198 INPUT-FMT-LIST is a list of INPUT-FMTs. OUTPUT-FMT-ALIST is an
2199 alist where each element is of the form (OUTPUT-FMT
2200 OUTPUT-FILE-EXTENSION EXTRA-OPTIONS).
2202 The variable is interpreted as follows:
2203 `org-e-odt-convert-process' can take any document that is in
2204 INPUT-FMT-LIST and produce any document that is in the
2205 OUTPUT-FMT-LIST. A document converted to OUTPUT-FMT will have
2206 OUTPUT-FILE-EXTENSION as the file name extension. OUTPUT-FMT
2207 serves dual purposes:
2208 - It is used for populating completion candidates during
2209 `org-e-odt-convert' commands.
2210 - It is used as the value of \"%f\" specifier in
2211 `org-e-odt-convert-process'.
2213 EXTRA-OPTIONS is used as the value of \"%x\" specifier in
2214 `org-e-odt-convert-process'.
2216 DOCUMENT-CLASS is used to group a set of file formats in
2217 INPUT-FMT-LIST in to a single class.
2219 Note that this variable inherently captures how LibreOffice based
2220 converters work. LibreOffice maps documents of various formats
2221 to classes like Text, Web, Spreadsheet, Presentation etc and
2222 allow document of a given class (irrespective of it's source
2223 format) to be converted to any of the export formats associated
2226 See default setting of this variable for an typical
2228 :group
'org-export-e-odt
2232 (const :tag
"None" nil
)
2233 (alist :tag
"Capabilities"
2234 :key-type
(string :tag
"Document Class")
2236 (group (repeat :tag
"Input formats" (string :tag
"Input format"))
2237 (alist :tag
"Output formats"
2238 :key-type
(string :tag
"Output format")
2240 (group (string :tag
"Output file extension")
2242 (const :tag
"None" nil
)
2243 (string :tag
"Extra options"))))))))
2250 ;;;; Document Header (Styles)
2252 ;;;; Document Header (Scripts)
2254 ;;;; Document Header (Mathjax)
2267 ;;;; Statistics Cookie
2287 ;;;; Horizontal Rule
2288 ;;;; Inline Babel Call
2289 ;;;; Inline Src Block
2293 ;;;; Latex Environment
2302 ;;;; Property Drawer
2328 ;;; User Configurable Variables (MAYBE)
2336 (defcustom org-e-odt-format-headline-function nil
2337 "Function to format headline text.
2339 This function will be called with 5 arguments:
2340 TODO the todo keyword \(string or nil\).
2341 TODO-TYPE the type of todo \(symbol: `todo', `done', nil\)
2342 PRIORITY the priority of the headline \(integer or nil\)
2343 TEXT the main headline text \(string\).
2344 TAGS the tags string, separated with colons \(string or nil\).
2346 The function result will be used in the section format string.
2348 As an example, one could set the variable to the following, in
2349 order to reproduce the default set-up:
2351 \(defun org-e-odt-format-headline \(todo todo-type priority text tags\)
2352 \"Default format function for an headline.\"
2353 \(concat \(when todo
2354 \(format \"\\\\textbf{\\\\textsc{\\\\textsf{%s}}} \" todo\)\)
2356 \(format \"\\\\framebox{\\\\#%c} \" priority\)\)
2358 \(when tags \(format \"\\\\hfill{}\\\\textsc{%s}\" tags\)\)\)\)"
2359 :group
'org-export-e-odt
2366 (defcustom org-e-odt-active-timestamp-format
"\\textit{%s}"
2367 "A printf format string to be applied to active timestamps."
2368 :group
'org-export-e-odt
2371 (defcustom org-e-odt-inactive-timestamp-format
"\\textit{%s}"
2372 "A printf format string to be applied to inactive timestamps."
2373 :group
'org-export-e-odt
2376 (defcustom org-e-odt-diary-timestamp-format
"\\textit{%s}"
2377 "A printf format string to be applied to diary timestamps."
2378 :group
'org-export-e-odt
2384 (defcustom org-e-odt-inline-image-rules
2385 '(("file" .
"\\.\\(jpeg\\|jpg\\|png\\|gif\\)\\'"))
2386 "Rules characterizing image files that can be inlined into HTML.
2388 A rule consists in an association whose key is the type of link
2389 to consider, and value is a regexp that will be matched against
2392 Note that, by default, the image extension *actually* allowed
2393 depend on the way the HTML file is processed. When used with
2394 pdflatex, pdf, jpg and png images are OK. When processing
2395 through dvi to Postscript, only ps and eps are allowed. The
2396 default we use here encompasses both."
2397 :group
'org-export-e-odt
2398 :type
'(alist :key-type
(string :tag
"Type")
2399 :value-type
(regexp :tag
"Path")))
2403 (defcustom org-e-odt-table-caption-above t
2404 "When non-nil, place caption string at the beginning of the table.
2405 Otherwise, place it near the end."
2406 :group
'org-export-e-odt
2411 (defcustom org-e-odt-format-drawer-function nil
2412 "Function called to format a drawer in HTML code.
2414 The function must accept two parameters:
2415 NAME the drawer name, like \"LOGBOOK\"
2416 CONTENTS the contents of the drawer.
2418 The function should return the string to be exported.
2420 For example, the variable could be set to the following function
2421 in order to mimic default behaviour:
2423 \(defun org-e-odt-format-drawer-default \(name contents\)
2424 \"Format a drawer element for HTML export.\"
2426 :group
'org-export-e-odt
2432 (defcustom org-e-odt-format-inlinetask-function nil
2433 "Function called to format an inlinetask in HTML code.
2435 The function must accept six parameters:
2436 TODO the todo keyword, as a string
2437 TODO-TYPE the todo type, a symbol among `todo', `done' and nil.
2438 PRIORITY the inlinetask priority, as a string
2439 NAME the inlinetask name, as a string.
2440 TAGS the inlinetask tags, as a string.
2441 CONTENTS the contents of the inlinetask, as a string.
2443 The function should return the string to be exported.
2445 For example, the variable could be set to the following function
2446 in order to mimic default behaviour:
2448 \(defun org-e-odt-format-inlinetask \(todo type priority name tags contents\)
2449 \"Format an inline task element for HTML export.\"
2450 \(let \(\(full-title
2453 \(format \"\\\\textbf{\\\\textsf{\\\\textsc{%s}}} \" todo\)\)
2454 \(when priority \(format \"\\\\framebox{\\\\#%c} \" priority\)\)
2456 \(when tags \(format \"\\\\hfill{}\\\\textsc{%s}\" tags\)\)\)\)\)
2457 \(format \(concat \"\\\\begin{center}\\n\"
2459 \"\\\\begin{minipage}[c]{.6\\\\textwidth}\\n\"
2461 \"\\\\rule[.8em]{\\\\textwidth}{2pt}\\n\\n\"
2463 \"\\\\end{minipage}}\"
2464 \"\\\\end{center}\"\)
2465 full-title contents\)\)"
2466 :group
'org-export-e-odt
2474 (defcustom org-e-odt-quotes
2476 ("\\(\\s-\\|[[(]\\|^\\)\"" .
"« ")
2477 ("\\(\\S-\\)\"" .
"» ")
2478 ("\\(\\s-\\|(\\|^\\)'" .
"'"))
2480 ("\\(\\s-\\|[[(]\\|^\\)\"" .
"“")
2481 ("\\(\\S-\\)\"" .
"”")
2482 ("\\(\\s-\\|(\\|^\\)'" .
"‘")
2483 ("\\(\\S-\\)'" .
"’")))
2484 "Alist for quotes to use when converting english double-quotes.
2486 The CAR of each item in this alist is the language code.
2487 The CDR of each item in this alist is a list of three CONS:
2488 - the first CONS defines the opening quote;
2489 - the second CONS defines the closing quote;
2490 - the last CONS defines single quotes.
2492 For each item in a CONS, the first string is a regexp
2493 for allowed characters before/after the quote, the second
2494 string defines the replacement string for this quote."
2495 :group
'org-export-e-odt
2497 (cons :tag
"Opening quote"
2498 (string :tag
"Regexp for char before")
2499 (string :tag
"Replacement quote "))
2500 (cons :tag
"Closing quote"
2501 (string :tag
"Regexp for char after ")
2502 (string :tag
"Replacement quote "))
2503 (cons :tag
"Single quote"
2504 (string :tag
"Regexp for char before")
2505 (string :tag
"Replacement quote "))))
2512 ;;; Internal Functions (HTML)
2514 ;; (defun org-e-odt-format-inline-image (path &optional caption label attr)
2515 ;; ;; FIXME: alt text missing here?
2516 ;; (let ((inline-image (format "<img src=\"%s\" alt=\"%s\"/>"
2517 ;; path (file-name-nondirectory path))))
2518 ;; (if (not label) inline-image
2519 ;; (org-e-odt-format-section inline-image "figure" label))))
2523 (defun org-e-odt-bibliography ()
2524 "Find bibliography, cut it out and return it."
2526 (let (beg end
(cnt 1) bib
)
2528 (goto-char (point-min))
2529 (when (re-search-forward
2530 "^[ \t]*<div \\(id\\|class\\)=\"bibliography\"" nil t
)
2531 (setq beg
(match-beginning 0))
2532 (while (re-search-forward "</?div\\>" nil t
)
2533 (setq cnt
(+ cnt
(if (string= (match-string 0) "<div") +1 -
1)))
2535 (and (looking-at ">") (forward-char 1))
2536 (setq bib
(buffer-substring beg
(point)))
2537 (delete-region beg
(point))
2538 (throw 'exit bib
))))
2543 (defun org-e-odt-toc-entry-formatter
2544 (level snumber todo todo-type priority
2545 headline tags target extra-targets extra-class
)
2546 (org-e-odt-format-toc-entry snumber todo headline tags target
))
2548 (defun org-e-odt-make-string (n string
)
2549 (let (out) (dotimes (i n out
) (setq out
(concat string out
)))))
2551 (defun org-e-odt-toc-text (toc-entries)
2552 (let* ((prev-level (1- (nth 1 (car toc-entries
))))
2553 (start-level prev-level
))
2556 (let ((headline (nth 0 entry
))
2557 (level (nth 1 entry
)))
2558 (prog1 (org-e-odt-format-toc-item headline level prev-level
)
2559 (setq prev-level level
))))
2562 (defun* org-e-odt-format-toc-headline
2563 (todo todo-type priority text tags
2564 &key level section-number headline-label
&allow-other-keys
)
2567 (and org-export-with-section-numbers
2568 (concat section-number
". "))
2572 (org-e-odt-format-spaces 3)
2573 (org-e-odt-format-fontify tags
"tag")))))
2575 (setq text
(org-e-odt-format-fontify text
"todo")))
2577 (let ((org-e-odt-suppress-xref t
))
2578 (org-e-odt-format-link text
(concat "#" headline-label
))))
2580 (defun org-e-odt-toc (depth info
)
2581 (assert (wholenump depth
))
2582 (let* ((headlines (org-export-collect-headlines info depth
))
2584 (loop for headline in headlines collect
2585 (list (org-e-odt-format-headline--wrap
2586 headline info
'org-e-odt-format-toc-headline
)
2587 (org-export-get-relative-level headline info
)))))
2589 (let* ((lang-specific-heading "Table of Contents")) ; FIXME
2591 (org-e-odt-begin-toc lang-specific-heading depth
)
2592 (org-e-odt-toc-text toc-entries
)
2593 (org-e-odt-end-toc))))))
2595 (defun org-e-odt-suffix-from-snumber (snumber)
2596 (let* ((snu (replace-regexp-in-string "\\." "-" snumber
))
2597 (href (cdr (assoc (concat "sec-" snu
)
2598 org-export-preferred-target-alist
))))
2599 (org-solidify-link-text (or href snu
))))
2601 ;; (defun org-e-odt-format-line (line)
2602 ;; (case org-lparse-dyn-current-environment
2603 ;; ((quote fixedwidth) (concat (org-e-odt-encode-plain-text line) "\n"))
2604 ;; (t (concat line "\n"))))
2606 (defun org-e-odt-fix-class-name (kwd) ; audit callers of this function
2607 "Turn todo keyword into a valid class name.
2608 Replaces invalid characters with \"_\"."
2610 (while (string-match "[^a-zA-Z0-9_]" kwd
)
2611 (setq kwd
(replace-match "_" t t kwd
))))
2614 (defun org-e-odt-format-internal-link (text href
&optional extra
)
2615 (org-e-odt-format-link text
(concat "#" href
) extra
))
2617 (defun org-e-odt-format-extra-targets (extra-targets)
2618 (if (not extra-targets
) ""
2619 (mapconcat (lambda (x)
2621 (setq x
(org-solidify-link-text
2622 (if (org-uuidgen-p x
) (concat "ID-" x
) x
)))
2623 (org-e-odt-format-anchor "" x
))) extra-targets
"")))
2625 (defun org-e-odt-format-org-tags (tags)
2627 (org-e-odt-format-fontify
2630 (org-e-odt-format-fontify
2631 x
(concat "" ;; org-e-odt-tag-class-prefix
2632 (org-e-odt-fix-class-name x
))))
2634 (org-e-odt-format-spaces 1)) "tag")))
2636 (defun org-e-odt-format-section-number (&optional snumber level
)
2638 (and nil org-export-with-section-numbers
2639 ;; (not org-lparse-body-only)
2641 (org-e-odt-format-fontify snumber
(format "section-number-%d" level
))))
2643 ;; (defun org-e-odt-format-headline (title extra-targets tags
2644 ;; &optional snumber level)
2646 ;; (org-e-odt-format-extra-targets extra-targets)
2647 ;; (concat (org-e-odt-format-section-number snumber level) " ")
2649 ;; (and tags (concat (org-e-odt-format-spaces 3)
2650 ;; (org-e-odt-format-org-tags tags)))))
2652 ;; (defun org-e-odt-format-date (info)
2653 ;; (let ((date (plist-get info :date)))
2655 ;; ((and date (string-match "%" date))
2656 ;; (format-time-string date))
2658 ;; (t (format-time-string "%Y-%m-%d %T %Z")))))
2662 ;;; Internal Functions (Ngz)
2664 (defun org-e-odt--caption/label-string
(caption label info
)
2665 "Return caption and label HTML string for floats.
2667 CAPTION is a cons cell of secondary strings, the car being the
2668 standard caption and the cdr its short form. LABEL is a string
2669 representing the label. INFO is a plist holding contextual
2672 If there's no caption nor label, return the empty string.
2674 For non-floats, see `org-e-odt--wrap-label'."
2675 (setq label nil
) ;; FIXME
2677 (let ((label-str (if label
(format "\\label{%s}" label
) "")))
2679 ((and (not caption
) (not label
)) "")
2680 ((not caption
) (format "\\label{%s}\n" label
))
2681 ;; Option caption format with short name.
2683 (format "\\caption[%s]{%s%s}\n"
2684 (org-export-data (cdr caption
) info
)
2686 (org-export-data (car caption
) info
)))
2687 ;; Standard caption format.
2688 ;; (t (format "\\caption{%s%s}\n"
2690 ;; (org-export-data (car caption) info)))
2691 (t (org-export-data (car caption
) info
)))))
2693 (defun org-e-odt--find-verb-separator (s)
2694 "Return a character not used in string S.
2695 This is used to choose a separator for constructs like \\verb."
2696 (let ((ll "~,./?;':\"|!@#%^&-_=+abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ<>()[]{}"))
2697 (loop for c across ll
2698 when
(not (string-match (regexp-quote (char-to-string c
)) s
))
2699 return
(char-to-string c
))))
2701 (defun org-e-odt--quotation-marks (text info
)
2702 "Export quotation marks depending on language conventions.
2703 TEXT is a string containing quotation marks to be replaced. INFO
2704 is a plist used as a communication channel."
2707 (while (setq start
(string-match (car l
) text start
))
2708 (let ((new-quote (concat (match-string 1 text
) (cdr l
))))
2709 (setq text
(replace-match new-quote t t text
))))))
2710 (cdr (or (assoc (plist-get info
:language
) org-e-odt-quotes
)
2711 ;; Falls back on English.
2712 (assoc "en" org-e-odt-quotes
))))
2715 (defun org-e-odt--wrap-label (element output
)
2716 "Wrap label associated to ELEMENT around OUTPUT, if appropriate.
2717 This function shouldn't be used for floats. See
2718 `org-e-odt--caption/label-string'."
2719 ;; (let ((label (org-element-property :name element)))
2720 ;; (if (or (not output) (not label) (string= output "") (string= label ""))
2722 ;; (concat (format "\\label{%s}\n" label) output)))
2727 ;;; Transcode Helpers
2729 (defun* org-e-odt-format-headline
2730 (todo todo-type priority text tags
2731 &key level section-number headline-label
&allow-other-keys
)
2732 (concat (org-e-odt-todo todo
) (and todo
" ") text
2733 (and tags
(org-e-odt-format-spaces 3))
2734 (and tags
(org-e-odt-format-org-tags tags
))))
2738 (defun org-e-odt-htmlfontify-string (line)
2739 (let* ((hfy-html-quote-regex "\\([<\"&> ]\\)")
2740 (hfy-html-quote-map '(("\"" """)
2745 (" " "<text:tab/>")))
2746 (hfy-face-to-css 'org-e-odt-hfy-face-to-css
)
2747 (hfy-optimisations-1 (copy-seq hfy-optimisations
))
2748 (hfy-optimisations (add-to-list 'hfy-optimisations-1
2750 (hfy-begin-span-handler
2751 (lambda (style text-block text-id text-begins-block-p
)
2752 (insert (format "<text:span text:style-name=\"%s\">" style
))))
2753 (hfy-end-span-handler (lambda nil
(insert "</text:span>"))))
2754 (htmlfontify-string line
)))
2756 (defun org-e-odt-do-format-code
2757 (code &optional lang refs retain-labels num-start
)
2758 (let* ((lang (or (assoc-default lang org-src-lang-modes
) lang
))
2759 (lang-mode (and lang
(intern (format "%s-mode" lang
))))
2760 (code-lines (org-split-string code
"\n"))
2761 (code-length (length code-lines
))
2762 (use-htmlfontify-p (and (functionp lang-mode
)
2763 org-e-odt-fontify-srcblocks
2764 (require 'htmlfontify nil t
)
2765 (fboundp 'htmlfontify-string
)))
2766 (code (if (not use-htmlfontify-p
) code
2770 (font-lock-fontify-buffer)
2772 (fontifier (if use-htmlfontify-p
'org-e-odt-htmlfontify-string
2773 'org-e-odt-encode-plain-text
))
2774 (par-style (if use-htmlfontify-p
"OrgSrcBlock"
2775 "OrgFixedWidthBlock"))
2777 (assert (= code-length
(length (org-split-string code
"\n"))))
2779 (org-export-format-code
2781 (lambda (loc line-num ref
)
2783 (concat par-style
(and (= (incf i
) code-length
) "LastLine")))
2785 (setq loc
(concat loc
(and ref retain-labels
(format " (%s)" ref
))))
2786 (setq loc
(funcall fontifier loc
))
2788 (setq loc
(org-e-odt-format-target loc
(concat "coderef-" ref
))))
2789 (setq loc
(org-e-odt-format-stylized-paragraph par-style loc
))
2790 (if (not line-num
) loc
2791 (org-e-odt-format-tags
2792 '("<text:list-item>" .
"</text:list-item>") loc
)))
2795 ((not num-start
) code
)
2796 ((equal num-start
0)
2797 (org-e-odt-format-tags
2798 '("<text:list text:style-name=\"OrgSrcBlockNumberedLine\"%s>"
2799 .
"</text:list>") code
" text:continue-numbering=\"false\""))
2800 (t (org-e-odt-format-tags
2801 '("<text:list text:style-name=\"OrgSrcBlockNumberedLine\"%s>"
2802 .
"</text:list>") code
" text:continue-numbering=\"true\"")))))
2804 (defun org-e-odt-format-code (element info
)
2805 (let* ((lang (org-element-property :language element
))
2806 ;; Extract code and references.
2807 (code-info (org-export-unravel-code element
))
2808 (code (car code-info
))
2809 (refs (cdr code-info
))
2810 ;; Does the src block contain labels?
2811 (retain-labels (org-element-property :retain-labels element
))
2812 ;; Does it have line numbers?
2813 (num-start (case (org-element-property :number-lines element
)
2814 (continued (org-export-get-loc element info
))
2816 (org-e-odt-do-format-code code lang refs retain-labels num-start
)))
2822 (defun org-e-odt-template (contents info
)
2823 "Return complete document string after HTML conversion.
2824 CONTENTS is the transcoded contents string. RAW-DATA is the
2825 original parsed data. INFO is a plist holding export options."
2827 (org-e-odt-update-meta-file info
)
2829 (insert-file-contents
2830 (or org-e-odt-content-template-file
2831 (expand-file-name "OrgOdtContentTemplate.xml"
2832 org-e-odt-styles-dir
)))
2833 (goto-char (point-min))
2834 (re-search-forward "</office:text>" nil nil
)
2835 (goto-char (match-beginning 0))
2838 (insert (org-e-odt-format-preamble info
))
2839 ;; Table of Contents
2840 (let ((depth (plist-get info
:with-toc
)))
2841 (when (wholenump depth
) (insert (org-e-odt-toc depth info
))))
2843 ;; Copy styles.xml. Also dump htmlfontify styles, if there is any.
2844 (org-e-odt-update-styles-file info
)
2846 ;; Update styles.xml - take care of outline numbering
2847 (with-current-buffer
2848 (find-file-noselect (expand-file-name "styles.xml") t
)
2849 ;; Don't make automatic backup of styles.xml file. This setting
2850 ;; prevents the backed-up styles.xml file from being zipped in to
2851 ;; odt file. This is more of a hackish fix. Better alternative
2852 ;; would be to fix the zip command so that the output odt file
2853 ;; includes only the needed files and excludes any auto-generated
2854 ;; extra files like backups and auto-saves etc etc. Note that
2855 ;; currently the zip command zips up the entire temp directory so
2856 ;; that any auto-generated files created under the hood ends up in
2857 ;; the resulting odt file.
2858 (set (make-local-variable 'backup-inhibited
) t
)
2859 (org-e-odt-configure-outline-numbering))
2863 (buffer-substring-no-properties (point-min) (point-max))))
2867 ;;; Transcode Functions
2871 (defun org-e-odt-bold (bold contents info
)
2872 "Transcode BOLD from Org to ODT.
2873 CONTENTS is the text with bold markup. INFO is a plist holding
2874 contextual information."
2875 (org-e-odt-format-fontify contents
'bold
))
2880 (defun org-e-odt-center-block (center-block contents info
)
2881 "Transcode a CENTER-BLOCK element from Org to ODT.
2882 CONTENTS holds the contents of the center block. INFO is a plist
2883 holding contextual information."
2884 (org-e-odt--wrap-label center-block contents
))
2889 (defun org-e-odt-clock (clock contents info
)
2890 "Transcode a CLOCK element from Org to ODT.
2891 CONTENTS is nil. INFO is a plist used as a communication
2893 (org-e-odt-format-fontify
2894 (concat (org-e-odt-format-fontify org-clock-string
"timestamp-kwd")
2895 (org-e-odt-format-fontify
2896 (concat (org-translate-time (org-element-property :value clock
))
2897 (let ((time (org-element-property :time clock
)))
2898 (and time
(format " (%s)" time
))))
2900 "timestamp-wrapper"))
2905 (defun org-e-odt-code (code contents info
)
2906 "Transcode a CODE object from Org to ODT.
2907 CONTENTS is nil. INFO is a plist used as a communication
2909 (org-e-odt-format-fontify (org-element-property :value code
) 'code
))
2914 ;; Comments are ignored.
2919 ;; Comment Blocks are ignored.
2924 (defun org-e-odt-drawer (drawer contents info
)
2925 "Transcode a DRAWER element from Org to ODT.
2926 CONTENTS holds the contents of the block. INFO is a plist
2927 holding contextual information."
2928 (let* ((name (org-element-property :drawer-name drawer
))
2929 (output (if (functionp org-e-odt-format-drawer-function
)
2930 (funcall org-e-odt-format-drawer-function
2932 ;; If there's no user defined function: simply
2933 ;; display contents of the drawer.
2935 (org-e-odt--wrap-label drawer output
)))
2940 (defun org-e-odt-dynamic-block (dynamic-block contents info
)
2941 "Transcode a DYNAMIC-BLOCK element from Org to ODT.
2942 CONTENTS holds the contents of the block. INFO is a plist
2943 holding contextual information. See `org-export-data'."
2944 (org-e-odt--wrap-label dynamic-block contents
))
2949 (defun org-e-odt-entity (entity contents info
)
2950 "Transcode an ENTITY object from Org to ODT.
2951 CONTENTS are the definition itself. INFO is a plist holding
2952 contextual information."
2953 ;; (let ((ent (org-element-property :latex entity)))
2954 ;; (if (org-element-property :latex-math-p entity)
2955 ;; (format "$%s$" ent)
2957 (org-element-property :utf-8 entity
))
2962 (defun org-e-odt-example-block (example-block contents info
)
2963 "Transcode a EXAMPLE-BLOCK element from Org to ODT.
2964 CONTENTS is nil. INFO is a plist holding contextual information."
2965 (org-e-odt--wrap-label
2966 example-block
(org-e-odt-format-code example-block info
)))
2971 (defun org-e-odt-export-snippet (export-snippet contents info
)
2972 "Transcode a EXPORT-SNIPPET object from Org to ODT.
2973 CONTENTS is nil. INFO is a plist holding contextual information."
2974 (when (eq (org-export-snippet-backend export-snippet
) 'e-odt
)
2975 (org-element-property :value export-snippet
)))
2980 (defun org-e-odt-export-block (export-block contents info
)
2981 "Transcode a EXPORT-BLOCK element from Org to ODT.
2982 CONTENTS is nil. INFO is a plist holding contextual information."
2983 (when (string= (org-element-property :type export-block
) "ODT")
2984 (org-remove-indentation (org-element-property :value export-block
))))
2989 (defun org-e-odt-fixed-width (fixed-width contents info
)
2990 "Transcode a FIXED-WIDTH element from Org to ODT.
2991 CONTENTS is nil. INFO is a plist holding contextual information."
2992 (org-e-odt--wrap-label
2993 fixed-width
(org-e-odt-do-format-code
2994 (org-element-property :value fixed-width
))))
2997 ;;;; Footnote Definition
2999 ;; Footnote Definitions are ignored.
3002 ;;;; Footnote Reference
3004 (defun org-e-odt-footnote-def (raw info
) ; FIXME
3005 (if (equal (org-element-type raw
) 'org-data
)
3006 (org-trim (org-export-data raw info
)) ; fix paragraph style
3007 (org-e-odt-format-stylized-paragraph
3008 'footnote
(org-trim (org-export-data raw info
)))))
3010 (defvar org-e-odt-footnote-separator
3011 (org-e-odt-format-fontify "," 'superscript
))
3013 (defun org-e-odt-footnote-reference (footnote-reference contents info
)
3014 "Transcode a FOOTNOTE-REFERENCE element from Org to ODT.
3015 CONTENTS is nil. INFO is a plist holding contextual information."
3017 ;; Insert separator between two footnotes in a row.
3018 (let ((prev (org-export-get-previous-element footnote-reference info
)))
3019 (when (eq (org-element-type prev
) 'footnote-reference
)
3020 org-e-odt-footnote-separator
))
3022 ((not (org-export-footnote-first-reference-p footnote-reference info
))
3023 (let* ((n (org-export-get-footnote-number footnote-reference info
)))
3024 (org-e-odt-format-footnote-reference n
"IGNORED" 100)))
3025 ;; Inline definitions are secondary strings.
3026 ((eq (org-element-property :type footnote-reference
) 'inline
)
3027 (let* ((raw (org-export-get-footnote-definition footnote-reference info
))
3028 (n (org-export-get-footnote-number footnote-reference info
))
3029 (def (org-e-odt-footnote-def raw info
)))
3030 (org-e-odt-format-footnote-reference n def
1)))
3031 ;; Non-inline footnotes definitions are full Org data.
3033 (let* ((raw (org-export-get-footnote-definition footnote-reference info
))
3034 (n (org-export-get-footnote-number footnote-reference info
))
3035 (def (org-e-odt-footnote-def raw info
)))
3036 (org-e-odt-format-footnote-reference n def
1))))))
3041 (defun org-e-odt-todo (todo)
3043 (org-e-odt-format-fontify
3045 "" ; org-e-odt-todo-kwd-class-prefix
3046 (org-e-odt-fix-class-name todo
))
3047 (list (if (member todo org-done-keywords
) "done" "todo")
3050 (defun org-e-odt-format-headline--wrap (headline info
3051 &optional format-function
3053 "Transcode an HEADLINE element from Org to ODT.
3054 CONTENTS holds the contents of the headline. INFO is a plist
3055 holding contextual information."
3056 (let* ((level (+ (org-export-get-relative-level headline info
)))
3057 (headline-number (org-export-get-headline-number headline info
))
3058 (section-number (and (org-export-numbered-headline-p headline info
)
3059 (mapconcat 'number-to-string
3060 headline-number
".")))
3061 (todo (and (plist-get info
:with-todo-keywords
)
3062 (let ((todo (org-element-property :todo-keyword headline
)))
3063 (and todo
(org-export-data todo info
)))))
3064 (todo-type (and todo
(org-element-property :todo-type headline
)))
3065 (priority (and (plist-get info
:with-priority
)
3066 (org-element-property :priority headline
)))
3067 (text (org-export-data (org-element-property :title headline
) info
))
3068 (tags (and (plist-get info
:with-tags
)
3069 (org-export-get-tags headline info
)))
3070 (headline-label (concat "sec-" (mapconcat 'number-to-string
3071 headline-number
"-")))
3072 (format-function (cond
3073 ((functionp format-function
) format-function
)
3074 ((functionp org-e-odt-format-headline-function
)
3076 (lambda (todo todo-type priority text tags
3078 (funcall org-e-odt-format-headline-function
3079 todo todo-type priority text tags
))))
3080 (t 'org-e-odt-format-headline
))))
3081 (apply format-function
3082 todo todo-type priority text tags
3083 :headline-label headline-label
:level level
3084 :section-number section-number extra-keys
)))
3086 (defun org-e-odt-headline (headline contents info
)
3087 "Transcode an HEADLINE element from Org to ODT.
3088 CONTENTS holds the contents of the headline. INFO is a plist
3089 holding contextual information."
3090 (let* ((numberedp (org-export-numbered-headline-p headline info
))
3091 ;; Get level relative to current parsed data.
3092 (level (org-export-get-relative-level headline info
))
3093 (text (org-export-data (org-element-property :title headline
) info
))
3094 ;; Create the headline text.
3095 (full-text (org-e-odt-format-headline--wrap headline info
)))
3097 ;; Case 1: This is a footnote section: ignore it.
3098 ((org-element-property :footnote-section-p headline
) nil
)
3099 ;; Case 2. This is a deep sub-tree: export it as a list item.
3100 ;; Also export as items headlines for which no section
3101 ;; format has been found.
3102 ((org-export-low-level-p headline info
) ; FIXME (or (not section-fmt))
3103 ;; Build the real contents of the sub-tree.
3104 (let* ((type (if numberedp
'unordered
'unordered
)) ; FIXME
3105 (itemized-body (org-e-odt-format-list-item
3106 contents type nil nil full-text
)))
3108 (and (org-export-first-sibling-p headline info
)
3109 (org-e-odt-begin-plain-list type
))
3111 (and (org-export-last-sibling-p headline info
)
3112 (org-e-odt-end-plain-list type
)))))
3113 ;; Case 3. Standard headline. Export it as a section.
3115 (let* ((extra-ids (list (org-element-property :custom-id headline
)
3116 (org-element-property :id headline
)))
3117 (extra-ids nil
) ; FIXME
3118 (id (concat "sec-" (mapconcat 'number-to-string
3119 (org-export-get-headline-number
3120 headline info
) "-"))))
3122 (org-e-odt-format-tags
3123 '("<text:h text:style-name=\"Heading_20_%s\" text:outline-level=\"%s\">" .
3125 (concat (org-e-odt-format-extra-targets extra-ids
)
3126 (if (not id
) full-text
(org-e-odt-format-target full-text id
) ))
3131 ;;;; Horizontal Rule
3133 (defun org-e-odt-horizontal-rule (horizontal-rule contents info
)
3134 "Transcode an HORIZONTAL-RULE object from Org to ODT.
3135 CONTENTS is nil. INFO is a plist holding contextual information."
3136 (let ((attr (mapconcat #'identity
3137 (org-element-property :attr_odt horizontal-rule
)
3139 (org-e-odt--wrap-label horizontal-rule
3140 (org-e-odt-format-horizontal-line))))
3143 ;;;; Inline Babel Call
3145 ;; Inline Babel Calls are ignored.
3148 ;;;; Inline Src Block
3150 (defun org-e-odt-inline-src-block (inline-src-block contents info
)
3151 "Transcode an INLINE-SRC-BLOCK element from Org to ODT.
3152 CONTENTS holds the contents of the item. INFO is a plist holding
3153 contextual information."
3154 (let* ((org-lang (org-element-property :language inline-src-block
))
3155 (code (org-element-property :value inline-src-block
))
3156 (separator (org-e-odt--find-verb-separator code
)))
3162 (defun org-e-odt-format-section (text class
&optional id
)
3163 (let ((extra (concat (when id
(format " id=\"%s\"" id
)))))
3164 (concat (format "<div class=\"%s\"%s>\n" class extra
) text
"</div>\n")))
3166 (defun org-e-odt-inlinetask (inlinetask contents info
)
3167 "Transcode an INLINETASK element from Org to ODT.
3168 CONTENTS holds the contents of the block. INFO is a plist
3169 holding contextual information."
3171 ;; If `org-e-odt-format-inlinetask-function' is provided, call it
3172 ;; with appropriate arguments.
3173 ((functionp org-e-odt-format-inlinetask-function
)
3174 (let ((format-function
3176 (lambda (todo todo-type priority text tags
3177 &key contents
&allow-other-keys
)
3178 (funcall org-e-odt-format-inlinetask-function
3179 todo todo-type priority text tags contents
)))))
3180 (org-e-odt-format-headline--wrap
3181 inlinetask info format-function
:contents contents
)))
3182 ;; Otherwise, use a default template.
3183 (t (org-e-odt--wrap-label
3185 (org-e-odt-format-stylized-paragraph
3186 nil
(org-e-odt-format-textbox
3187 (concat (org-e-odt-format-stylized-paragraph
3188 "OrgInlineTaskHeading" (org-e-odt-format-headline--wrap
3191 nil nil
"OrgInlineTaskFrame" " style:rel-width=\"100%\""))))))
3195 (defun org-e-odt-italic (italic contents info
)
3196 "Transcode ITALIC from Org to ODT.
3197 CONTENTS is the text with italic markup. INFO is a plist holding
3198 contextual information."
3199 (org-e-odt-format-fontify contents
'italic
))
3204 (defun org-e-odt-format-list-item (contents type checkbox
3205 &optional term-counter-id
3209 (org-e-odt-format-fontify (case checkbox
3212 (trans "[-]")) 'code
)))
3214 (org-e-odt-begin-list-item type term-counter-id headline
)
3215 ;; FIXME checkbox (and checkbox " ")
3217 (org-e-odt-end-list-item type
)))
3219 (defun org-e-odt-item (item contents info
)
3220 "Transcode an ITEM element from Org to ODT.
3221 CONTENTS holds the contents of the item. INFO is a plist holding
3222 contextual information."
3223 (let* ((plain-list (org-export-get-parent item info
))
3224 (type (org-element-property :type plain-list
))
3225 (counter (org-element-property :counter item
))
3226 (checkbox (org-element-property :checkbox item
))
3227 (tag (let ((tag (org-element-property :tag item
)))
3228 (and tag
(org-export-data tag info
)))))
3229 (org-e-odt-format-list-item
3230 contents type checkbox
(or tag counter
))))
3235 (defun org-e-odt-keyword (keyword contents info
)
3236 "Transcode a KEYWORD element from Org to ODT.
3237 CONTENTS is nil. INFO is a plist holding contextual information."
3238 (let ((key (org-element-property :key keyword
))
3239 (value (org-element-property :value keyword
)))
3241 ((string= key
"LATEX") value
)
3242 ((string= key
"INDEX") (format "\\index{%s}" value
))
3243 ((string= key
"TARGET") nil
; FIXME
3244 ;; (format "\\label{%s}" (org-export-solidify-link-text value))
3246 ((string= key
"toc")
3247 (let ((value (downcase value
)))
3249 ((string-match "\\<headlines\\>" value
)
3250 (let ((depth (or (and (string-match "[0-9]+" value
)
3251 (string-to-number (match-string 0 value
)))
3252 (plist-get info
:with-toc
))))
3253 (when (wholenump depth
) (org-e-odt-toc depth info
))))
3254 ((string= "tables" value
) "FIXME")
3255 ((string= "figures" value
) "FIXME")
3256 ((string= "listings" value
)
3258 ;; At the moment, src blocks with a caption are wrapped
3259 ;; into a figure environment.
3263 ;;;; Latex Environment
3265 (defun org-e-odt-format-latex (latex-frag processing-type
)
3266 (let* ((prefix (case processing-type
3268 (mathml "ltxmathml/")))
3270 (concat prefix
(file-name-sans-extension
3271 (file-name-nondirectory (buffer-file-name)))))
3272 (cache-dir (file-name-directory (buffer-file-name )))
3273 (display-msg (case processing-type
3274 (dvipng "Creating LaTeX Image...")
3275 (mathml "Creating MathML snippet..."))))
3278 (org-format-latex cache-relpath cache-dir nil display-msg
3279 nil nil processing-type
)
3282 (defun org-e-odt-latex-environment (latex-environment contents info
)
3283 "Transcode a LATEX-ENVIRONMENT element from Org to ODT.
3284 CONTENTS is nil. INFO is a plist holding contextual information."
3285 (org-e-odt--wrap-label
3288 (org-remove-indentation
3289 (org-element-property :value latex-environment
)))
3290 (processing-type (plist-get info
:LaTeX-fragments
))
3291 (caption (org-element-property :caption latex-environment
))
3292 (short-caption (and (cdr caption
)
3293 (org-export-data (cdr caption
) info
)))
3294 (caption (and (car caption
) (org-export-data (car caption
) info
)))
3295 (label (org-element-property :name latex-environment
))
3297 (label (org-element-property :name latex-environment
)))
3299 ((member processing-type
'(t mathjax
))
3300 (org-e-odt-format-formula latex-environment info
))
3301 ((equal processing-type
'dvipng
)
3302 (org-e-odt-format-stylized-paragraph
3303 nil
(org-e-odt-link--inline-image latex-environment info
)))
3310 ;; (when latex-frag ; FIXME
3311 ;; (setq href (org-propertize href :title "LaTeX Fragment"
3312 ;; :description latex-frag)))
3314 ;; provide descriptions
3316 (defun org-e-odt-latex-fragment (latex-fragment contents info
)
3317 "Transcode a LATEX-FRAGMENT object from Org to ODT.
3318 CONTENTS is nil. INFO is a plist holding contextual information."
3319 (let* ((latex-frag (org-element-property :value latex-fragment
))
3320 (processing-type (plist-get info
:LaTeX-fragments
)))
3322 ((member processing-type
'(t mathjax
))
3323 (org-e-odt-format-formula latex-fragment info
))
3324 ((equal processing-type
'dvipng
)
3325 (org-e-odt-link--inline-image latex-fragment info
))
3331 (defun org-e-odt-line-break (line-break contents info
)
3332 "Transcode a LINE-BREAK object from Org to ODT.
3333 CONTENTS is nil. INFO is a plist holding contextual information."
3334 "<text:line-break/>\n")
3339 (defun org-e-odt-link--inline-image (element info
)
3340 "Return HTML code for an inline image.
3341 LINK is the link pointing to the inline image. INFO is a plist
3342 used as a communication channel."
3344 ((eq (org-element-type element
) 'link
)
3345 (let* ((type (org-element-property :type element
))
3346 (raw-path (org-element-property :path element
)))
3347 (cond ((member type
'("http" "https"))
3348 (concat type
":" raw-path
))
3349 ((file-name-absolute-p raw-path
)
3350 (expand-file-name raw-path
))
3352 ((member (org-element-type element
)
3353 '(latex-fragment latex-environment
))
3354 (let* ((latex-frag (org-remove-indentation
3355 (org-element-property
3357 (formula-link (org-e-odt-format-latex
3358 latex-frag
'dvipng
)))
3360 (string-match "file:\\([^]]*\\)" formula-link
)
3361 (match-string 1 formula-link
))))
3362 (t (error "what is this?"))))
3363 (href (org-e-odt-format-tags
3364 "<draw:image xlink:href=\"%s\" xlink:type=\"simple\" xlink:show=\"embed\" xlink:actuate=\"onLoad\"/>" ""
3365 (org-e-odt-copy-image-file src
)))
3366 ;; extract attributes from #+ATTR_ODT line.
3367 (attr-from (case (org-element-type element
)
3368 (link (org-export-get-parent-paragraph element info
))
3370 ;; convert attributes to a plist.
3371 (attr-plist (org-e-odt-element-attributes attr-from info
))
3372 ;; handle `:anchor', `:style' and `:attributes' properties.
3374 (car (assoc-string (plist-get attr-plist
:anchor
)
3375 '(("as-char") ("paragraph") ("page")) t
)))
3377 (and user-frame-anchor
(plist-get attr-plist
:style
)))
3379 (and user-frame-anchor
(plist-get attr-plist
:attributes
)))
3381 (list user-frame-style user-frame-attrs user-frame-anchor
))
3382 ;; (embed-as (or embed-as user-frame-anchor "paragraph"))
3384 ;; handle `:width', `:height' and `:scale' properties.
3385 (size (org-e-odt-image-size-from-file
3386 src
(plist-get attr-plist
:width
)
3387 (plist-get attr-plist
:height
)
3388 (plist-get attr-plist
:scale
) nil
;; embed-as
3391 (width (car size
)) (height (cdr size
))
3393 (case (org-element-type element
)
3394 ((org-e-odt-standalone-image-p element info
) "paragraph")
3395 (latex-fragment "as-char")
3396 (latex-environment "paragraph")
3398 (captions (org-e-odt-format-label element info
'definition
))
3399 (caption (car captions
)) (short-caption (cdr captions
))
3400 (entity (concat (and caption
"Captioned") embed-as
"Image")))
3401 (org-e-odt-format-entity entity href width height
3402 captions user-frame-params
)))
3404 (defun org-e-odt-format-entity (entity href width height
&optional
3405 captions user-frame-params
)
3406 (let* ((caption (car captions
)) (short-caption (cdr captions
))
3407 (entity-style (assoc-string entity org-e-odt-entity-frame-styles t
))
3408 default-frame-params frame-params
)
3411 (setq default-frame-params
(nth 2 entity-style
))
3412 (setq frame-params
(org-e-odt-merge-frame-params
3413 default-frame-params user-frame-params
))
3414 (apply 'org-e-odt-format-frame href width height frame-params
))
3416 (setq default-frame-params
(nth 3 entity-style
))
3417 (setq frame-params
(org-e-odt-merge-frame-params
3418 default-frame-params user-frame-params
))
3419 (apply 'org-e-odt-format-textbox
3420 (org-e-odt-format-stylized-paragraph
3423 (apply 'org-e-odt-format-frame href width height
3424 (let ((entity-style-1 (copy-sequence
3425 (nth 2 entity-style
))))
3426 (setcar (cdr entity-style-1
)
3428 (cadr entity-style-1
)
3430 (format " draw:name=\"%s\" "
3434 width height frame-params
)))))
3436 (defvar org-e-odt-standalone-image-predicate
3437 (function (lambda (paragraph)
3438 (or (org-element-property :caption paragraph
)
3439 (org-element-property :name paragraph
)))))
3441 (defun org-e-odt-standalone-image-p (element info
&optional predicate
)
3442 "Test if ELEMENT is a standalone image for the purpose ODT export.
3443 INFO is a plist holding contextual information.
3445 Return non-nil, if ELEMENT is of type paragraph and it's sole
3446 content, save for whitespaces, is a link that qualifies as an
3449 Return non-nil, if ELEMENT is of type link and it's containing
3450 paragraph has no other content save for leading and trailing
3453 Return nil, otherwise.
3455 Bind `org-e-odt-standalone-image-predicate' to constrain
3456 paragraph further. For example, to check for only captioned
3457 standalone images, do the following.
3459 \(setq org-e-odt-standalone-image-predicate
3460 \(lambda \(paragraph\)
3461 \(org-element-property :caption paragraph\)\)\)
3463 (let ((paragraph (case (org-element-type element
)
3465 (link (and (org-export-inline-image-p
3466 element org-e-odt-inline-image-rules
)
3467 (org-export-get-parent element info
)))
3470 (assert (eq (org-element-type paragraph
) 'paragraph
))
3471 (when (or (not (and (boundp 'org-e-odt-standalone-image-predicate
)
3472 (functionp org-e-odt-standalone-image-predicate
)))
3473 (funcall org-e-odt-standalone-image-predicate paragraph
))
3474 (let ((contents (org-element-contents paragraph
)))
3475 (loop for x in contents
3476 with inline-image-count
= 0
3478 ((eq (org-element-type x
) 'plain-text
)
3479 (not (org-string-nw-p x
)))
3480 ((eq (org-element-type x
) 'link
)
3481 (when (org-export-inline-image-p
3482 x org-e-odt-inline-image-rules
)
3483 (= (incf inline-image-count
) 1)))
3486 (defun org-e-odt-link (link desc info
)
3487 "Transcode a LINK object from Org to ODT.
3489 DESC is the description part of the link, or the empty string.
3490 INFO is a plist holding contextual information. See
3492 (let* ((type (org-element-property :type link
))
3493 (raw-path (org-element-property :path link
))
3494 ;; Ensure DESC really exists, or set it to nil.
3495 (desc (and (not (string= desc
"")) desc
))
3496 (imagep (org-export-inline-image-p
3497 link org-e-odt-inline-image-rules
))
3499 ((member type
'("http" "https" "ftp" "mailto"))
3500 (concat type
":" raw-path
))
3501 ((string= type
"file")
3502 (when (string-match "\\(.+\\)::.+" raw-path
)
3503 (setq raw-path
(match-string 1 raw-path
)))
3504 (if (file-name-absolute-p raw-path
)
3505 (concat "file://" (expand-file-name raw-path
))
3506 (concat "file://" raw-path
)))
3511 ((and (not desc
) (org-export-inline-image-p
3512 link org-e-odt-inline-image-rules
))
3513 (org-e-odt-link--inline-image link info
))
3514 ;; Radio target: Transcode target's contents and use them as
3515 ;; link's description.
3516 ((string= type
"radio")
3517 (let ((destination (org-export-resolve-radio-link link info
)))
3519 (org-e-odt-format-internal-link
3520 (org-export-data (org-element-contents destination
) info
)
3521 (org-export-solidify-link-text path
)))))
3522 ;; Links pointing to an headline: Find destination and build
3523 ;; appropriate referencing command.
3524 ((member type
'("custom-id" "fuzzy" "id"))
3525 (let ((destination (if (string= type
"fuzzy")
3526 (org-export-resolve-fuzzy-link link info
)
3527 (org-export-resolve-id-link link info
))))
3528 (case (org-element-type destination
)
3529 ;; Fuzzy link points nowhere.
3531 (org-e-odt-format-fontify
3532 (or desc
(org-export-data
3533 (org-element-property :raw-link link
) info
))
3535 ;; Fuzzy link points to an invisible target.
3537 ;; LINK points to an headline. If headlines are numbered
3538 ;; and the link has no description, display headline's
3539 ;; number. Otherwise, display description or headline's
3542 (let* ((headline-no (org-export-get-headline-number destination info
))
3543 (label (format "sec-%s" (mapconcat 'number-to-string
3545 (section-no (mapconcat 'number-to-string headline-no
".")))
3549 ((plist-get info
:section-numbers
) section-no
)
3551 (org-element-property :title destination
) info
))))
3552 (org-e-odt-format-internal-link desc label
)))
3553 ;; Fuzzy link points to a target. Do as above.
3556 ;; (setq number (cond
3557 ;; ((org-e-odt-standalone-image-p destination info)
3558 ;; (org-export-get-ordinal
3559 ;; (assoc 'link (org-element-contents destination))
3560 ;; info 'link 'org-e-odt-standalone-image-p))
3561 ;; (t (org-export-get-ordinal destination info))))
3562 ;; (setq desc (when number
3563 ;; (if (atom number) (number-to-string number)
3564 ;; (mapconcat 'number-to-string number ".")))))
3566 (let ((label-reference
3567 (org-e-odt-format-label destination info
'reference
)))
3568 (assert label-reference
)
3569 label-reference
)))))
3570 ;; Coderef: replace link with the reference name or the
3571 ;; equivalent line number.
3572 ((string= type
"coderef")
3573 (let* ((fmt (org-export-get-coderef-format path desc
))
3574 (res (org-export-resolve-coderef path info
))
3575 (org-e-odt-suppress-xref nil
)
3576 (href (org-xml-format-href (concat "#coderef-" path
))))
3577 (format fmt
(org-e-odt-format-link res href
))))
3578 ;; Link type is handled by a special function.
3579 ((functionp (setq protocol
(nth 2 (assoc type org-link-protocols
))))
3580 (funcall protocol
(org-link-unescape path
) desc
'html
))
3581 ;; External link with a description part.
3582 ((and path desc
) (org-e-odt-format-link desc path
))
3583 ;; External link without a description part.
3584 (path (org-e-odt-format-link path path
))
3585 ;; No path, only description. Try to do something useful.
3586 (t (org-e-odt-format-fontify desc
'italic
)))))
3591 ;; Babel Calls are ignored.
3596 (defun org-e-odt-macro (macro contents info
)
3597 "Transcode a MACRO element from Org to ODT.
3598 CONTENTS is nil. INFO is a plist holding contextual information."
3599 ;; Use available tools.
3600 (org-export-expand-macro macro info
))
3605 (defun org-e-odt-paragraph (paragraph contents info
)
3606 "Transcode a PARAGRAPH element from Org to ODT.
3607 CONTENTS is the contents of the paragraph, as a string. INFO is
3608 the plist used as a communication channel."
3609 (let* ((style nil
) ; FIXME
3610 (class (cdr (assoc style
'((footnote .
"footnote")
3612 (extra (if class
(format " class=\"%s\"" class
) ""))
3613 (parent (org-export-get-parent paragraph info
))
3614 (parent-type (org-element-type parent
))
3615 (style (case parent-type
3616 (quote-block 'quote
)
3617 (center-block 'center
)
3618 (footnote-definition 'footnote
)
3620 (org-e-odt-format-stylized-paragraph style contents
)))
3625 (defun org-e-odt-plain-list (plain-list contents info
)
3626 "Transcode a PLAIN-LIST element from Org to ODT.
3627 CONTENTS is the contents of the list. INFO is a plist holding
3628 contextual information."
3629 (let* (arg1 ;; FIXME
3630 (type (org-element-property :type plain-list
))
3631 (attr (mapconcat #'identity
3632 (org-element-property :attr_odt plain-list
)
3634 (org-e-odt--wrap-label
3635 plain-list
(format "%s\n%s%s"
3636 (org-e-odt-begin-plain-list type
)
3637 contents
(org-e-odt-end-plain-list type
)))))
3641 ;; (defun org-e-odt-encode-plain-text (s)
3642 ;; "Convert plain text characters to HTML equivalent.
3643 ;; Possible conversions are set in `org-export-html-protect-char-alist'."
3644 ;; (let ((cl org-e-odt-protect-char-alist) c)
3645 ;; (while (setq c (pop cl))
3647 ;; (while (string-match (car c) s start)
3648 ;; (setq s (replace-match (cdr c) t t s)
3649 ;; start (1+ (match-beginning 0))))))
3652 (defun org-e-odt-plain-text (text info
)
3653 "Transcode a TEXT string from Org to ODT.
3654 TEXT is the string to transcode. INFO is a plist holding
3655 contextual information."
3656 (setq text
(org-e-odt-encode-plain-text text t
))
3657 ;; Protect %, #, &, $, ~, ^, _, { and }.
3658 ;; (while (string-match "\\([^\\]\\|^\\)\\([%$#&{}~^_]\\)" text)
3660 ;; (replace-match (format "\\%s" (match-string 2 text)) nil t text 2)))
3662 ;; (setq text (replace-regexp-in-string
3663 ;; "\\(?:[^\\]\\|^\\)\\(\\\\\\)\\(?:[^%$#&{}~^_\\]\\|$\\)"
3664 ;; "$\\backslash$" text nil t 1))
3665 ;; HTML into \HTML{} and TeX into \TeX{}.
3666 ;; (let ((case-fold-search nil)
3668 ;; (while (string-match "\\<\\(\\(?:La\\)?TeX\\)\\>" text start)
3669 ;; (setq text (replace-match
3670 ;; (format "\\%s{}" (match-string 1 text)) nil t text)
3671 ;; start (match-end 0))))
3672 ;; Handle quotation marks
3673 (setq text
(org-e-odt--quotation-marks text info
))
3674 ;; Convert special strings.
3675 (when (plist-get info
:with-special-strings
)
3678 (setq text
(replace-regexp-in-string (car pair
) (cdr pair
) text t nil
)))
3679 org-e-odt-special-string-regexps
))
3680 ;; Handle break preservation if required.
3681 (when (plist-get info
:preserve-breaks
)
3682 (setq text
(replace-regexp-in-string
3683 "\\(\\\\\\\\\\)?[ \t]*\n" "<text:line-break/>\n" text t
)))
3690 (defun org-e-odt-planning (planning contents info
)
3691 "Transcode a PLANNING element from Org to ODT.
3692 CONTENTS is nil. INFO is a plist used as a communication
3694 (org-e-odt-format-fontify
3696 (let ((closed (org-element-property :closed planning
)))
3698 (concat (org-e-odt-format-fontify org-closed-string
"timestamp-kwd")
3699 (org-e-odt-format-fontify (org-translate-time closed
)
3701 (let ((deadline (org-element-property :deadline planning
)))
3703 (concat (org-e-odt-format-fontify org-deadline-string
"timestamp-kwd")
3704 (org-e-odt-format-fontify (org-translate-time deadline
)
3706 (let ((scheduled (org-element-property :scheduled planning
)))
3708 (concat (org-e-odt-format-fontify org-scheduled-string
"timestamp-kwd")
3709 (org-e-odt-format-fontify (org-translate-time scheduled
)
3711 "timestamp-wrapper"))
3714 ;;;; Property Drawer
3716 (defun org-e-odt-property-drawer (property-drawer contents info
)
3717 "Transcode a PROPERTY-DRAWER element from Org to ODT.
3718 CONTENTS is nil. INFO is a plist holding contextual
3720 ;; The property drawer isn't exported but we want separating blank
3721 ;; lines nonetheless.
3727 (defun org-e-odt-quote-block (quote-block contents info
)
3728 "Transcode a QUOTE-BLOCK element from Org to ODT.
3729 CONTENTS holds the contents of the block. INFO is a plist
3730 holding contextual information."
3731 (org-e-odt--wrap-label quote-block contents
))
3736 (defun org-e-odt-quote-section (quote-section contents info
)
3737 "Transcode a QUOTE-SECTION element from Org to ODT.
3738 CONTENTS is nil. INFO is a plist holding contextual information."
3739 (let ((value (org-remove-indentation
3740 (org-element-property :value quote-section
))))
3741 (when value
(org-e-odt-do-format-code value
))))
3746 (defun org-e-odt-section (section contents info
) ; FIXME
3747 "Transcode a SECTION element from Org to ODT.
3748 CONTENTS holds the contents of the section. INFO is a plist
3749 holding contextual information."
3754 (defun org-e-odt-radio-target (radio-target text info
)
3755 "Transcode a RADIO-TARGET object from Org to ODT.
3756 TEXT is the text of the target. INFO is a plist holding
3757 contextual information."
3758 (org-e-odt-format-anchor
3759 text
(org-export-solidify-link-text
3760 (org-element-property :value radio-target
))))
3765 (defun org-e-odt-special-block (special-block contents info
)
3766 "Transcode a SPECIAL-BLOCK element from Org to ODT.
3767 CONTENTS holds the contents of the block. INFO is a plist
3768 holding contextual information."
3769 (let ((type (downcase (org-element-property :type special-block
))))
3770 (org-e-odt--wrap-label
3772 (format "\\begin{%s}\n%s\\end{%s}" type contents type
))))
3777 (defun org-e-odt-src-block (src-block contents info
)
3778 "Transcode a SRC-BLOCK element from Org to ODT.
3779 CONTENTS holds the contents of the item. INFO is a plist holding
3780 contextual information."
3781 (let* ((lang (org-element-property :language src-block
))
3782 (caption (org-element-property :caption src-block
))
3783 (short-caption (and (cdr caption
)
3784 (org-export-data (cdr caption
) info
)))
3785 (caption (and (car caption
) (org-export-data (car caption
) info
)))
3786 (label (org-element-property :name src-block
)))
3787 ;; FIXME: Handle caption
3788 ;; caption-str (when caption)
3789 ;; (main (org-export-data (car caption) info))
3790 ;; (secondary (org-export-data (cdr caption) info))
3791 ;; (caption-str (org-e-odt--caption/label-string caption label info))
3792 (let* ((captions (org-e-odt-format-label src-block info
'definition
))
3793 (caption (car captions
)) (short-caption (cdr captions
)))
3795 (and caption
(org-e-odt-format-stylized-paragraph 'listing caption
))
3796 (org-e-odt-format-code src-block info
)))))
3799 ;;;; Statistics Cookie
3801 (defun org-e-odt-statistics-cookie (statistics-cookie contents info
)
3802 "Transcode a STATISTICS-COOKIE object from Org to ODT.
3803 CONTENTS is nil. INFO is a plist holding contextual information."
3804 (let ((cookie-value (org-element-property :value statistics-cookie
)))
3805 (org-e-odt-format-fontify cookie-value
'code
)))
3810 (defun org-e-odt-strike-through (strike-through contents info
)
3811 "Transcode STRIKE-THROUGH from Org to ODT.
3812 CONTENTS is the text with strike-through markup. INFO is a plist
3813 holding contextual information."
3814 (org-e-odt-format-fontify contents
'strike
))
3819 (defun org-e-odt-subscript (subscript contents info
)
3820 "Transcode a SUBSCRIPT object from Org to ODT.
3821 CONTENTS is the contents of the object. INFO is a plist holding
3822 contextual information."
3823 ;; (format (if (= (length contents) 1) "$_%s$" "$_{\\mathrm{%s}}$") contents)
3824 (org-e-odt-format-fontify contents
'subscript
))
3829 (defun org-e-odt-superscript (superscript contents info
)
3830 "Transcode a SUPERSCRIPT object from Org to ODT.
3831 CONTENTS is the contents of the object. INFO is a plist holding
3832 contextual information."
3833 ;; (format (if (= (length contents) 1) "$^%s$" "$^{\\mathrm{%s}}$") contents)
3834 (org-e-odt-format-fontify contents
'superscript
))
3839 (defun org-e-odt-table-style-spec (element info
)
3840 (let* ((table (org-export-get-parent-table element info
))
3841 (table-attributes (org-e-odt-element-attributes table info
))
3842 (table-style (plist-get table-attributes
:style
)))
3843 (assoc table-style org-e-odt-table-styles
)))
3845 (defun org-e-odt-get-table-cell-styles (table-cell info
)
3846 "Retrieve styles applicable to a table cell.
3847 R and C are (zero-based) row and column numbers of the table
3848 cell. STYLE-SPEC is an entry in `org-e-odt-table-styles'
3849 applicable to the current table. It is `nil' if the table is not
3850 associated with any style attributes.
3852 Return a cons of (TABLE-CELL-STYLE-NAME . PARAGRAPH-STYLE-NAME).
3854 When STYLE-SPEC is nil, style the table cell the conventional way
3855 - choose cell borders based on row and column groupings and
3856 choose paragraph alignment based on `org-col-cookies' text
3858 `org-e-odt-get-paragraph-style-cookie-for-table-cell'.
3860 When STYLE-SPEC is non-nil, ignore the above cookie and return
3861 styles congruent with the ODF-1.2 specification."
3862 (let* ((table-cell-address (org-export-table-cell-address table-cell info
))
3863 (r (car table-cell-address
)) (c (cdr table-cell-address
))
3864 (style-spec (org-e-odt-table-style-spec table-cell info
))
3865 (table-dimensions (org-export-table-dimensions
3866 (org-export-get-parent-table table-cell info
)
3869 ;; LibreOffice - particularly the Writer - honors neither table
3870 ;; templates nor custom table-cell styles. Inorder to retain
3871 ;; inter-operability with LibreOffice, only automatic styles are
3872 ;; used for styling of table-cells. The current implementation is
3873 ;; congruent with ODF-1.2 specification and hence is
3874 ;; future-compatible.
3876 ;; Additional Note: LibreOffice's AutoFormat facility for tables -
3877 ;; which recognizes as many as 16 different cell types - is much
3878 ;; richer. Unfortunately it is NOT amenable to easy configuration
3880 (let* ((template-name (nth 1 style-spec
))
3881 (cell-style-selectors (nth 2 style-spec
))
3884 ((and (cdr (assoc 'use-first-column-styles cell-style-selectors
))
3885 (= c
0)) "FirstColumn")
3886 ((and (cdr (assoc 'use-last-column-styles cell-style-selectors
))
3887 (= (1+ c
) (cdr table-dimensions
)))
3889 ((and (cdr (assoc 'use-first-row-styles cell-style-selectors
))
3890 (= r
0)) "FirstRow")
3891 ((and (cdr (assoc 'use-last-row-styles cell-style-selectors
))
3892 (= (1+ r
) (car table-dimensions
)))
3894 ((and (cdr (assoc 'use-banding-rows-styles cell-style-selectors
))
3895 (= (% r
2) 1)) "EvenRow")
3896 ((and (cdr (assoc 'use-banding-rows-styles cell-style-selectors
))
3897 (= (% r
2) 0)) "OddRow")
3898 ((and (cdr (assoc 'use-banding-columns-styles cell-style-selectors
))
3899 (= (% c
2) 1)) "EvenColumn")
3900 ((and (cdr (assoc 'use-banding-columns-styles cell-style-selectors
))
3901 (= (% c
2) 0)) "OddColumn")
3903 (concat template-name cell-type
)))))
3905 (defun org-e-odt-table-cell (table-cell contents info
)
3906 "Transcode a TABLE-CELL element from Org to ODT.
3907 CONTENTS is nil. INFO is a plist used as a communication
3909 (let* ((table-cell-address (org-export-table-cell-address table-cell info
))
3910 (r (car table-cell-address
))
3911 (c (cdr table-cell-address
))
3912 (horiz-span (or (org-export-table-cell-width table-cell info
) 0))
3913 (table-row (org-export-get-parent table-cell info
))
3914 (custom-style-prefix (org-e-odt-get-table-cell-styles
3918 (and custom-style-prefix
3919 (format "%sTableParagraph" custom-style-prefix
))
3922 ((and (= 1 (org-export-table-row-group table-row info
))
3923 (org-export-table-has-header-p
3924 (org-export-get-parent-table table-row info
) info
))
3926 ((let* ((table (org-export-get-parent-table table-cell info
))
3927 (table-attrs (org-e-odt-element-attributes table info
))
3928 (table-header-columns (plist-get table-attrs
3930 (<= c
(cond ((wholenump table-header-columns
)
3931 (- table-header-columns
1))
3932 (table-header-columns 0)
3935 (t "OrgTableContents"))
3936 (capitalize (symbol-name (org-export-table-cell-alignment
3937 table-cell info
))))))
3940 (and custom-style-prefix
(format "%sTableCell"
3941 custom-style-prefix
))
3944 (when (or (org-export-table-row-starts-rowgroup-p table-row info
)
3946 (when (org-export-table-row-ends-rowgroup-p table-row info
) "B")
3947 (when (and (org-export-table-cell-starts-colgroup-p table-cell info
)
3948 (not (zerop c
)) ) "L"))))
3951 (format " table:style-name=\"%s\"" cell-style-name
)
3952 (and (> horiz-span
0)
3953 (format " table:number-columns-spanned=\"%d\""
3954 (1+ horiz-span
))))))
3955 (unless contents
(setq contents
""))
3957 (org-e-odt-format-tags
3958 '("<table:table-cell%s>" .
"</table:table-cell>")
3959 (org-e-odt-format-stylized-paragraph paragraph-style contents
)
3962 (dotimes (i horiz-span s
)
3963 (setq s
(concat s
"\n<table:covered-table-cell/>"))))
3969 (defun org-e-odt-table-row (table-row contents info
)
3970 "Transcode a TABLE-ROW element from Org to ODT.
3971 CONTENTS is the contents of the row. INFO is a plist used as a
3972 communication channel."
3973 ;; Rules are ignored since table separators are deduced from
3974 ;; borders of the current row.
3975 (when (eq (org-element-property :type table-row
) 'standard
)
3976 (let* ((rowgroup-tags
3977 (if (and (= 1 (org-export-table-row-group table-row info
))
3978 (org-export-table-has-header-p
3979 (org-export-get-parent-table table-row info
) info
))
3980 ;; If the row belongs to the first rowgroup and the
3981 ;; table has more than one row groups, then this row
3982 ;; belongs to the header row group.
3983 '("\n<table:table-header-rows>" .
"\n</table:table-header-rows>")
3984 ;; Otherwise, it belongs to non-header row group.
3985 '("\n<table:table-rows>" .
"\n</table:table-rows>"))))
3987 ;; Does this row begin a rowgroup?
3988 (when (org-export-table-row-starts-rowgroup-p table-row info
)
3989 (car rowgroup-tags
))
3991 (org-e-odt-format-tags
3992 '("<table:table-row>" .
"</table:table-row>") contents
)
3993 ;; Does this row end a rowgroup?
3994 (when (org-export-table-row-ends-rowgroup-p table-row info
)
3995 (cdr rowgroup-tags
))))))
4000 (defun org-e-odt-table-first-row-data-cells (table info
)
4005 (unless (eq (org-element-property :type row
) 'rule
) row
))
4007 (special-column-p (org-export-table-has-special-column-p table
)))
4008 (if (not special-column-p
) (org-element-contents table-row
)
4009 (cdr (org-element-contents table-row
)))))
4011 (defun org-e-odt-table (table contents info
)
4012 "Transcode a TABLE element from Org to ODT.
4013 CONTENTS is the contents of the table. INFO is a plist holding
4014 contextual information."
4015 (case (org-element-property :type table
)
4018 (let* ((captions (org-e-odt-format-label table info
'definition
))
4019 (caption (car captions
)) (short-caption (cdr captions
))
4020 (attributes (org-e-odt-element-attributes table info
))
4021 (custom-table-style (nth 1 (org-e-odt-table-style-spec table info
)))
4024 (lambda (table info
)
4025 (let* ((table-style (or custom-table-style
"OrgTable"))
4026 (column-style (format "%sColumn" table-style
)))
4028 (lambda (table-cell)
4029 (let ((width (1+ (or (org-export-table-cell-width
4030 table-cell info
) 0))))
4031 (org-e-odt-make-string
4033 (org-e-odt-format-tags
4034 "<table:table-column table:style-name=\"%s\"/>"
4036 (org-e-odt-table-first-row-data-cells table info
) "\n"))))))
4039 (when caption
(org-e-odt-format-stylized-paragraph 'table caption
))
4041 (let* ((automatic-name
4042 (org-e-odt-add-automatic-style "Table" attributes
)))
4044 "\n<table:table table:name=\"%s\" table:style-name=\"%s\">\n"
4045 (or short-caption
(car automatic-name
))
4046 (or custom-table-style
(cdr automatic-name
) "OrgTable")))
4047 ;; column specification.
4048 (funcall table-column-specs table info
)
4052 "</table:table>")))))
4057 (defun org-e-odt-target (target contents info
)
4058 "Transcode a TARGET object from Org to ODT.
4059 CONTENTS is nil. INFO is a plist holding contextual
4061 (org-e-odt-format-anchor
4062 "" (org-export-solidify-link-text (org-element-property :value target
))))
4067 (defun org-e-odt-timestamp (timestamp contents info
)
4068 "Transcode a TIMESTAMP object from Org to ODT.
4069 CONTENTS is nil. INFO is a plist used as a communication
4071 (org-e-odt-format-fontify
4072 (org-e-odt-format-fontify
4073 (org-translate-time (org-element-property :value timestamp
))
4075 "timestamp-wrapper"))
4080 (defun org-e-odt-underline (underline contents info
)
4081 "Transcode UNDERLINE from Org to ODT.
4082 CONTENTS is the text with underline markup. INFO is a plist
4083 holding contextual information."
4084 (org-e-odt-format-fontify contents
'underline
))
4089 (defun org-e-odt-verbatim (verbatim contents info
)
4090 "Transcode a VERBATIM object from Org to ODT.
4091 CONTENTS is nil. INFO is a plist used as a communication
4093 (org-e-odt-format-fontify (org-element-property :value verbatim
) 'verbatim
))
4098 (defun org-e-odt-verse-block (verse-block contents info
)
4099 "Transcode a VERSE-BLOCK element from Org to ODT.
4100 CONTENTS is verse block contents. INFO is a plist holding
4101 contextual information."
4102 ;; Add line breaks to each line of verse.
4103 (setq contents
(replace-regexp-in-string
4104 "\\(<text:line-break/>\\)?[ \t]*\n"
4105 "<text:line-break/>" contents
))
4106 ;; Replace tabs and spaces.
4107 (setq contents
(org-e-odt-fill-tabs-and-spaces contents
))
4108 ;; Surround it in a verse environment.
4109 (org-e-odt--wrap-label
4110 verse-block
(org-e-odt-format-stylized-paragraph 'verse contents
)))
4115 ;;; Filter Functions
4117 ;;;; Filter Settings
4120 ;;; Interactive functions
4123 (defun org-e-odt-export-to-odt
4124 (&optional subtreep visible-only body-only ext-plist pub-dir
)
4125 "Export current buffer to a HTML file.
4127 If narrowing is active in the current buffer, only export its
4130 If a region is active, export that region.
4132 When optional argument SUBTREEP is non-nil, export the sub-tree
4133 at point, extracting information from the headline properties
4136 When optional argument VISIBLE-ONLY is non-nil, don't export
4137 contents of hidden elements.
4139 When optional argument BODY-ONLY is non-nil, only write code
4140 between \"\\begin{document}\" and \"\\end{document}\".
4142 EXT-PLIST, when provided, is a property list with external
4143 parameters overriding Org default settings, but still inferior to
4144 file-local settings.
4146 When optional argument PUB-DIR is set, use it as the publishing
4149 Return output file's name."
4151 (setq debug-on-error t
)
4153 ;; (let* ((outfile (org-export-output-file-name ".html" subtreep pub-dir))
4154 ;; (outfile "content.xml"))
4155 ;; (org-export-to-file
4156 ;; 'e-odt outfile subtreep visible-only body-only ext-plist))
4158 (let* ((outbuf (org-e-odt-init-outfile))
4159 (target (org-export-output-file-name ".odt" subtreep pub-dir
))
4160 (outdir (file-name-directory (buffer-file-name outbuf
)))
4161 (default-directory outdir
))
4163 ;; FIXME: for copying embedded images
4164 (setq org-current-export-file
4165 (file-name-directory
4166 (org-export-output-file-name ".odt" subtreep nil
)))
4168 (org-export-to-buffer
4170 (memq 'subtree optns
) (memq 'visible optns
) (memq 'body optns
))
4172 (setq org-lparse-opt-plist nil
) ; FIXME
4173 (org-e-odt-save-as-outfile target
;; info
4178 (if (not org-e-odt-preferred-output-format
) target
4179 (or (org-e-odt-convert target org-e-odt-preferred-output-format
)
4186 (defun org-e-odt-reachable-p (in-fmt out-fmt
)
4187 "Return non-nil if IN-FMT can be converted to OUT-FMT."
4189 (let ((reachable-formats (org-e-odt-do-reachable-formats in-fmt
)))
4190 (dolist (e reachable-formats
)
4191 (let ((out-fmt-spec (assoc out-fmt
(cdr e
))))
4193 (throw 'done
(cons (car e
) out-fmt-spec
))))))))
4195 (defun org-e-odt-do-convert (in-file out-fmt
&optional prefix-arg
)
4196 "Workhorse routine for `org-e-odt-convert'."
4197 (require 'browse-url
)
4198 (let* ((in-file (expand-file-name (or in-file buffer-file-name
)))
4199 (dummy (or (file-readable-p in-file
)
4200 (error "Cannot read %s" in-file
)))
4201 (in-fmt (file-name-extension in-file
))
4202 (out-fmt (or out-fmt
(error "Output format unspecified")))
4203 (how (or (org-e-odt-reachable-p in-fmt out-fmt
)
4204 (error "Cannot convert from %s format to %s format?"
4206 (convert-process (car how
))
4207 (out-file (concat (file-name-sans-extension in-file
) "."
4208 (nth 1 (or (cdr how
) out-fmt
))))
4209 (extra-options (or (nth 2 (cdr how
)) ""))
4210 (out-dir (file-name-directory in-file
))
4211 (cmd (format-spec convert-process
4212 `((?i .
,(shell-quote-argument in-file
))
4213 (?I .
,(browse-url-file-url in-file
))
4216 (?O .
,(browse-url-file-url out-file
))
4217 (?d .
, (shell-quote-argument out-dir
))
4218 (?D .
,(browse-url-file-url out-dir
))
4219 (?x .
,extra-options
)))))
4220 (when (file-exists-p out-file
)
4221 (delete-file out-file
))
4223 (message "Executing %s" cmd
)
4224 (let ((cmd-output (shell-command-to-string cmd
)))
4225 (message "%s" cmd-output
))
4228 ((file-exists-p out-file
)
4229 (message "Exported to %s" out-file
)
4231 (message "Opening %s..." out-file
)
4232 (org-open-file out-file
))
4235 (message "Export to %s failed" out-file
)
4238 (defun org-e-odt-do-reachable-formats (in-fmt)
4239 "Return verbose info about formats to which IN-FMT can be converted.
4240 Return a list where each element is of the
4241 form (CONVERTER-PROCESS . OUTPUT-FMT-ALIST). See
4242 `org-e-odt-convert-processes' for CONVERTER-PROCESS and see
4243 `org-e-odt-convert-capabilities' for OUTPUT-FMT-ALIST."
4245 (and org-e-odt-convert-process
4246 (cadr (assoc-string org-e-odt-convert-process
4247 org-e-odt-convert-processes t
))))
4249 (and org-e-odt-convert-process
4250 (cadr (assoc-string org-e-odt-convert-process
4251 org-e-odt-convert-processes t
))
4252 org-e-odt-convert-capabilities
))
4255 (dolist (c capabilities
)
4256 (when (member in-fmt
(nth 1 c
))
4257 (push (cons converter
(nth 2 c
)) reachable-formats
))))
4260 (defun org-e-odt-reachable-formats (in-fmt)
4261 "Return list of formats to which IN-FMT can be converted.
4262 The list of the form (OUTPUT-FMT-1 OUTPUT-FMT-2 ...)."
4264 (mapc (lambda (e) (add-to-list 'l e
))
4265 (apply 'append
(mapcar
4266 (lambda (e) (mapcar 'car
(cdr e
)))
4267 (org-e-odt-do-reachable-formats in-fmt
))))
4270 (defun org-e-odt-convert-read-params ()
4271 "Return IN-FILE and OUT-FMT params for `org-e-odt-do-convert'.
4272 This is a helper routine for interactive use."
4273 (let* ((input (if (featurep 'ido
) 'ido-completing-read
'completing-read
))
4274 (in-file (read-file-name "File to be converted: "
4275 nil buffer-file-name t
))
4276 (in-fmt (file-name-extension in-file
))
4277 (out-fmt-choices (org-e-odt-reachable-formats in-fmt
))
4279 (or (and out-fmt-choices
4280 (funcall input
"Output format: "
4281 out-fmt-choices nil nil nil
))
4283 "No known converter or no known output formats for %s files"
4285 (list in-file out-fmt
)))
4288 (defun org-e-odt-convert (&optional in-file out-fmt prefix-arg
)
4289 "Convert IN-FILE to format OUT-FMT using a command line converter.
4290 IN-FILE is the file to be converted. If unspecified, it defaults
4291 to variable `buffer-file-name'. OUT-FMT is the desired output
4292 format. Use `org-e-odt-convert-process' as the converter.
4293 If PREFIX-ARG is non-nil then the newly converted file is opened
4294 using `org-open-file'."
4296 (append (org-e-odt-convert-read-params) current-prefix-arg
))
4297 (org-e-odt-do-convert in-file out-fmt prefix-arg
))
4299 ;;; FIXMES, TODOS, FOR REVIEW etc
4303 ;; (defun org-e-odt-discontinue-list ()
4304 ;; (let ((stashed-stack org-lparse-list-stack))
4305 ;; (loop for list-type in stashed-stack
4306 ;; do (org-lparse-end-list-item-1 list-type)
4307 ;; (org-lparse-end-list list-type))
4308 ;; (setq org-e-odt-list-stack-stashed stashed-stack)))
4310 ;; (defun org-e-odt-continue-list ()
4311 ;; (setq org-e-odt-list-stack-stashed (nreverse org-e-odt-list-stack-stashed))
4312 ;; (loop for list-type in org-e-odt-list-stack-stashed
4313 ;; do (org-lparse-begin-list list-type)
4314 ;; (org-lparse-begin-list-item list-type)))
4316 ;; FIXME: Begin indented table
4317 ;; (setq org-e-odt-table-indentedp (not (null org-lparse-list-stack)))
4318 ;; (setq org-e-odt-table-indentedp nil) ; FIXME
4319 ;; (when org-e-odt-table-indentedp
4320 ;; ;; Within the Org file, the table is appearing within a list item.
4321 ;; ;; OpenDocument doesn't allow table to appear within list items.
4322 ;; ;; Temporarily terminate the list, emit the table and then
4323 ;; ;; re-continue the list.
4324 ;; (org-e-odt-discontinue-list)
4325 ;; ;; Put the Table in an indented section.
4326 ;; (let ((level (length org-e-odt-list-stack-stashed)))
4327 ;; (org-e-odt-begin-section (format "OrgIndentedSection-Level-%d" level))))
4329 ;; FIXME: End indented table
4330 ;; (when org-e-odt-table-indentedp
4331 ;; (org-e-odt-end-section)
4332 ;; (org-e-odt-continue-list))
4335 ;;;; org-format-table-html
4336 ;;;; org-format-org-table-html
4337 ;;;; org-format-table-table-html
4338 ;;;; org-table-number-fraction
4339 ;;;; org-table-number-regexp
4340 ;;;; org-e-odt-table-caption-above
4343 ;;;; "<span style=\"visibility:hidden;\">%s</span>"
4344 ;;;; Remove display properties
4346 ;;;; org-e-odt-with-timestamp
4347 ;;;; org-e-odt-html-helper-timestamp
4349 ;;;; org-export-as-html-and-open
4350 ;;;; org-export-as-html-batch
4351 ;;;; org-export-as-html-to-buffer
4352 ;;;; org-replace-region-by-html
4353 ;;;; org-export-region-as-html
4354 ;;;; org-export-as-html
4356 ;;;; (org-export-directory :html opt-plist)
4357 ;;;; (plist-get opt-plist :html-extension)
4358 ;;;; org-e-odt-toplevel-hlevel
4359 ;;;; org-e-odt-inline-image-extensions
4360 ;;;; org-e-odt-protect-char-alist
4361 ;;;; org-e-odt-table-use-header-tags-for-first-column
4362 ;;;; org-e-odt-todo-kwd-class-prefix
4363 ;;;; org-e-odt-tag-class-prefix
4364 ;;;; org-e-odt-footnote-separator
4367 ;;; Library Initializations
4371 ;; Let Org open all OpenDocument files using system-registered app
4372 (add-to-list 'org-file-apps
4373 (cons (concat "\\." (car desc
) "\\'") 'system
))
4374 ;; Let Emacs open all OpenDocument files in archive mode
4375 (add-to-list 'auto-mode-alist
4376 (cons (concat "\\." (car desc
) "\\'") 'archive-mode
)))
4377 org-e-odt-file-extensions
)
4379 (defvar org-e-odt-display-outline-level
2)
4380 (defun org-e-odt-enumerate-element (element info
&optional predicate n
)
4381 (let* ((numbered-parent-headline-at-<=-n
4383 (lambda (element n info
)
4384 (loop for x in
(org-export-get-genealogy element info
)
4385 thereis
(and (eq (org-element-type x
) 'headline
)
4386 (<= (org-export-get-relative-level x info
) n
)
4387 (org-export-numbered-headline-p x info
)
4391 (lambda (element scope info
&optional predicate
)
4394 (or scope
(plist-get info
:parse-tree
))
4395 (org-element-type element
)
4397 (and (or (not predicate
) (funcall predicate el info
))
4401 info
'first-match
)))))
4402 (scope (funcall numbered-parent-headline-at-
<=-n
4403 element
(or n org-e-odt-display-outline-level
) info
))
4404 (ordinal (funcall enumerate element scope info predicate
))
4409 (mapconcat 'number-to-string
4410 (org-export-get-headline-number scope info
) "."))
4414 (number-to-string ordinal
))))
4415 ;; (message "%s:\t%s" (org-element-property :name element) tag)
4418 (provide 'org-e-odt
)
4420 ;;; org-e-odt.el ends here