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/>.
31 ;; org-e-odt-preprocess-latex-fragments
32 ;; org-export-as-e-odt-and-open
33 ;; org-export-as-e-odt-batch
34 ;; org-export-as-e-odt
36 (defun org-e-odt-get-style-name-for-entity (category &optional entity
)
37 (let ((entity (or entity
'default
)))
39 (cdr (assoc entity
(cdr (assoc category
40 org-e-odt-org-styles-alist
))))
41 (cdr (assoc entity
(cdr (assoc category
42 org-e-odt-default-org-styles-alist
))))
43 (error "Cannot determine style name for entity %s of type %s"
46 ;; Following variable is let bound when `org-do-lparse' is in
47 ;; progress. See org-html.el.
49 (defun org-e-odt-format-preamble (info)
50 (let* ((title (org-export-secondary-string
51 (plist-get info
:title
) 'e-odt info
))
52 (author (and (plist-get info
:with-author
)
53 (let ((auth (plist-get info
:author
)))
54 (and auth
(org-export-secondary-string
56 (date (plist-get info
:date
))
57 (iso-date (org-e-odt-format-date date
))
58 (date (org-e-odt-format-date date
"%d %b %Y"))
59 (email (plist-get info
:email
))
60 ;; switch on or off above vars based on user settings
61 (author (and (plist-get info
:with-author
) (or author email
)))
62 ;; (date (and (plist-get info :time-stamp-file) date))
63 (email (and (plist-get info
:with-email
) email
)))
68 (org-e-odt-format-stylized-paragraph
69 'title
(format "\n<text:title>%s</text:title>" title
))
71 "\n<text:p text:style-name=\"OrgTitle\"/>"))
73 ((and author
(not email
))
76 (org-e-odt-format-stylized-paragraph
78 (format "<text:initial-creator>%s</text:initial-creator>" author
))
80 "\n<text:p text:style-name=\"OrgSubtitle\"/>"))
84 (org-e-odt-format-stylized-paragraph
86 (org-e-odt-format-link
87 (format "<text:initial-creator>%s</text:initial-creator>" author
)
88 (concat "mailto:" email
)))
90 "\n<text:p text:style-name=\"OrgSubtitle\"/>")))
94 (org-e-odt-format-stylized-paragraph
96 (org-e-odt-format-tags
97 '("<text:date style:data-style-name=\"%s\" text:date-value=\"%s\">"
101 "<text:p text:style-name=\"OrgSubtitle\"/>")))))
103 (defun org-e-odt-begin-section (style &optional name
)
104 (let ((default-name (car (org-e-odt-add-automatic-style "Section"))))
105 (format "<text:section text:style-name=\"%s\" text:name=\"%s\">"
106 style
(or name default-name
))))
108 (defun org-e-odt-end-section ()
111 (defun org-e-odt-begin-paragraph (&optional style
)
112 (format "<text:p%s>" (org-e-odt-get-extra-attrs-for-paragraph-style style
)))
114 (defun org-e-odt-end-paragraph ()
117 (defun org-e-odt-get-extra-attrs-for-paragraph-style (style)
121 ((stringp style
) style
)
122 ((symbolp style
) (org-e-odt-get-style-name-for-entity
125 (error "Don't know how to handle paragraph style %s" style
))
126 (format " text:style-name=\"%s\"" style-name
)))
128 (defun org-e-odt-format-stylized-paragraph (style text
)
129 (format "\n<text:p%s>%s</text:p>"
130 (org-e-odt-get-extra-attrs-for-paragraph-style style
)
133 (defun org-e-odt-format-author (&optional author
)
134 (when (setq author
(or author
(plist-get org-lparse-opt-plist
:author
)))
135 (format "<dc:creator>%s</dc:creator>" author
)))
137 (defun org-e-odt-format-date (&optional org-ts fmt
)
140 (and (stringp org-ts
)
141 (string-match org-ts-regexp0 org-ts
)
143 (org-fix-decoded-time
144 (org-parse-time-string (match-string 0 org-ts
) t
)))))
147 (fmt (format-time-string fmt time
))
148 (t (setq date
(format-time-string "%Y-%m-%dT%H:%M:%S%z" time
))
149 (format "%s:%s" (substring date
0 -
2) (substring date -
2)))))))
151 (defun org-e-odt-begin-annotation (&optional author date
)
153 "<office:annotation>\n"
154 (and author
(org-e-odt-format-author author
))
155 (org-e-odt-format-tags
156 '("<dc:date>" .
"</dc:date>")
157 (org-e-odt-format-date
158 (or date
(plist-get org-lparse-opt-plist
:date
))))
159 (org-e-odt-begin-paragraph)))
161 (defun org-e-odt-end-annotation ()
162 "</office:annotation>")
164 (defun org-e-odt-begin-plain-list (ltype)
165 (let* ((style-name (org-e-odt-get-style-name-for-entity 'list ltype
))
167 ;; (if (or org-lparse-list-table-p
168 ;; (and (= 1 (length org-lparse-list-stack))
169 ;; (null org-e-odt-list-stack-stashed)))
170 ;; " text:continue-numbering=\"false\""
171 ;; " text:continue-numbering=\"true\"")
173 " text:continue-numbering=\"true\""
176 (format " text:style-name=\"%s\"" style-name
)))))
178 ((ordered unordered descriptive
)
180 ;; (org-e-odt-end-paragraph)
181 (format "<text:list%s>" extra
)))
182 (t (error "Unknown list type: %s" ltype
)))))
184 (defun org-e-odt-end-plain-list (ltype)
185 (if ltype
"</text:list>"
186 (error "Unknown list type: %s" ltype
)))
188 (defun org-e-odt-begin-list-item (ltype &optional arg headline
)
191 (assert (not headline
) t
)
192 (let* ((counter arg
) (extra ""))
193 (concat "<text:list-item>" ;; (org-e-odt-begin-paragraph)
195 ;; (if (= (length org-lparse-list-stack)
196 ;; (length org-e-odt-list-stack-stashed))
197 ;; "<text:list-header>" "<text:list-item>")
200 (let* ((id arg
) (extra ""))
203 ;; (org-e-odt-begin-paragraph)
204 (if headline
(org-e-odt-format-target headline id
)
205 (org-e-odt-format-bookmark "" id
)))
206 ;; (if (= (length org-lparse-list-stack)
207 ;; (length org-e-odt-list-stack-stashed))
208 ;; "<text:list-header>" "<text:list-item>")
211 (assert (not headline
) t
)
212 (let ((term (or arg
"(no term)")))
214 (org-e-odt-format-tags
215 '("<text:list-item>" .
"</text:list-item>")
216 (org-e-odt-format-stylized-paragraph 'definition-term term
))
217 (org-e-odt-begin-list-item 'unordered
)
218 (org-e-odt-begin-plain-list 'descriptive
)
219 (org-e-odt-begin-list-item 'unordered
))))
220 (t (error "Unknown list type"))))
222 (defun org-e-odt-end-list-item (ltype)
225 ;; (org-lparse-insert-tag
226 ;; (if (= (length org-lparse-list-stack)
227 ;; (length org-e-odt-list-stack-stashed))
228 ;; (prog1 "</text:list-header>"
229 ;; (setq org-e-odt-list-stack-stashed nil))
230 ;; "</text:list-item>")
236 (org-e-odt-end-list-item 'unordered
)
237 (org-e-odt-end-plain-list 'descriptive
)
238 (org-e-odt-end-list-item 'unordered
)
240 (t (error "Unknown list type"))))
242 (defun org-e-odt-discontinue-list ()
243 (let ((stashed-stack org-lparse-list-stack
))
244 (loop for list-type in stashed-stack
245 do
(org-lparse-end-list-item-1 list-type
)
246 (org-lparse-end-list list-type
))
247 (setq org-e-odt-list-stack-stashed stashed-stack
)))
249 (defun org-e-odt-continue-list ()
250 (setq org-e-odt-list-stack-stashed
(nreverse org-e-odt-list-stack-stashed
))
251 (loop for list-type in org-e-odt-list-stack-stashed
252 do
(org-lparse-begin-list list-type
)
253 (org-lparse-begin-list-item list-type
)))
255 (defun org-e-odt-write-automatic-styles ()
256 "Write automatic styles to \"content.xml\"."
258 (find-file-noselect (expand-file-name "content.xml") t
)
259 ;; position the cursor
260 (goto-char (point-min))
261 (re-search-forward " </office:automatic-styles>" nil t
)
262 (goto-char (match-beginning 0))
263 ;; write automatic table styles
264 (loop for
(style-name props
) in
265 (plist-get org-e-odt-automatic-styles
'Table
) do
266 (when (setq props
(or (plist-get props
:rel-width
) 96))
267 (insert (format org-e-odt-table-style-format style-name props
))))))
269 (defun org-e-odt-add-automatic-style (object-type &optional object-props
)
270 "Create an automatic style of type OBJECT-TYPE with param OBJECT-PROPS.
271 OBJECT-PROPS is (typically) a plist created by passing
272 \"#+ATTR_ODT: \" option of the object in question to
273 `org-e-odt-parse-block-attributes'.
275 Use `org-e-odt-object-counters' to generate an automatic
276 OBJECT-NAME and STYLE-NAME. If OBJECT-PROPS is non-nil, add a
277 new entry in `org-e-odt-automatic-styles'. Return (OBJECT-NAME
279 (assert (stringp object-type
))
280 (let* ((object (intern object-type
))
282 (seqno (1+ (or (plist-get org-e-odt-object-counters seqvar
) 0)))
283 (object-name (format "%s%d" object-type seqno
)) style-name
)
284 (setq org-e-odt-object-counters
285 (plist-put org-e-odt-object-counters seqvar seqno
))
287 (setq style-name
(format "Org%s" object-name
))
288 (setq org-e-odt-automatic-styles
289 (plist-put org-e-odt-automatic-styles object
290 (append (list (list style-name object-props
))
291 (plist-get org-e-odt-automatic-styles object
)))))
292 (cons object-name style-name
)))
294 (defun org-e-odt-format-table-columns ()
295 (let* ((num-cols (length (plist-get table-info
:alignment
)))
296 (col-nos (loop for i from
0 below num-cols collect i
))
298 (col-widths (plist-get table-info
:width
))
299 (style (or (nth 1 org-e-odt-table-style-spec
) "OrgTable")))
302 (let* ((width (or (and org-lparse-table-is-styled
(aref col-widths c
))
304 (org-e-odt-make-string
306 (org-e-odt-format-tags
307 "<table:table-column table:style-name=\"%sColumn\"/>" "" style
))))
310 (defun org-e-odt-begin-table (caption-from info
)
311 (let* ((captions (org-e-odt-format-label caption-from info
'definition
))
312 (caption (car captions
)) (short-caption (cdr captions
))
313 (attributes (mapconcat #'identity
314 (org-element-property :attr_odt caption-from
)
316 (attributes (org-e-odt-parse-block-attributes attributes
)))
317 ;; (setq org-e-odt-table-indentedp (not (null org-lparse-list-stack)))
318 (setq org-e-odt-table-indentedp nil
) ; FIXME
319 (when org-e-odt-table-indentedp
320 ;; Within the Org file, the table is appearing within a list item.
321 ;; OpenDocument doesn't allow table to appear within list items.
322 ;; Temporarily terminate the list, emit the table and then
323 ;; re-continue the list.
324 (org-e-odt-discontinue-list)
325 ;; Put the Table in an indented section.
326 (let ((level (length org-e-odt-list-stack-stashed
)))
327 (org-e-odt-begin-section (format "OrgIndentedSection-Level-%d" level
))))
328 (setq org-e-odt-table-style
(plist-get attributes
:style
))
329 (setq org-e-odt-table-style-spec
330 (assoc org-e-odt-table-style org-e-odt-table-styles
))
332 (and caption
(org-e-odt-format-stylized-paragraph 'table caption
))
333 (let ((automatic-name (org-e-odt-add-automatic-style "Table" attributes
)))
335 "\n<table:table table:name=\"%s\" table:style-name=\"%s\">\n"
336 (or short-caption
(car automatic-name
))
337 (or (nth 1 org-e-odt-table-style-spec
) (cdr automatic-name
) "OrgTable")))
338 (org-e-odt-format-table-columns) "\n")))
340 (defun org-e-odt-end-table ()
343 ;; (when org-e-odt-table-indentedp
344 ;; (org-e-odt-end-section)
345 ;; (org-e-odt-continue-list))
348 (defun org-e-odt-begin-table-rowgroup (&optional is-header-row
)
350 (concat (when org-e-odt-table-rowgrp-open
351 (org-e-odt-end-table-rowgroup))
352 (if is-header-row
"<table:table-header-rows>"
353 "<table:table-rows>"))
354 (setq org-e-odt-table-rowgrp-open t
)
355 (setq org-e-odt-table-cur-rowgrp-is-hdr is-header-row
)))
357 (defun org-e-odt-end-table-rowgroup ()
358 (when org-e-odt-table-rowgrp-open
359 (setq org-e-odt-table-rowgrp-open nil
)
360 (if org-e-odt-table-cur-rowgrp-is-hdr
361 "</table:table-header-rows>" "</table:table-rows>")))
363 (defun org-e-odt-format-table-row (row)
364 (org-e-odt-format-tags
365 '("<table:table-row>" .
"</table:table-row>") row
))
367 (defun org-e-odt-get-column-alignment (c)
368 (let ((colalign-vector (plist-get table-info
:alignment
)))
370 (assoc-default (aref colalign-vector c
)
375 (defun org-e-odt-get-table-cell-styles (r c
&optional style-spec
)
376 "Retrieve styles applicable to a table cell.
377 R and C are (zero-based) row and column numbers of the table
378 cell. STYLE-SPEC is an entry in `org-e-odt-table-styles'
379 applicable to the current table. It is `nil' if the table is not
380 associated with any style attributes.
382 Return a cons of (TABLE-CELL-STYLE-NAME . PARAGRAPH-STYLE-NAME).
384 When STYLE-SPEC is nil, style the table cell the conventional way
385 - choose cell borders based on row and column groupings and
386 choose paragraph alignment based on `org-col-cookies' text
388 `org-e-odt-get-paragraph-style-cookie-for-table-cell'.
390 When STYLE-SPEC is non-nil, ignore the above cookie and return
391 styles congruent with the ODF-1.2 specification."
395 ;; LibreOffice - particularly the Writer - honors neither table
396 ;; templates nor custom table-cell styles. Inorder to retain
397 ;; inter-operability with LibreOffice, only automatic styles are
398 ;; used for styling of table-cells. The current implementation is
399 ;; congruent with ODF-1.2 specification and hence is
400 ;; future-compatible.
402 ;; Additional Note: LibreOffice's AutoFormat facility for tables -
403 ;; which recognizes as many as 16 different cell types - is much
404 ;; richer. Unfortunately it is NOT amenable to easy configuration
407 (let* ((template-name (nth 1 style-spec
))
408 (cell-style-selectors (nth 2 style-spec
))
411 ((and (cdr (assoc 'use-first-column-styles cell-style-selectors
))
412 (= c
0)) "FirstColumn")
413 ((and (cdr (assoc 'use-last-column-styles cell-style-selectors
))
414 (= c
(1- org-lparse-table-ncols
))) "LastColumn")
415 ((and (cdr (assoc 'use-first-row-styles cell-style-selectors
))
417 ((and (cdr (assoc 'use-last-row-styles cell-style-selectors
))
418 (= r org-e-odt-table-rownum
))
420 ((and (cdr (assoc 'use-banding-rows-styles cell-style-selectors
))
421 (= (% r
2) 1)) "EvenRow")
422 ((and (cdr (assoc 'use-banding-rows-styles cell-style-selectors
))
423 (= (% r
2) 0)) "OddRow")
424 ((and (cdr (assoc 'use-banding-columns-styles cell-style-selectors
))
425 (= (% c
2) 1)) "EvenColumn")
426 ((and (cdr (assoc 'use-banding-columns-styles cell-style-selectors
))
427 (= (% c
2) 0)) "OddColumn")
430 (concat template-name cell-type
"TableCell")
431 (concat template-name cell-type
"TableParagraph"))))
438 ((eq (cdr (assoc r nil
;; org-lparse-table-rowgrp-info FIXME
441 (when (= r org-e-odt-table-rownum
) "B")
444 ((or (memq (nth c org-table-colgroup-info
) '(:start
:startend
))
445 (memq (nth (1- c
) org-table-colgroup-info
) '(:end
:startend
))) "L")
447 (capitalize (org-e-odt-get-column-alignment c
))))))
449 (defun org-e-odt-get-paragraph-style-cookie-for-table-cell (r c
)
451 (and (not org-e-odt-table-style-spec
)
453 (org-e-odt-table-cur-rowgrp-is-hdr "OrgTableHeading")
455 ;; (org-lparse-get 'TABLE-FIRST-COLUMN-AS-LABELS)
458 (t "OrgTableContents")))
459 (and org-lparse-table-is-styled
460 (cdr (org-e-odt-get-table-cell-styles
461 r c org-e-odt-table-style-spec
)))))
463 (defun org-e-odt-get-style-name-cookie-for-table-cell (r c
)
464 (when org-lparse-table-is-styled
465 (let* ((cell-styles (org-e-odt-get-table-cell-styles
466 r c org-e-odt-table-style-spec
))
467 (table-cell-style (car cell-styles
)))
470 (defun org-e-odt-format-table-cell (data r c horiz-span
)
472 (let* ((paragraph-style-cookie
473 (org-e-odt-get-paragraph-style-cookie-for-table-cell r c
))
475 (org-e-odt-get-style-name-cookie-for-table-cell r c
))
476 (extra (and style-name-cookie
477 (format " table:style-name=\"%s\"" style-name-cookie
)))
479 (and (> horiz-span
0)
480 (format " table:number-columns-spanned=\"%d\""
482 (org-e-odt-format-tags
483 '("<table:table-cell%s>" .
"</table:table-cell>")
484 (if org-lparse-list-table-p data
485 (org-e-odt-format-stylized-paragraph paragraph-style-cookie data
)) extra
))
487 (dotimes (i horiz-span
)
488 (setq s
(concat s
"\n<table:covered-table-cell/>"))) s
)
491 (defun org-e-odt-begin-toc (lang-specific-heading max-level
)
494 <text:table-of-content text:style-name=\"Sect2\" text:protected=\"true\" text:name=\"Table of Contents1\">
495 <text:table-of-content-source text:outline-level=\"%d\">
496 <text:index-title-template text:style-name=\"Contents_20_Heading\">%s</text:index-title-template>
497 " max-level lang-specific-heading
)
499 (let ((entry-templates ""))
500 (loop for level from
1 upto
10
501 do
(setq entry-templates
502 (concat entry-templates
505 <text:table-of-content-entry-template text:outline-level=\"%d\" text:style-name=\"Contents_20_%d\">
506 <text:index-entry-link-start text:style-name=\"Internet_20_link\"/>
507 <text:index-entry-chapter/>
508 <text:index-entry-text/>
509 <text:index-entry-link-end/>
510 </text:table-of-content-entry-template>
515 </text:table-of-content-source>
518 <text:index-title text:style-name=\"Sect1\" text:name=\"Table of Contents1_Head\">
519 <text:p text:style-name=\"Contents_20_Heading\">%s</text:p>
521 " lang-specific-heading
)))
523 (defun org-e-odt-end-toc ()
526 </text:table-of-content>
529 (defun org-e-odt-format-toc-entry (snumber todo headline tags href
)
532 (setq headline
(concat
533 (and org-export-with-section-numbers
534 (concat snumber
". "))
538 (org-e-odt-format-spaces 3)
539 (org-e-odt-format-fontify tags
"tag")))))
541 (setq headline
(org-e-odt-format-fontify headline
"todo")))
543 (let ((org-e-odt-suppress-xref t
))
544 (org-e-odt-format-link headline
(concat "#" href
))))
546 (defun org-e-odt-format-toc-item (toc-entry level org-last-level
)
547 (let ((style (format "Contents_20_%d" level
)))
548 (concat "\n" (org-e-odt-format-stylized-paragraph style toc-entry
) "\n")))
550 ;; Following variable is let bound during 'ORG-LINK callback. See
553 (defun org-e-odt-format-link (desc href
&optional attr
)
555 ((and (= (string-to-char href
) ?
#) (not org-e-odt-suppress-xref
))
556 (setq href
(substring href
1))
557 (let ((xref-format "text"))
559 (setq desc
(format "%d" desc
) xref-format
"number"))
561 (setq desc
(mapconcat 'identity desc
".") xref-format
"chapter"))
562 (setq href
(concat org-e-odt-bookmark-prefix href
))
563 (org-e-odt-format-tags-simple
564 '("<text:bookmark-ref text:reference-format=\"%s\" text:ref-name=\"%s\">" .
565 "</text:bookmark-ref>")
566 desc xref-format href
)))
567 (org-lparse-link-description-is-image
568 (org-e-odt-format-tags
569 '("<draw:a xlink:type=\"simple\" xlink:href=\"%s\" %s>" .
"</draw:a>")
570 desc href
(or attr
"")))
572 (org-e-odt-format-tags-simple
573 '("<text:a xlink:type=\"simple\" xlink:href=\"%s\" %s>" .
"</text:a>")
574 desc href
(or attr
"")))))
576 (defun org-e-odt-format-spaces (n)
580 " " (org-e-odt-format-tags "<text:s text:c=\"%d\"/>" "" (1- n
))))
583 (defun org-e-odt-format-tabs (&optional n
)
584 (let ((tab "<text:tab/>")
588 (defun org-e-odt-format-line-break ()
589 (org-e-odt-format-tags "<text:line-break/>" ""))
591 (defun org-e-odt-format-horizontal-line ()
592 (org-e-odt-format-stylized-paragraph 'horizontal-line
""))
594 (defun org-e-odt-encode-plain-text (line &optional no-whitespace-filling
)
595 (setq line
(org-e-html-encode-plain-text line
))
596 (if no-whitespace-filling line
597 (org-e-odt-fill-tabs-and-spaces line
)))
599 (defun org-e-odt-format-line (line)
600 (case org-lparse-dyn-current-environment
602 (org-e-odt-format-stylized-paragraph
603 'fixedwidth
(org-e-odt-encode-plain-text line
)) "\n"))
604 (t (concat line
"\n"))))
606 (defun org-e-odt-format-comment (fmt &rest args
)
607 (let ((comment (apply 'format fmt args
)))
608 (format "\n<!-- %s -->\n" comment
)))
610 (defun org-e-odt-format-org-entity (wd)
611 (org-entity-get-representation wd
'utf8
))
613 (defun org-e-odt-fill-tabs-and-spaces (line)
614 (replace-regexp-in-string
615 "\\([\t]\\|\\([ ]+\\)\\)" (lambda (s)
617 ((string= s
"\t") (org-e-odt-format-tabs))
618 (t (org-e-odt-format-spaces (length s
))))) line
))
620 (defun org-e-odt-hfy-face-to-css (fn)
621 "Create custom style for face FN.
622 When FN is the default face, use it's foreground and background
623 properties to create \"OrgSrcBlock\" paragraph style. Otherwise
624 use it's color attribute to create a character style whose name
625 is obtained from FN. Currently all attributes of FN other than
628 The style name for a face FN is derived using the following
629 operations on the face name in that order - de-dash, CamelCase
630 and prefix with \"OrgSrc\". For example,
631 `font-lock-function-name-face' is associated with
632 \"OrgSrcFontLockFunctionNameFace\"."
633 (let* ((css-list (hfy-face-to-style fn
))
634 (style-name ((lambda (fn)
637 'capitalize
(split-string
638 (hfy-face-or-def-to-name fn
) "-")
640 (color-val (cdr (assoc "color" css-list
)))
641 (background-color-val (cdr (assoc "background" css-list
)))
642 (style (and org-e-odt-create-custom-styles-for-srcblocks
645 (format org-src-block-paragraph-format
646 background-color-val color-val
))
650 <style:style style:name=\"%s\" style:family=\"text\">
651 <style:text-properties fo:color=\"%s\"/>
652 </style:style>" style-name color-val
))))))
653 (cons style-name style
)))
655 (defun org-e-odt-insert-custom-styles-for-srcblocks (styles)
656 "Save STYLES used for colorizing of source blocks.
657 Update styles.xml with styles that were collected as part of
658 `org-e-odt-hfy-face-to-css' callbacks."
661 (find-file-noselect (expand-file-name "styles.xml") t
)
662 (goto-char (point-min))
663 (when (re-search-forward "</office:styles>" nil t
)
664 (goto-char (match-beginning 0))
665 (insert "\n<!-- Org Htmlfontify Styles -->\n" styles
"\n")))))
667 (defun org-e-odt-remap-stylenames (style-name)
669 (cdr (assoc style-name
'(("timestamp-wrapper" .
"OrgTimestampWrapper")
670 ("timestamp" .
"OrgTimestamp")
671 ("timestamp-kwd" .
"OrgTimestampKeyword")
675 ("target" .
"OrgTarget"))))
678 (defun org-e-odt-format-fontify (text style
&optional id
)
682 (org-e-odt-remap-stylenames style
))
684 (org-e-odt-get-style-name-for-entity 'character style
))
686 (assert (< 1 (length style
)))
687 (let ((parent-style (pop style
)))
688 (mapconcat (lambda (s)
689 ;; (assert (stringp s) t)
690 (org-e-odt-remap-stylenames s
)) style
"")
691 (org-e-odt-remap-stylenames parent-style
)))
692 (t (error "Don't how to handle style %s" style
)))))
693 (org-e-odt-format-tags-simple
694 '("<text:span text:style-name=\"%s\">" .
"</text:span>")
697 (defun org-e-odt-relocate-relative-path (path dir
)
698 (if (file-name-absolute-p path
) path
699 (file-relative-name (expand-file-name path dir
)
700 (expand-file-name "eyecandy" dir
))))
702 (defun org-e-odt-format-formula (element info
)
704 ((eq (org-element-type element
) 'link
) ; FIXME
705 (let* ((type (org-element-property :type element
))
706 (raw-path (org-element-property :path element
)))
708 ((file-name-absolute-p raw-path
)
709 (expand-file-name raw-path
))
711 ((member (org-element-type element
)
712 '(latex-fragment latex-environment
))
713 (let* ((latex-frag (org-remove-indentation
714 (org-element-property
716 (formula-link (org-e-odt-format-latex
717 latex-frag
'mathml
)))
719 (string-match "file:\\([^]]*\\)" formula-link
)
720 (match-string 1 formula-link
))))
721 (t (error "what is this?"))))
723 (case (org-element-type element
)
724 (link (org-export-get-parent-paragraph element info
))
726 (captions (org-e-odt-format-label caption-from info
'definition
))
727 (caption (car captions
))
729 (org-e-odt-format-tags
730 "<draw:object xlink:href=\"%s\" xlink:type=\"simple\" xlink:show=\"embed\" xlink:actuate=\"onLoad\"/>" ""
731 (file-name-directory (org-e-odt-copy-formula-file src
))))
732 (embed-as (if caption
'paragraph
'character
))
735 ((eq embed-as
'character
)
736 (org-e-odt-format-entity "InlineFormula" href width height
))
738 (let ((table-info nil
)
740 '(:alignment
["c" "c"]
741 :column-groups
[nil nil
]
743 :special-column-p nil
:width
[8 1]))
744 (org-lparse-table-ncols 2)) ; FIXME
745 (org-e-odt-list-table
748 (org-e-odt-format-entity
749 "CaptionedDisplayFormula" href width height captions
)
750 (let* ((org-e-odt-category-map-alist
751 '(("__Table__" "Table" "value")
752 ("__Figure__" "Illustration" "value")
753 ("__MathFormula__" "Text" "math-label")
754 ("__DvipngImage__" "Equation" "value")
755 ("__Listing__" "Listing" "value"))))
756 (car (org-e-odt-format-label caption-from info
'definition
)))))
757 '(table (:attr_odt
(":style \"OrgEquation\""))) info
))))))
759 (defun org-e-odt-copy-formula-file (path)
760 "Returns the internal name of the file"
761 (let* ((src-file (expand-file-name
762 path
(file-name-directory org-current-export-file
)))
763 (target-dir (format "Formula-%04d/"
764 (incf org-e-odt-embedded-formulas-count
)))
765 (target-file (concat target-dir
"content.xml")))
766 (message "Embedding %s as %s ..."
767 (substring-no-properties path
) target-file
)
769 (make-directory target-dir
)
770 (org-e-odt-create-manifest-file-entry
771 "application/vnd.oasis.opendocument.formula" target-dir
"1.2")
773 (case (org-e-odt-is-formula-link-p src-file
)
775 (copy-file src-file target-file
'overwrite
))
777 (org-e-odt-zip-extract-one src-file
"content.xml" target-dir
))
779 (error "%s is not a formula file" src-file
)))
781 (org-e-odt-create-manifest-file-entry "text/xml" target-file
)
784 (defun org-e-odt-is-formula-link-p (file)
785 (let ((case-fold-search nil
))
787 ((string-match "\\.\\(mathml\\|mml\\)\\'" file
)
789 ((string-match "\\.odf\\'" file
)
792 (defun org-e-odt-format-org-link (opt-plist type-1 path fragment desc attr
794 "Make a OpenDocument link.
795 OPT-PLIST is an options list.
796 TYPE-1 is the device-type of the link (THIS://foo.html).
797 PATH is the path of the link (http://THIS#location).
798 FRAGMENT is the fragment part of the link, if any (foo.html#THIS).
799 DESC is the link description, if any.
800 ATTR is a string of other attributes of the a element."
801 (declare (special org-lparse-par-open
))
804 (and (member type-1
'("http" "https" "file"))
805 (org-lparse-should-inline-p path descp
)
807 (type (if (equal type-1
"id") "file" type-1
))
811 ;; check for inlined images
812 ((and (member type
'("file"))
815 filename org-e-odt-inline-image-extensions
)
817 (org-e-odt-format-inline-image thefile
))
818 ;; check for embedded formulas
819 ((and (member type
'("file"))
821 (org-e-odt-is-formula-link-p filename
)
823 (org-e-odt-format-formula thefile
))
824 ((string= type
"coderef")
825 (let* ((ref fragment
)
826 (lineno-or-ref (cdr (assoc ref org-export-code-refs
)))
827 (desc (and descp desc
))
828 (org-e-odt-suppress-xref nil
)
829 (href (org-xml-format-href (concat "#coderef-" ref
))))
831 ((and (numberp lineno-or-ref
) (not desc
))
832 (org-e-odt-format-link lineno-or-ref href
))
833 ((and (numberp lineno-or-ref
) desc
834 (string-match (regexp-quote (concat "(" ref
")")) desc
))
835 (format (replace-match "%s" t t desc
)
836 (org-e-odt-format-link lineno-or-ref href
)))
839 (if (and desc
(string-match
840 (regexp-quote (concat "(" ref
")"))
842 (replace-match "%s" t t desc
)
845 (org-e-odt-format-link (org-xml-format-desc desc
) href
)))))
847 (when (string= type
"file")
850 ((file-name-absolute-p path
)
851 (concat "file://" (expand-file-name path
)))
852 (t (org-e-odt-relocate-relative-path
853 thefile org-current-export-file
)))))
855 (when (and (member type
'("" "http" "https" "file")) fragment
)
856 (setq thefile
(concat thefile
"#" fragment
)))
858 (setq thefile
(org-xml-format-href thefile
))
860 (when (not (member type
'("" "file")))
861 (setq thefile
(concat type
":" thefile
)))
863 (let ((org-e-odt-suppress-xref nil
))
864 (org-e-odt-format-link
865 (org-xml-format-desc desc
) thefile attr
)))))))
867 (defun org-e-odt-format-anchor (text name
&optional class
)
868 (org-e-odt-format-target text name
))
870 (defun org-e-odt-format-bookmark (text id
)
872 (org-e-odt-format-tags "<text:bookmark text:name=\"%s\"/>" text id
)
875 (defun org-e-odt-format-target (text id
)
876 (let ((name (concat org-e-odt-bookmark-prefix id
)))
878 (and id
(org-e-odt-format-tags
879 "<text:bookmark-start text:name=\"%s\"/>" "" name
))
880 (org-e-odt-format-bookmark text id
)
881 (and id
(org-e-odt-format-tags
882 "<text:bookmark-end text:name=\"%s\"/>" "" name
)))))
884 (defun org-e-odt-format-footnote (n def
)
885 (setq n
(format "%d" n
))
886 (let ((id (concat "fn" n
))
887 (note-class "footnote")
888 (par-style "Footnote"))
889 (org-e-odt-format-tags-simple
890 '("<text:note text:id=\"%s\" text:note-class=\"%s\">" .
"</text:note>")
892 (org-e-odt-format-tags-simple
893 '("<text:note-citation>" .
"</text:note-citation>") n
)
894 (org-e-odt-format-tags-simple
895 '("<text:note-body>" .
"</text:note-body>") def
))
898 (defun org-e-odt-format-footnote-reference (n def refcnt
)
900 (org-e-odt-format-footnote n def
)
901 (org-e-odt-format-footnote-ref n
)))
903 (defun org-e-odt-format-footnote-ref (n)
904 (setq n
(format "%d" n
))
905 (let ((note-class "footnote")
907 (ref-name (concat "fn" n
)))
908 (org-e-odt-format-tags-simple
909 '("<text:span text:style-name=\"%s\">" .
"</text:span>")
910 (org-e-odt-format-tags-simple
911 '("<text:note-ref text:note-class=\"%s\" text:reference-format=\"%s\" text:ref-name=\"%s\">" .
"</text:note-ref>")
912 n note-class ref-format ref-name
)
915 (defun org-e-odt-parse-block-attributes (params)
918 (setq params
(org-trim params
))
919 (unless (string-match "\\`(.*)\\'" params
)
920 (setq params
(format "(%s)" params
)))
921 (ignore-errors (read params
)))))
923 (defun org-e-odt-format-object-description (title description
)
924 (concat (and title
(org-e-odt-format-tags
925 '("<svg:title>" .
"</svg:title>")
926 (org-e-odt-encode-plain-text title t
)))
927 (and description
(org-e-odt-format-tags
928 '("<svg:desc>" .
"</svg:desc>")
929 (org-e-odt-encode-plain-text description t
)))))
931 (defun org-e-odt-format-frame (text width height style
&optional
935 (if width
(format " svg:width=\"%0.2fcm\"" width
) "")
936 (if height
(format " svg:height=\"%0.2fcm\"" height
) "")
938 (format " text:anchor-type=\"%s\"" (or anchor-type
"paragraph")))))
939 (org-e-odt-format-tags
940 '("<draw:frame draw:style-name=\"%s\"%s>" .
"</draw:frame>")
941 (concat text
(org-e-odt-format-object-description
942 (get-text-property 0 :title text
)
943 (get-text-property 0 :description text
)))
946 (defun org-e-odt-format-textbox (text width height style
&optional
948 (org-e-odt-format-frame
949 (org-e-odt-format-tags
950 '("<draw:text-box %s>" .
"</draw:text-box>")
951 text
(concat (format " fo:min-height=\"%0.2fcm\"" (or height
.2))
953 (format " fo:min-width=\"%0.2fcm\"" (or width
.2)))))
954 width nil style extra anchor-type
))
956 (defun org-e-odt-merge-frame-params(default-frame-params user-frame-params
)
957 (if (not user-frame-params
) default-frame-params
958 (assert (= (length default-frame-params
) 3))
959 (assert (= (length user-frame-params
) 3))
960 (loop for user-frame-param in user-frame-params
961 for default-frame-param in default-frame-params
962 collect
(or user-frame-param default-frame-param
))))
964 (defun org-e-odt-copy-image-file (path)
965 "Returns the internal name of the file"
966 (let* ((image-type (file-name-extension path
))
967 (media-type (format "image/%s" image-type
))
968 (src-file (expand-file-name
969 path
(file-name-directory org-current-export-file
)))
970 (target-dir "Images/")
972 (format "%s%04d.%s" target-dir
973 (incf org-e-odt-embedded-images-count
) image-type
)))
974 (message "Embedding %s as %s ..."
975 (substring-no-properties path
) target-file
)
977 (when (= 1 org-e-odt-embedded-images-count
)
978 (make-directory target-dir
)
979 (org-e-odt-create-manifest-file-entry "" target-dir
))
981 (copy-file src-file target-file
'overwrite
)
982 (org-e-odt-create-manifest-file-entry media-type target-file
)
985 (defun org-e-odt-do-image-size (probe-method file
&optional dpi anchor-type
)
986 (setq dpi
(or dpi org-e-odt-pixels-per-inch
))
987 (setq anchor-type
(or anchor-type
"paragraph"))
988 (flet ((size-in-cms (size-in-pixels)
989 (flet ((pixels-to-cms (pixels)
990 (let* ((cms-per-inch 2.54)
991 (inches (/ pixels dpi
)))
992 (* cms-per-inch inches
))))
994 (cons (pixels-to-cms (car size-in-pixels
))
995 (pixels-to-cms (cdr size-in-pixels
)))))))
998 (size-in-cms (ignore-errors ; Emacs could be in batch mode
1000 (image-size (create-image file
) 'pixels
))))
1003 (let ((dim (shell-command-to-string
1004 (format "identify -format \"%%w:%%h\" \"%s\"" file
))))
1005 (when (string-match "\\([0-9]+\\):\\([0-9]+\\)" dim
)
1006 (cons (string-to-number (match-string 1 dim
))
1007 (string-to-number (match-string 2 dim
)))))))
1009 (cdr (assoc-string anchor-type
1010 org-e-odt-default-image-sizes-alist
))))))
1012 (defun org-e-odt-image-size-from-file (file &optional user-width
1013 user-height scale dpi embed-as
)
1014 (unless (file-name-absolute-p file
)
1015 (setq file
(expand-file-name
1016 file
(file-name-directory org-current-export-file
))))
1017 (let* (size width height
)
1018 (unless (and user-height user-width
)
1019 (loop for probe-method in org-e-odt-image-size-probe-method
1021 do
(setq size
(org-e-odt-do-image-size
1022 probe-method file dpi embed-as
)))
1023 (or size
(error "Cannot determine Image size. Aborting ..."))
1024 (setq width
(car size
) height
(cdr size
)))
1027 (setq width
(* width scale
) height
(* height scale
)))
1028 ((and user-height user-width
)
1029 (setq width user-width height user-height
))
1031 (setq width
(* user-height
(/ width height
)) height user-height
))
1033 (setq height
(* user-width
(/ height width
)) width user-width
))
1035 ;; ensure that an embedded image fits comfortably within a page
1036 (let ((max-width (car org-e-odt-max-image-size
))
1037 (max-height (cdr org-e-odt-max-image-size
)))
1038 (when (or (> width max-width
) (> height max-height
))
1039 (let* ((scale1 (/ max-width width
))
1040 (scale2 (/ max-height height
))
1041 (scale (min scale1 scale2
)))
1042 (setq width
(* scale width
) height
(* scale height
)))))
1043 (cons width height
)))
1045 (defun org-e-odt-format-label (element info op
)
1046 (let* ((caption-from
1047 (case (org-element-type element
)
1048 (link (org-export-get-parent-paragraph element info
))
1050 ;; get label and caption.
1051 (label (org-element-property :name caption-from
))
1052 (caption (org-element-property :caption caption-from
))
1053 (short-caption (cdr caption
))
1054 ;; transcode captions.
1055 (caption (and (car caption
) (org-export-secondary-string
1056 (car caption
) 'e-odt info
)))
1057 (short-caption (and short-caption
(org-export-secondary-string
1058 short-caption
'e-odt info
))))
1059 (when (or label caption
)
1060 (let* ((default-category
1062 ((eq (org-element-type element
) 'table
)
1064 ((org-e-odt-standalone-image-p element info
)
1066 ((member (org-element-type element
)
1067 '(latex-environment latex-fragment
))
1068 (let ((processing-type (plist-get info
:LaTeX-fragments
)))
1070 ((eq processing-type
'dvipng
) "__DvipngImage__")
1071 ((eq processing-type
'mathjax
) "__MathFormula__")
1072 ((eq processing-type
't
) "__MathFormula__")
1073 (t (error "Handle LaTeX:verbatim")))))
1074 ((eq (org-element-type element
) 'src-block
)
1076 (t (error "Handle enumeration of %S" element
))))
1079 ((member (org-element-type element
)
1080 '(table latex-environment src-block
))
1082 ((org-e-odt-standalone-image-p element info
)
1083 'org-e-odt-standalone-image-p
)
1084 (t (error "Handle enumeration of %S" element
))))
1085 (seqno (org-e-odt-enumerate-element
1086 element info predicate
)) ; FIXME
1087 ;; handle label props.
1088 (label-props (assoc default-category org-e-odt-category-map-alist
))
1089 ;; identify opendocument counter
1090 (counter (nth 1 label-props
))
1091 ;; identify label style
1092 (label-style (nth 2 label-props
))
1093 ;; grok language setting
1094 (en-strings (assoc-default "en" org-e-odt-category-strings
))
1095 (lang (plist-get info
:language
)) ; FIXME
1096 (lang-strings (assoc-default lang org-e-odt-category-strings
))
1097 ;; retrieve localized category sting
1098 (pos (- (length org-e-odt-category-map-alist
)
1099 (length (memq label-props org-e-odt-category-map-alist
))))
1100 (category (or (nth pos lang-strings
) (nth pos en-strings
))))
1103 ;; assign an internal label, if user has not provided one
1104 (setq label
(or label
(format "%s-%s" default-category seqno
)))
1105 (setq label
(org-solidify-link-text label
))
1109 (cadr (assoc-string label-style org-e-odt-label-styles t
))
1111 (?n .
,(org-e-odt-format-tags-simple
1112 '("<text:sequence text:ref-name=\"%s\" text:name=\"%s\" text:formula=\"ooow:%s+1\" style:num-format=\"1\">" .
"</text:sequence>")
1113 seqno label counter counter
))
1114 (?c .
,(or caption
""))))
1118 (setq label
(org-solidify-link-text label
))
1119 (let* ((fmt (cddr (assoc-string label-style org-e-odt-label-styles t
)))
1122 (org-e-odt-format-tags-simple
1123 '("<text:sequence-ref text:reference-format=\"%s\" text:ref-name=\"%s\">"
1124 .
"</text:sequence-ref>")
1125 (format-spec fmt2
`((?e .
,category
)
1126 (?n .
,seqno
))) fmt1 label
)))
1127 (t (error "Unknow %S on label" op
)))))))
1129 (defun org-e-odt-format-tags-1 (tag text prefix suffix
&rest args
)
1132 (concat prefix
(apply 'format
(car tag
) args
) text suffix
1133 (format (cdr tag
))))
1134 ((stringp tag
) ; singleton tag
1135 (concat prefix
(apply 'format tag args
) text
))))
1137 (defun org-e-odt-format-tags (tag text
&rest args
)
1138 (apply 'org-e-odt-format-tags-1 tag text
"\n" "\n" args
))
1140 (defun org-e-odt-format-tags-simple (tag text
&rest args
)
1141 (apply 'org-e-odt-format-tags-1 tag text nil nil args
))
1143 (defun org-e-odt-init-outfile ()
1144 (unless (executable-find "zip")
1145 ;; Not at all OSes ship with zip by default
1146 (error "Executable \"zip\" needed for creating OpenDocument files"))
1148 (let* ((outdir (make-temp-file
1149 (format org-e-odt-tmpdir-prefix
'odt
) t
)) ; FIXME
1150 (content-file (expand-file-name "content.xml" outdir
)))
1153 (setq org-e-odt-manifest-file-entries nil
1154 org-e-odt-embedded-images-count
0
1155 org-e-odt-embedded-formulas-count
0
1156 org-e-odt-section-count
0
1157 org-e-odt-entity-labels-alist nil
1158 org-e-odt-list-stack-stashed nil
1159 org-e-odt-automatic-styles nil
1160 org-e-odt-object-counters nil
1161 org-e-odt-entity-counts-plist nil
)
1163 ;; let `htmlfontify' know that we are interested in collecting
1166 (setq hfy-user-sheet-assoc nil
)
1169 (with-current-buffer
1170 (find-file-noselect content-file t
)
1175 (defun org-e-odt-save-as-outfile (target opt-plist
)
1176 ;; write automatic styles
1177 (org-e-odt-write-automatic-styles)
1179 ;; write styles file
1180 ;; (when (equal org-lparse-backend 'odt) FIXME
1183 ;; (org-e-odt-update-styles-file opt-plist)
1185 ;; create mimetype file
1186 (let ((mimetype (org-e-odt-write-mimetype-file ;; org-lparse-backend FIXME
1188 (org-e-odt-create-manifest-file-entry mimetype
"/" "1.2"))
1190 ;; create a manifest entry for content.xml
1191 (org-e-odt-create-manifest-file-entry "text/xml" "content.xml")
1193 ;; write out the manifest entries before zipping
1194 (org-e-odt-write-manifest-file)
1196 (let ((xml-files '("mimetype" "META-INF/manifest.xml" "content.xml"
1198 (zipdir default-directory
))
1199 (when (or t
(equal org-lparse-backend
'odt
)) ; FIXME
1200 (push "styles.xml" xml-files
))
1201 (message "Switching to directory %s" (expand-file-name zipdir
))
1203 ;; save all xml files
1204 (mapc (lambda (file)
1205 (with-current-buffer
1206 (find-file-noselect (expand-file-name file
) t
)
1207 ;; prettify output if needed
1208 (when org-e-odt-prettify-xml
1209 (indent-region (point-min) (point-max)))
1213 (let* ((target-name (file-name-nondirectory target
))
1214 (target-dir (file-name-directory target
))
1215 (cmds `(("zip" "-mX0" ,target-name
"mimetype")
1216 ("zip" "-rmTq" ,target-name
"."))))
1217 (when (file-exists-p target
)
1218 ;; FIXME: If the file is locked this throws a cryptic error
1219 (delete-file target
))
1221 (let ((coding-system-for-write 'no-conversion
) exitcode err-string
)
1222 (message "Creating odt file...")
1225 (message "Running %s" (mapconcat 'identity cmd
" "))
1227 (with-output-to-string
1229 (apply 'call-process
(car cmd
)
1230 nil standard-output nil
(cdr cmd
)))))
1231 (or (zerop exitcode
)
1232 (ignore (message "%s" err-string
))
1233 (error "Unable to create odt file (%S)" exitcode
)))
1236 ;; move the file from outdir to target-dir
1237 (rename-file target-name target-dir
)
1239 ;; kill all xml buffers
1240 (mapc (lambda (file)
1242 (find-file-noselect (expand-file-name file zipdir
) t
)))
1245 (delete-directory zipdir
)))
1246 (message "Created %s" target
)
1247 (set-buffer (find-file-noselect target t
)))
1250 (defun org-e-odt-create-manifest-file-entry (&rest args
)
1251 (push args org-e-odt-manifest-file-entries
))
1253 (defun org-e-odt-write-manifest-file ()
1254 (make-directory "META-INF")
1255 (let ((manifest-file (expand-file-name "META-INF/manifest.xml")))
1256 (with-current-buffer
1257 (find-file-noselect manifest-file t
)
1259 "<?xml version=\"1.0\" encoding=\"UTF-8\"?>
1260 <manifest:manifest xmlns:manifest=\"urn:oasis:names:tc:opendocument:xmlns:manifest:1.0\" manifest:version=\"1.2\">\n")
1262 (lambda (file-entry)
1263 (let* ((version (nth 2 file-entry
))
1265 (format " manifest:version=\"%s\"" version
)
1268 (format org-e-odt-manifest-file-entry-tag
1269 (nth 0 file-entry
) (nth 1 file-entry
) extra
))))
1270 org-e-odt-manifest-file-entries
)
1271 (insert "\n</manifest:manifest>"))))
1273 (defun org-e-odt-update-meta-file (info) ; FIXME opt-plist
1274 (let ((title (org-export-secondary-string
1275 (plist-get info
:title
) 'e-odt info
))
1276 (author (or (let ((auth (plist-get info
:author
)))
1277 (and auth
(org-export-secondary-string
1278 auth
'e-odt info
))) ""))
1279 (date (org-e-odt-format-date (plist-get info
:date
)))
1280 (email (plist-get info
:email
))
1281 (keywords (plist-get info
:keywords
))
1282 (description (plist-get info
:description
)))
1285 "<?xml version=\"1.0\" encoding=\"UTF-8\"?>
1286 <office:document-meta
1287 xmlns:office=\"urn:oasis:names:tc:opendocument:xmlns:office:1.0\"
1288 xmlns:xlink=\"http://www.w3.org/1999/xlink\"
1289 xmlns:dc=\"http://purl.org/dc/elements/1.1/\"
1290 xmlns:meta=\"urn:oasis:names:tc:opendocument:xmlns:meta:1.0\"
1291 xmlns:ooo=\"http://openoffice.org/2004/office\"
1292 office:version=\"1.2\">
1294 (org-e-odt-format-author author
) "\n"
1295 (format "<meta:initial-creator>%s</meta:initial-creator>\n" author
)
1296 (format "<dc:date>%s</dc:date>\n" date
)
1297 (format "<meta:creation-date>%s</meta:creation-date>\n" date
)
1298 (format "<meta:generator>%s</meta:generator>\n"
1299 (when org-export-creator-info
1300 (format "Org-%s/Emacs-%s"
1301 org-version emacs-version
)))
1302 (format "<meta:keyword>%s</meta:keyword>\n" keywords
)
1303 (format "<dc:subject>%s</dc:subject>\n" description
)
1304 (format "<dc:title>%s</dc:title>\n" title
)
1306 " </office:meta>\n" "</office:document-meta>")
1307 nil
(expand-file-name "meta.xml")))
1309 ;; create a manifest entry for meta.xml
1310 (org-e-odt-create-manifest-file-entry "text/xml" "meta.xml"))
1312 (defun org-e-odt-update-styles-file (info)
1313 ;; write styles file
1314 (let ((styles-file (plist-get info
:odt-styles-file
)))
1315 (org-e-odt-copy-styles-file (and styles-file
1316 (read (org-trim styles-file
))))
1318 ;; FIXME: Who is opening an empty styles.xml before this point?
1319 (with-current-buffer
1320 (find-file-noselect (expand-file-name "styles.xml") t
)
1321 (revert-buffer t t
)))
1323 ;; Write custom styles for source blocks
1324 (org-e-odt-insert-custom-styles-for-srcblocks
1327 (format " %s\n" (cddr style
)))
1328 hfy-user-sheet-assoc
"")))
1330 (defun org-e-odt-write-mimetype-file (format)
1331 ;; create mimetype file
1334 (odt "application/vnd.oasis.opendocument.text")
1335 (odf "application/vnd.oasis.opendocument.formula")
1336 (t (error "Unknown OpenDocument backend %S" org-lparse-backend
)))))
1337 (write-region mimetype nil
(expand-file-name "mimetype"))
1340 (declare-function org-create-math-formula
"org"
1341 (latex-frag &optional mathml-file
))
1343 (defun org-e-odt-get (what &optional opt-plist
)
1345 (EXPORT-DIR (org-export-directory :html opt-plist
))
1346 (TABLE-FIRST-COLUMN-AS-LABELS nil
)
1347 (CODING-SYSTEM-FOR-WRITE 'utf-8
)
1348 (CODING-SYSTEM-FOR-SAVE 'utf-8
)
1349 (t (error "Unknown property: %s" what
))))
1351 (defun org-e-odt-do-preprocess-latex-fragments ()
1352 "Convert LaTeX fragments to images."
1353 (let* ((latex-frag-opt (plist-get org-lparse-opt-plist
:LaTeX-fragments
))
1354 (latex-frag-opt ; massage the options
1355 (or (and (member latex-frag-opt
'(mathjax t
))
1356 (not (and (fboundp 'org-format-latex-mathml-available-p
)
1357 (org-format-latex-mathml-available-p)))
1358 (prog1 org-lparse-latex-fragment-fallback
1361 "LaTeX to MathML converter not available. "
1362 (format "Using %S instead."
1363 org-lparse-latex-fragment-fallback
)))))
1365 cache-dir display-msg
)
1367 ((eq latex-frag-opt
'dvipng
)
1368 (setq cache-dir
"ltxpng/")
1369 (setq display-msg
"Creating LaTeX image %s"))
1370 ((member latex-frag-opt
'(mathjax t
))
1371 (setq latex-frag-opt
'mathml
)
1372 (setq cache-dir
"ltxmathml/")
1373 (setq display-msg
"Creating MathML formula %s")))
1374 (when (and org-current-export-file
)
1376 (concat cache-dir
(file-name-sans-extension
1377 (file-name-nondirectory org-current-export-file
)))
1378 org-current-export-dir nil display-msg
1379 nil nil latex-frag-opt
))))
1381 (eval-after-load 'org-odt
1382 '(ad-deactivate 'org-format-latex-as-mathml
))
1386 ;; (defadvice org-format-latex-as-mathml ; FIXME
1387 ;; (after org-e-odt-protect-latex-fragment activate)
1388 ;; "Encode LaTeX fragment as XML.
1389 ;; Do this when translation to MathML fails."
1390 ;; (when (or (not (> (length ad-return-value) 0))
1391 ;; (get-text-property 0 'org-protected ad-return-value))
1392 ;; (setq ad-return-value
1393 ;; (org-propertize (org-e-odt-encode-plain-text (ad-get-arg 0))
1394 ;; 'org-protected t))))
1396 (defun org-e-odt-zip-extract-one (archive member
&optional target
)
1398 (let* ((target (or target default-directory
))
1399 (archive (expand-file-name archive
))
1400 (archive-zip-extract
1401 (list "unzip" "-qq" "-o" "-d" target
))
1402 exit-code command-output
)
1403 (setq command-output
1405 (setq exit-code
(archive-zip-extract archive member
))
1407 (unless (zerop exit-code
)
1408 (message command-output
)
1409 (error "Extraction failed"))))
1411 (defun org-e-odt-zip-extract (archive members
&optional target
)
1412 (when (atom members
) (setq members
(list members
)))
1413 (mapc (lambda (member)
1414 (org-e-odt-zip-extract-one archive member target
))
1417 (defun org-e-odt-copy-styles-file (&optional styles-file
)
1418 ;; Non-availability of styles.xml is not a critical error. For now
1419 ;; throw an error purely for aesthetic reasons.
1420 (setq styles-file
(or styles-file
1421 org-e-odt-styles-file
1422 (expand-file-name "OrgOdtStyles.xml"
1423 org-e-odt-styles-dir
)
1424 (error "org-e-odt: Missing styles file?")))
1426 ((listp styles-file
)
1427 (let ((archive (nth 0 styles-file
))
1428 (members (nth 1 styles-file
)))
1429 (org-e-odt-zip-extract archive members
)
1432 (when (org-file-image-p member
)
1433 (let* ((image-type (file-name-extension member
))
1434 (media-type (format "image/%s" image-type
)))
1435 (org-e-odt-create-manifest-file-entry media-type member
))))
1437 ((and (stringp styles-file
) (file-exists-p styles-file
))
1438 (let ((styles-file-type (file-name-extension styles-file
)))
1440 ((string= styles-file-type
"xml")
1441 (copy-file styles-file
(expand-file-name "styles.xml") t
))
1442 ((member styles-file-type
'("odt" "ott"))
1443 (org-e-odt-zip-extract styles-file
"styles.xml")))))
1445 (error (format "Invalid specification of styles.xml file: %S"
1446 org-e-odt-styles-file
))))
1448 ;; create a manifest entry for styles.xml
1449 (org-e-odt-create-manifest-file-entry "text/xml" "styles.xml"))
1451 (defun org-e-odt-configure-outline-numbering ()
1452 "Outline numbering is retained only upto LEVEL.
1453 To disable outline numbering pass a LEVEL of 0."
1454 (goto-char (point-min))
1456 "<text:outline-level-style\\([^>]*\\)text:level=\"\\([^\"]*\\)\"\\([^>]*\\)>")
1458 "<text:outline-level-style\\1text:level=\"\\2\" style:num-format=\"\">"))
1459 (while (re-search-forward regex nil t
)
1460 (unless (let ((sec-num (plist-get info
:section-numbers
))
1461 (level (string-to-number (match-string 2))))
1462 (if (wholenump sec-num
) (<= level sec-num
) sec-num
))
1463 (replace-match replacement t nil
))))
1467 (defun org-export-as-odf (latex-frag &optional odf-file
)
1468 "Export LATEX-FRAG as OpenDocument formula file ODF-FILE.
1469 Use `org-create-math-formula' to convert LATEX-FRAG first to
1470 MathML. When invoked as an interactive command, use
1471 `org-latex-regexps' to infer LATEX-FRAG from currently active
1472 region. If no LaTeX fragments are found, prompt for it. Push
1473 MathML source to kill ring, if `org-export-copy-to-kill-ring' is
1477 (setq frag
(and (setq frag
(and (region-active-p)
1478 (buffer-substring (region-beginning)
1480 (loop for e in org-latex-regexps
1481 thereis
(when (string-match (nth 1 e
) frag
)
1482 (match-string (nth 2 e
) frag
)))))
1483 (read-string "LaTeX Fragment: " frag nil frag
))
1484 ,(let ((odf-filename (expand-file-name
1486 (file-name-sans-extension
1487 (or (file-name-nondirectory buffer-file-name
)))
1489 (file-name-directory buffer-file-name
))))
1490 (read-file-name "ODF filename: " nil odf-filename nil
1491 (file-name-nondirectory odf-filename
)))))
1492 (let* ((org-lparse-backend 'odf
)
1493 org-lparse-opt-plist
1494 (filename (or odf-file
1497 (file-name-sans-extension
1498 (or (file-name-nondirectory buffer-file-name
)))
1500 (file-name-directory buffer-file-name
))))
1501 (buffer (find-file-noselect (org-e-odt-init-outfile filename
)))
1502 (coding-system-for-write 'utf-8
)
1503 (save-buffer-coding-system 'utf-8
))
1505 (set-buffer-file-coding-system coding-system-for-write
)
1506 (let ((mathml (org-create-math-formula latex-frag
)))
1507 (unless mathml
(error "No Math formula created"))
1509 (or (org-export-push-to-kill-ring
1510 (upcase (symbol-name org-lparse-backend
)))
1511 (message "Exporting... done")))
1512 (org-e-odt-save-as-outfile filename nil
; FIXME
1516 (defun org-export-as-odf-and-open ()
1517 "Export LaTeX fragment as OpenDocument formula and immediately open it.
1518 Use `org-export-as-odf' to read LaTeX fragment and OpenDocument
1521 (org-lparse-and-open
1522 nil nil nil
(call-interactively 'org-export-as-odf
)))
1527 ;;; Driver Starts here
1530 (require 'format-spec
)
1531 (eval-when-compile (require 'cl
) (require 'table
))
1537 ;; FIXME: it already exists in org-e-odt.el
1538 ;;; Function Declarations
1540 (declare-function org-element-property
"org-element" (property element
))
1541 (declare-function org-element-normalize-string
"org-element" (s))
1542 (declare-function org-element-parse-secondary-string
1543 "org-element" (string restriction
&optional buffer
))
1544 (defvar org-element-string-restrictions
)
1545 (defvar org-element-object-restrictions
)
1547 (declare-function org-export-clean-table
"org-export" (table specialp
))
1548 (declare-function org-export-data
"org-export" (data backend info
))
1549 (declare-function org-export-directory
"org-export" (type plist
))
1550 (declare-function org-export-expand-macro
"org-export" (macro info
))
1551 (declare-function org-export-first-sibling-p
"org-export" (headline info
))
1552 (declare-function org-export-footnote-first-reference-p
"org-export"
1553 (footnote-reference info
))
1554 (declare-function org-export-get-coderef-format
"org-export" (path desc
))
1555 (declare-function org-export-get-footnote-definition
"org-export"
1556 (footnote-reference info
))
1557 (declare-function org-export-get-footnote-number
"org-export" (footnote info
))
1558 (declare-function org-export-get-previous-element
"org-export" (blob info
))
1559 (declare-function org-export-get-relative-level
"org-export" (headline info
))
1560 (declare-function org-export-handle-code
1561 "org-export" (element info
&optional num-fmt ref-fmt delayed
))
1562 (declare-function org-export-included-file
"org-export" (keyword backend info
))
1563 (declare-function org-export-inline-image-p
"org-export"
1564 (link &optional extensions
))
1565 (declare-function org-export-last-sibling-p
"org-export" (headline info
))
1566 (declare-function org-export-low-level-p
"org-export" (headline info
))
1567 (declare-function org-export-output-file-name
1568 "org-export" (extension &optional subtreep pub-dir
))
1569 (declare-function org-export-resolve-coderef
"org-export" (ref info
))
1570 (declare-function org-export-resolve-fuzzy-link
"org-export" (link info
))
1571 (declare-function org-export-secondary-string
"org-export"
1572 (secondary backend info
))
1573 (declare-function org-export-solidify-link-text
"org-export" (s))
1574 (declare-function org-export-table-format-info
"org-export" (table))
1576 org-export-to-buffer
"org-export"
1577 (backend buffer
&optional subtreep visible-only body-only ext-plist
))
1579 org-export-to-file
"org-export"
1580 (backend file
&optional subtreep visible-only body-only ext-plist
))
1582 (declare-function org-id-find-id-file
"org-id" (id))
1583 (declare-function htmlize-region
"ext:htmlize" (beg end
))
1584 (declare-function org-pop-to-buffer-same-window
1585 "org-compat" (&optional buffer-or-name norecord label
))
1591 (declare-function hfy-face-to-style
"htmlfontify" (fn))
1592 (declare-function hfy-face-or-def-to-name
"htmlfontify" (fn))
1593 (declare-function archive-zip-extract
"arc-mode.el" (archive name
))
1595 ;;; Internal Variables
1597 ;;;; ODT Internal Variables
1599 (defconst org-e-odt-lib-dir
1600 (file-name-directory load-file-name
)
1601 "Location of ODT exporter.
1602 Use this to infer values of `org-e-odt-styles-dir' and
1603 `org-e-odt-schema-dir'.")
1605 (defvar org-e-odt-data-dir
1606 (expand-file-name "../etc/" org-e-odt-lib-dir
)
1607 "Data directory for ODT exporter.
1608 Use this to infer values of `org-e-odt-styles-dir' and
1609 `org-e-odt-schema-dir'.")
1611 (defconst org-e-odt-special-string-regexps
1612 '(("\\\\-" .
"­\\1") ; shy
1613 ("---\\([^-]\\)" .
"—\\1") ; mdash
1614 ("--\\([^-]\\)" .
"–\\1") ; ndash
1615 ("\\.\\.\\." .
"…")) ; hellip
1616 "Regular expressions for special string conversion.")
1618 (defconst org-e-odt-schema-dir-list
1620 (and org-e-odt-data-dir
1621 (expand-file-name "./schema/" org-e-odt-data-dir
)) ; bail out
1623 (and (boundp 'org-e-odt-data-dir
) org-e-odt-data-dir
; see make install
1624 (expand-file-name "./schema/" org-e-odt-data-dir
)))
1625 (expand-file-name "../contrib/odt/etc/schema/" org-e-odt-lib-dir
) ; git
1627 "List of directories to search for OpenDocument schema files.
1628 Use this list to set the default value of
1629 `org-e-odt-schema-dir'. The entries in this list are
1630 populated heuristically based on the values of `org-e-odt-lib-dir'
1631 and `org-e-odt-data-dir'.")
1634 (defconst org-e-odt-styles-dir-list
1636 (and org-e-odt-data-dir
1637 (expand-file-name "./styles/" org-e-odt-data-dir
)) ; bail out
1639 (and (boundp 'org-e-odt-data-dir
) org-e-odt-data-dir
; see make install
1640 (expand-file-name "./styles/" org-e-odt-data-dir
)))
1641 (expand-file-name "../etc/styles/" org-e-odt-lib-dir
) ; git
1642 (expand-file-name "./etc/styles/" org-e-odt-lib-dir
) ; elpa
1643 (expand-file-name "./org/" data-directory
) ; system
1645 "List of directories to search for OpenDocument styles files.
1646 See `org-e-odt-styles-dir'. The entries in this list are populated
1647 heuristically based on the values of `org-e-odt-lib-dir' and
1648 `org-e-odt-data-dir'.")
1650 (defconst org-e-odt-styles-dir
1653 (message "Debug (org-e-odt): Searching for OpenDocument styles files...")
1654 (mapc (lambda (styles-dir)
1656 (message "Debug (org-e-odt): Trying %s..." styles-dir
)
1657 (when (and (file-readable-p
1659 "OrgOdtContentTemplate.xml" styles-dir
))
1662 "OrgOdtStyles.xml" styles-dir
)))
1663 (message "Debug (org-e-odt): Using styles under %s"
1665 (throw 'styles-dir styles-dir
))))
1666 org-e-odt-styles-dir-list
)
1669 (error "Error (org-e-odt): Cannot find factory styles files. Aborting."))
1671 "Directory that holds auxiliary XML files used by the ODT exporter.
1673 This directory contains the following XML files -
1674 \"OrgOdtStyles.xml\" and \"OrgOdtContentTemplate.xml\". These
1675 XML files are used as the default values of
1676 `org-e-odt-styles-file' and
1677 `org-e-odt-content-template-file'.
1679 The default value of this variable varies depending on the
1680 version of org in use and is initialized from
1681 `org-e-odt-styles-dir-list'. Note that the user could be using org
1682 from one of: org's own private git repository, GNU ELPA tar or
1685 (defconst org-e-odt-tmpdir-prefix
"%s-")
1686 (defconst org-e-odt-bookmark-prefix
"OrgXref.")
1688 (defconst org-e-odt-manifest-file-entry-tag
1690 <manifest:file-entry manifest:media-type=\"%s\" manifest:full-path=\"%s\"%s/>")
1694 (defvar org-lparse-dyn-first-heading-pos
) ; let bound during org-do-lparse
1696 (defvar org-e-odt-suppress-xref nil
)
1697 (defvar org-e-odt-file-extensions
1698 '(("odt" .
"OpenDocument Text")
1699 ("ott" .
"OpenDocument Text Template")
1700 ("odm" .
"OpenDocument Master Document")
1701 ("ods" .
"OpenDocument Spreadsheet")
1702 ("ots" .
"OpenDocument Spreadsheet Template")
1703 ("odg" .
"OpenDocument Drawing (Graphics)")
1704 ("otg" .
"OpenDocument Drawing Template")
1705 ("odp" .
"OpenDocument Presentation")
1706 ("otp" .
"OpenDocument Presentation Template")
1707 ("odi" .
"OpenDocument Image")
1708 ("odf" .
"OpenDocument Formula")
1709 ("odc" .
"OpenDocument Chart")))
1711 (defvar org-e-odt-default-org-styles-alist
1712 '((paragraph .
((default .
"Text_20_body")
1713 (fixedwidth .
"OrgFixedWidthBlock")
1714 (verse .
"OrgVerse")
1715 (quote .
"Quotations")
1716 (blockquote .
"Quotations")
1717 (center .
"OrgCenter")
1719 (right .
"OrgRight")
1720 (title .
"OrgTitle")
1721 (subtitle .
"OrgSubtitle")
1722 (footnote .
"Footnote")
1723 (src .
"OrgSrcBlock")
1724 (illustration .
"Illustration")
1726 (listing .
"Listing")
1727 (definition-term .
"Text_20_body_20_bold")
1728 (horizontal-line .
"Horizontal_20_Line")))
1729 (character .
((bold .
"Bold")
1730 (emphasis .
"Emphasis")
1732 (verbatim .
"OrgCode")
1733 (strike .
"Strikethrough")
1734 (underline .
"Underline")
1735 (subscript .
"OrgSubscript")
1736 (superscript .
"OrgSuperscript")))
1737 (list .
((ordered .
"OrgNumberedList")
1738 (unordered .
"OrgBulletedList")
1739 (descriptive .
"OrgDescriptionList"))))
1740 "Default styles for various entities.")
1742 (defvar org-e-odt-org-styles-alist org-e-odt-default-org-styles-alist
)
1745 ;;;_. control callbacks
1746 ;;;_ , document body
1748 (defvar org-lparse-body-only
) ; let bound during org-do-lparse
1749 (defvar org-lparse-opt-plist
) ; bound during org-do-lparse
1750 (defvar org-lparse-list-stack
) ; dynamically bound in org-do-lparse
1751 (defvar org-e-odt-list-stack-stashed
)
1752 (defvar org-lparse-table-ncols
)
1753 (defvar org-e-odt-table-rowgrp-open
)
1754 (defvar org-e-odt-table-rownum
)
1755 (defvar org-e-odt-table-cur-rowgrp-is-hdr
)
1756 (defvar org-lparse-table-is-styled
)
1757 (defvar org-lparse-table-rowgrp-info
)
1758 (defvar org-lparse-table-colalign-vector
)
1760 (defvar org-e-odt-table-style nil
1761 "Table style specified by \"#+ATTR_ODT: <style-name>\" line.
1762 This is set during `org-e-odt-begin-table'.")
1764 (defvar org-e-odt-table-style-spec nil
1765 "Entry for `org-e-odt-table-style' in `org-e-odt-table-styles'.")
1768 (defvar org-e-odt-table-style-format
1770 <style:style style:name=\"%s\" style:family=\"table\">
1771 <style:table-properties style:rel-width=\"%d%%\" fo:margin-top=\"0cm\" fo:margin-bottom=\"0.20cm\" table:align=\"center\"/>
1774 "Template for auto-generated Table styles.")
1776 (defvar org-e-odt-automatic-styles
'()
1777 "Registry of automatic styles for various OBJECT-TYPEs.
1778 The variable has the following form:
1780 \(\(OBJECT-NAME-A.1 OBJECT-PROPS-A.1\)
1781 \(OBJECT-NAME-A.2 OBJECT-PROPS-A.2\) ...\)\)
1783 \(\(OBJECT-NAME-B.1 OBJECT-PROPS-B.1\)
1784 \(OBJECT-NAME-B.2 OBJECT-PROPS-B.2\) ...\)\)
1787 OBJECT-TYPEs could be \"Section\", \"Table\", \"Figure\" etc.
1788 OBJECT-PROPS is (typically) a plist created by passing
1789 \"#+ATTR_ODT: \" option to `org-e-odt-parse-block-attributes'.
1791 Use `org-e-odt-add-automatic-style' to add update this variable.'")
1793 (defvar org-e-odt-object-counters nil
1794 "Running counters for various OBJECT-TYPEs.
1795 Use this to generate automatic names and style-names. See
1796 `org-e-odt-add-automatic-style'.")
1798 (defvar org-e-odt-table-indentedp nil
)
1799 (defvar org-lparse-table-colalign-info
)
1800 (defvar org-lparse-link-description-is-image nil
)
1803 (defvar org-src-block-paragraph-format
1804 "<style:style style:name=\"OrgSrcBlock\" style:family=\"paragraph\" style:parent-style-name=\"Preformatted_20_Text\">
1805 <style:paragraph-properties fo:background-color=\"%s\" fo:padding=\"0.049cm\" fo:border=\"0.51pt solid #000000\" style:shadow=\"none\">
1806 <style:background-image/>
1807 </style:paragraph-properties>
1808 <style:text-properties fo:color=\"%s\"/>
1810 "Custom paragraph style for colorized source and example blocks.
1811 This style is much the same as that of \"OrgFixedWidthBlock\"
1812 except that the foreground and background colors are set
1813 according to the default face identified by the `htmlfontify'.")
1815 (defvar hfy-optimisations
)
1816 (defvar org-e-odt-embedded-formulas-count
0)
1817 (defvar org-e-odt-entity-frame-styles
1818 '(("As-CharImage" "__Figure__" ("OrgInlineImage" nil
"as-char"))
1819 ("ParagraphImage" "__Figure__" ("OrgDisplayImage" nil
"paragraph"))
1820 ("PageImage" "__Figure__" ("OrgPageImage" nil
"page"))
1821 ("CaptionedAs-CharImage" "__Figure__"
1822 ("OrgCaptionedImage"
1823 " style:rel-width=\"100%\" style:rel-height=\"scale\"" "paragraph")
1824 ("OrgInlineImage" nil
"as-char"))
1825 ("CaptionedParagraphImage" "__Figure__"
1826 ("OrgCaptionedImage"
1827 " style:rel-width=\"100%\" style:rel-height=\"scale\"" "paragraph")
1828 ("OrgImageCaptionFrame" nil
"paragraph"))
1829 ("CaptionedPageImage" "__Figure__"
1830 ("OrgCaptionedImage"
1831 " style:rel-width=\"100%\" style:rel-height=\"scale\"" "paragraph")
1832 ("OrgPageImageCaptionFrame" nil
"page"))
1833 ("InlineFormula" "__MathFormula__" ("OrgInlineFormula" nil
"as-char"))
1834 ("DisplayFormula" "__MathFormula__" ("OrgDisplayFormula" nil
"as-char"))
1835 ("CaptionedDisplayFormula" "__MathFormula__"
1836 ("OrgCaptionedFormula" nil
"paragraph")
1837 ("OrgFormulaCaptionFrame" nil
"as-char"))))
1839 (defvar org-e-odt-embedded-images-count
0)
1841 (defvar org-e-odt-image-size-probe-method
1842 (append (and (executable-find "identify") '(imagemagick)) ; See Bug#10675
1844 "Ordered list of methods for determining image sizes.")
1846 (defvar org-e-odt-default-image-sizes-alist
1847 '(("as-char" .
(5 .
0.4))
1848 ("paragraph" .
(5 .
5)))
1849 "Hardcoded image dimensions one for each of the anchor
1852 ;; A4 page size is 21.0 by 29.7 cms
1853 ;; The default page settings has 2cm margin on each of the sides. So
1854 ;; the effective text area is 17.0 by 25.7 cm
1855 (defvar org-e-odt-max-image-size
'(17.0 .
20.0)
1856 "Limiting dimensions for an embedded image.")
1858 (defvar org-e-odt-entity-labels-alist nil
1859 "Associate Labels with the Labeled entities.
1860 Each element of the alist is of the form (LABEL-NAME
1861 CATEGORY-NAME SEQNO LABEL-STYLE-NAME). LABEL-NAME is same as
1862 that specified by \"#+LABEL: ...\" line. CATEGORY-NAME is the
1863 type of the entity that LABEL-NAME is attached to. CATEGORY-NAME
1864 can be one of \"Table\", \"Figure\" or \"Equation\". SEQNO is
1865 the unique number assigned to the referenced entity on a
1866 per-CATEGORY basis. It is generated sequentially and is 1-based.
1867 LABEL-STYLE-NAME is a key `org-e-odt-label-styles'.
1869 See `org-e-odt-add-label-definition' and
1870 `org-e-odt-fixup-label-references'.")
1872 (defvar org-e-odt-entity-counts-plist nil
1873 "Plist of running counters of SEQNOs for each of the CATEGORY-NAMEs.
1874 See `org-e-odt-entity-labels-alist' for known CATEGORY-NAMEs.")
1876 (defvar org-e-odt-label-styles
1877 '(("math-formula" "%c" "text" "(%n)")
1878 ("math-label" "(%n)" "text" "(%n)")
1879 ("category-and-value" "%e %n: %c" "category-and-value" "%e %n")
1880 ("value" "%e %n: %c" "value" "%n"))
1881 "Specify how labels are applied and referenced.
1882 This is an alist where each element is of the
1883 form (LABEL-STYLE-NAME LABEL-ATTACH-FMT LABEL-REF-MODE
1886 LABEL-ATTACH-FMT controls how labels and captions are attached to
1887 an entity. It may contain following specifiers - %e, %n and %c.
1888 %e is replaced with the CATEGORY-NAME. %n is replaced with
1889 \"<text:sequence ...> SEQNO </text:sequence>\". %c is replaced
1890 with CAPTION. See `org-e-odt-format-label-definition'.
1892 LABEL-REF-MODE and LABEL-REF-FMT controls how label references
1893 are generated. The following XML is generated for a label
1894 reference - \"<text:sequence-ref
1895 text:reference-format=\"LABEL-REF-MODE\" ...> LABEL-REF-FMT
1896 </text:sequence-ref>\". LABEL-REF-FMT may contain following
1897 specifiers - %e and %n. %e is replaced with the CATEGORY-NAME.
1898 %n is replaced with SEQNO. See
1899 `org-e-odt-format-label-reference'.")
1901 (defcustom org-e-odt-category-strings
1902 '(("en" "Table" "Figure" "Equation" "Equation" "Listing"))
1903 "Specify category strings for various captionable entities.
1904 Captionable entity can be one of a Table, an Embedded Image, a
1905 LaTeX fragment (generated with dvipng) or a Math Formula.
1907 For example, when `org-export-default-language' is \"en\", an
1908 embedded image will be captioned as \"Figure 1: Orgmode Logo\".
1909 If you want the images to be captioned instead as \"Illustration
1910 1: Orgmode Logo\", then modify the entry for \"en\" as shown
1913 \(setq org-e-odt-category-strings
1914 '\(\(\"en\" \"Table\" \"Illustration\"
1915 \"Equation\" \"Equation\"\)\)\)"
1916 :group
'org-export-e-odt
1918 :type
'(repeat (list (string :tag
"Language tag")
1919 (choice :tag
"Table"
1920 (const :tag
"Use Default" nil
)
1921 (string :tag
"Category string"))
1922 (choice :tag
"Figure"
1923 (const :tag
"Use Default" nil
)
1924 (string :tag
"Category string"))
1925 (choice :tag
"Math Formula"
1926 (const :tag
"Use Default" nil
)
1927 (string :tag
"Category string"))
1928 (choice :tag
"Dvipng Image"
1929 (const :tag
"Use Default" nil
)
1930 (string :tag
"Category string"))
1931 (choice :tag
"Listing"
1932 (const :tag
"Use Default" nil
)
1933 (string :tag
"Category string")))))
1935 (defvar org-e-odt-category-map-alist
1936 '(("__Table__" "Table" "value")
1937 ("__Figure__" "Illustration" "value")
1938 ("__MathFormula__" "Text" "math-formula")
1939 ("__DvipngImage__" "Equation" "value")
1940 ("__Listing__" "Listing" "value")
1941 ;; ("__Table__" "Table" "category-and-value")
1942 ;; ("__Figure__" "Figure" "category-and-value")
1943 ;; ("__DvipngImage__" "Equation" "category-and-value")
1945 "Map a CATEGORY-HANDLE to OD-VARIABLE and LABEL-STYLE.
1946 This is a list where each entry is of the form \\(CATEGORY-HANDLE
1947 OD-VARIABLE LABEL-STYLE\\). CATEGORY_HANDLE identifies the
1948 captionable entity in question. OD-VARIABLE is the OpenDocument
1949 sequence counter associated with the entity. These counters are
1951 \"<text:sequence-decls>...</text:sequence-decls>\" block of
1952 `org-e-odt-content-template-file'. LABEL-STYLE is a key
1953 into `org-e-odt-label-styles' and specifies how a given entity
1954 should be captioned and referenced.
1956 The position of a CATEGORY-HANDLE in this list is used as an
1957 index in to per-language entry for
1958 `org-e-odt-category-strings' to retrieve a CATEGORY-NAME.
1959 This CATEGORY-NAME is then used for qualifying the user-specified
1960 captions on export.")
1962 (defvar org-e-odt-manifest-file-entries nil
)
1963 (defvar hfy-user-sheet-assoc
) ; bound during org-do-lparse
1964 (defvar org-lparse-latex-fragment-fallback
) ; set by org-do-lparse
1967 ;;;; HTML Internal Variables
1969 (defvar org-e-odt-option-alist
1971 ;; (:agenda-style nil nil org-agenda-export-html-style)
1972 ;; (:convert-org-links nil nil org-e-odt-link-org-files-as-html)
1973 ;; ;; FIXME Use (org-xml-encode-org-text-skip-links s) ??
1974 ;; ;; (:expand-quoted-html nil "@" org-e-odt-expand)
1975 ;; (:inline-images nil nil org-e-odt-inline-images)
1976 ;; ;; (:link-home nil nil org-e-odt-link-home) FIXME
1977 ;; ;; (:link-up nil nil org-e-odt-link-up) FIXME
1978 ;; (:style nil nil org-e-odt-style)
1979 ;; (:style-extra nil nil org-e-odt-style-extra)
1980 ;; (:style-include-default nil nil org-e-odt-style-include-default)
1981 ;; (:style-include-scripts nil nil org-e-odt-style-include-scripts)
1982 ;; ;; (:timestamp nil nil org-e-odt-with-timestamp)
1983 ;; (:html-extension nil nil org-e-odt-extension)
1984 ;; (:html-postamble nil nil org-e-odt-postamble)
1985 ;; (:html-preamble nil nil org-e-odt-preamble)
1986 ;; (:html-table-tag nil nil org-e-odt-table-tag)
1987 ;; (:xml-declaration nil nil org-e-odt-xml-declaration)
1988 (:odt-styles-file
"ODT_STYLES_FILE" nil nil t
)
1989 (:LaTeX-fragments nil
"LaTeX" org-export-with-LaTeX-fragments
))
1990 "Alist between export properties and ways to set them.
1992 The car of the alist is the property name, and the cdr is a list
1993 like \(KEYWORD OPTION DEFAULT BEHAVIOUR\) where:
1995 KEYWORD is a string representing a buffer keyword, or nil.
1996 OPTION is a string that could be found in an #+OPTIONS: line.
1997 DEFAULT is the default value for the property.
1998 BEHAVIOUR determine how Org should handle multiple keywords for
1999 the same property. It is a symbol among:
2000 nil Keep old value and discard the new one.
2001 t Replace old value with the new one.
2002 `space' Concatenate the values, separating them with a space.
2003 `newline' Concatenate the values, separating them with
2005 `split' Split values at white spaces, and cons them to the
2008 KEYWORD and OPTION have precedence over DEFAULT.
2010 All these properties should be back-end agnostic. For back-end
2011 specific properties, define a similar variable named
2012 `org-BACKEND-option-alist', replacing BACKEND with the name of
2013 the appropriate back-end. You can also redefine properties
2014 there, as they have precedence over these.")
2016 (defvar html-table-tag nil
) ; dynamically scoped into this.
2018 ;; FIXME: it already exists in org-e-odt.el
2019 (defconst org-e-odt-cvt-link-fn
2021 "Function to convert link URLs to exportable URLs.
2022 Takes two arguments, TYPE and PATH.
2023 Returns exportable url as (TYPE PATH), or nil to signal that it
2024 didn't handle this case.
2025 Intended to be locally bound around a call to `org-export-as-html'." )
2030 (defvar org-e-odt-format-table-no-css
)
2031 (defvar htmlize-buffer-places
) ; from htmlize.el
2032 (defvar body-only
) ; dynamically scoped into this.
2034 (defvar org-e-odt-table-rowgrp-open
)
2035 (defvar org-e-odt-table-rownum
)
2036 (defvar org-e-odt-table-cur-rowgrp-is-hdr
)
2037 (defvar org-lparse-table-is-styled
)
2040 (defvar org-e-odt-headline-formatter
2041 (lambda (level snumber todo todo-type priority
2042 title tags target extra-targets extra-class
)
2043 (concat snumber
" " title
)))
2047 ;;; User Configuration Variables
2049 (defgroup org-export-e-odt nil
2050 "Options for exporting Org mode files to ODT."
2051 :tag
"Org Export ODT"
2054 (defcustom org-e-odt-protect-char-alist
2058 "Alist of characters to be converted by `org-e-html-protect'."
2059 :group
'org-export-e-html
2060 :type
'(repeat (cons (string :tag
"Character")
2061 (string :tag
"ODT equivalent"))))
2062 (defcustom org-e-odt-schema-dir
2065 (message "Debug (org-e-odt): Searching for OpenDocument schema files...")
2067 (lambda (schema-dir)
2069 (message "Debug (org-e-odt): Trying %s..." schema-dir
)
2070 (when (and (file-readable-p
2071 (expand-file-name "od-manifest-schema-v1.2-cs01.rnc"
2074 (expand-file-name "od-schema-v1.2-cs01.rnc"
2077 (expand-file-name "schemas.xml" schema-dir
)))
2078 (message "Debug (org-e-odt): Using schema files under %s"
2080 (throw 'schema-dir schema-dir
))))
2081 org-e-odt-schema-dir-list
)
2082 (message "Debug (org-e-odt): No OpenDocument schema files installed")
2085 "Directory that contains OpenDocument schema files.
2087 This directory contains:
2088 1. rnc files for OpenDocument schema
2089 2. a \"schemas.xml\" file that specifies locating rules needed
2090 for auto validation of OpenDocument XML files.
2092 Use the customize interface to set this variable. This ensures
2093 that `rng-schema-locating-files' is updated and auto-validation
2094 of OpenDocument XML takes place based on the value
2095 `rng-nxml-auto-validate-flag'.
2097 The default value of this variable varies depending on the
2098 version of org in use and is initialized from
2099 `org-e-odt-schema-dir-list'. The OASIS schema files are available
2100 only in the org's private git repository. It is *not* bundled
2101 with GNU ELPA tar or standard Emacs distribution."
2103 (const :tag
"Not set" nil
)
2104 (directory :tag
"Schema directory"))
2105 :group
'org-export-e-odt
2109 "Set `org-e-odt-schema-dir'.
2110 Also add it to `rng-schema-locating-files'."
2111 (let ((schema-dir value
))
2115 (expand-file-name "od-manifest-schema-v1.2-cs01.rnc" schema-dir
))
2117 (expand-file-name "od-schema-v1.2-cs01.rnc" schema-dir
))
2119 (expand-file-name "schemas.xml" schema-dir
)))
2122 (message "Error (org-e-odt): %s has no OpenDocument schema files"
2125 (when org-e-odt-schema-dir
2126 (eval-after-load 'rng-loc
2127 '(add-to-list 'rng-schema-locating-files
2128 (expand-file-name "schemas.xml"
2129 org-e-odt-schema-dir
))))))
2131 (defcustom org-e-odt-content-template-file nil
2132 "Template file for \"content.xml\".
2133 The exporter embeds the exported content just before
2134 \"</office:text>\" element.
2136 If unspecified, the file named \"OrgOdtContentTemplate.xml\"
2137 under `org-e-odt-styles-dir' is used."
2139 :group
'org-export-e-odt
2142 (defcustom org-e-odt-styles-file nil
2143 "Default styles file for use with ODT export.
2144 Valid values are one of:
2146 2. path to a styles.xml file
2147 3. path to a *.odt or a *.ott file
2148 4. list of the form (ODT-OR-OTT-FILE (FILE-MEMBER-1 FILE-MEMBER-2
2151 In case of option 1, an in-built styles.xml is used. See
2152 `org-e-odt-styles-dir' for more information.
2154 In case of option 3, the specified file is unzipped and the
2155 styles.xml embedded therein is used.
2157 In case of option 4, the specified ODT-OR-OTT-FILE is unzipped
2158 and FILE-MEMBER-1, FILE-MEMBER-2 etc are copied in to the
2159 generated odt file. Use relative path for specifying the
2160 FILE-MEMBERS. styles.xml must be specified as one of the
2163 Use options 1, 2 or 3 only if styles.xml alone suffices for
2164 achieving the desired formatting. Use option 4, if the styles.xml
2165 references additional files like header and footer images for
2166 achieving the desired formatting.
2168 Use \"#+ODT_STYLES_FILE: ...\" directive to set this variable on
2169 a per-file basis. For example,
2171 #+ODT_STYLES_FILE: \"/path/to/styles.xml\" or
2172 #+ODT_STYLES_FILE: (\"/path/to/file.ott\" (\"styles.xml\" \"image/hdr.png\"))."
2173 :group
'org-export-e-odt
2177 (const :tag
"Factory settings" nil
)
2178 (file :must-match t
:tag
"styles.xml")
2179 (file :must-match t
:tag
"ODT or OTT file")
2180 (list :tag
"ODT or OTT file + Members"
2181 (file :must-match t
:tag
"ODF Text or Text Template file")
2182 (cons :tag
"Members"
2183 (file :tag
" Member" "styles.xml")
2184 (repeat (file :tag
"Member"))))))
2187 (defcustom org-e-odt-inline-image-extensions
2188 '("png" "jpeg" "jpg" "gif")
2189 "Extensions of image files that can be inlined into HTML."
2190 :type
'(repeat (string :tag
"Extension"))
2191 :group
'org-export-e-odt
2194 (defcustom org-e-odt-pixels-per-inch display-pixels-per-inch
2195 "Scaling factor for converting images pixels to inches.
2196 Use this for sizing of embedded images. See Info node `(org)
2197 Images in ODT export' for more information."
2199 :group
'org-export-e-odt
2202 (defcustom org-e-odt-create-custom-styles-for-srcblocks t
2203 "Whether custom styles for colorized source blocks be automatically created.
2204 When this option is turned on, the exporter creates custom styles
2205 for source blocks based on the advice of `htmlfontify'. Creation
2206 of custom styles happen as part of `org-e-odt-hfy-face-to-css'.
2208 When this option is turned off exporter does not create such
2211 Use the latter option if you do not want the custom styles to be
2212 based on your current display settings. It is necessary that the
2213 styles.xml already contains needed styles for colorizing to work.
2215 This variable is effective only if
2216 `org-e-odt-fontify-srcblocks' is turned on."
2217 :group
'org-export-e-odt
2221 (defcustom org-e-odt-preferred-output-format nil
2222 "Automatically post-process to this format after exporting to \"odt\".
2223 Interactive commands `org-export-as-e-odt' and
2224 `org-export-as-e-odt-and-open' export first to \"odt\" format and
2225 then use `org-e-odt-convert-process' to convert the
2226 resulting document to this format. During customization of this
2227 variable, the list of valid values are populated based on
2228 `org-e-odt-convert-capabilities'."
2229 :group
'org-export-e-odt
2231 :type
'(choice :convert-widget
2233 (apply 'widget-convert
(widget-type w
)
2234 (eval (car (widget-get w
:args
)))))
2235 `((const :tag
"None" nil
)
2236 ,@(mapcar (lambda (c)
2237 `(const :tag
,c
,c
))
2238 (org-e-odt-reachable-formats "odt")))))
2240 (defcustom org-e-odt-table-styles
2241 '(("OrgEquation" "OrgEquation"
2242 ((use-first-column-styles . t
)
2243 (use-last-column-styles . t
))))
2244 "Specify how Table Styles should be derived from a Table Template.
2245 This is a list where each element is of the
2246 form (TABLE-STYLE-NAME TABLE-TEMPLATE-NAME TABLE-CELL-OPTIONS).
2248 TABLE-STYLE-NAME is the style associated with the table through
2249 `org-e-odt-table-style'.
2251 TABLE-TEMPLATE-NAME is a set of - upto 9 - automatic
2252 TABLE-CELL-STYLE-NAMEs and PARAGRAPH-STYLE-NAMEs (as defined
2253 below) that is included in
2254 `org-e-odt-content-template-file'.
2256 TABLE-CELL-STYLE-NAME := TABLE-TEMPLATE-NAME + TABLE-CELL-TYPE +
2258 PARAGRAPH-STYLE-NAME := TABLE-TEMPLATE-NAME + TABLE-CELL-TYPE +
2260 TABLE-CELL-TYPE := \"FirstRow\" | \"LastColumn\" |
2261 \"FirstRow\" | \"LastRow\" |
2262 \"EvenRow\" | \"OddRow\" |
2263 \"EvenColumn\" | \"OddColumn\" | \"\"
2264 where \"+\" above denotes string concatenation.
2266 TABLE-CELL-OPTIONS is an alist where each element is of the
2267 form (TABLE-CELL-STYLE-SELECTOR . ON-OR-OFF).
2268 TABLE-CELL-STYLE-SELECTOR := `use-first-row-styles' |
2269 `use-last-row-styles' |
2270 `use-first-column-styles' |
2271 `use-last-column-styles' |
2272 `use-banding-rows-styles' |
2273 `use-banding-columns-styles' |
2274 `use-first-row-styles'
2275 ON-OR-OFF := `t' | `nil'
2277 For example, with the following configuration
2279 \(setq org-e-odt-table-styles
2280 '\(\(\"TableWithHeaderRowsAndColumns\" \"Custom\"
2281 \(\(use-first-row-styles . t\)
2282 \(use-first-column-styles . t\)\)\)
2283 \(\"TableWithHeaderColumns\" \"Custom\"
2284 \(\(use-first-column-styles . t\)\)\)\)\)
2286 1. A table associated with \"TableWithHeaderRowsAndColumns\"
2287 style will use the following table-cell styles -
2288 \"CustomFirstRowTableCell\", \"CustomFirstColumnTableCell\",
2289 \"CustomTableCell\" and the following paragraph styles
2290 \"CustomFirstRowTableParagraph\",
2291 \"CustomFirstColumnTableParagraph\", \"CustomTableParagraph\"
2294 2. A table associated with \"TableWithHeaderColumns\" style will
2295 use the following table-cell styles -
2296 \"CustomFirstColumnTableCell\", \"CustomTableCell\" and the
2297 following paragraph styles
2298 \"CustomFirstColumnTableParagraph\", \"CustomTableParagraph\"
2301 Note that TABLE-TEMPLATE-NAME corresponds to the
2302 \"<table:table-template>\" elements contained within
2303 \"<office:styles>\". The entries (TABLE-STYLE-NAME
2304 TABLE-TEMPLATE-NAME TABLE-CELL-OPTIONS) correspond to
2305 \"table:template-name\" and \"table:use-first-row-styles\" etc
2306 attributes of \"<table:table>\" element. Refer ODF-1.2
2307 specification for more information. Also consult the
2308 implementation filed under `org-e-odt-get-table-cell-styles'.
2310 The TABLE-STYLE-NAME \"OrgEquation\" is used internally for
2311 formatting of numbered display equations. Do not delete this
2312 style from the list."
2313 :group
'org-export-e-odt
2316 (const :tag
"None" nil
)
2317 (repeat :tag
"Table Styles"
2318 (list :tag
"Table Style Specification"
2319 (string :tag
"Table Style Name")
2320 (string :tag
"Table Template Name")
2321 (alist :options
(use-first-row-styles
2323 use-first-column-styles
2324 use-last-column-styles
2325 use-banding-rows-styles
2326 use-banding-columns-styles
)
2328 :value-type
(const :tag
"True" t
))))))
2329 (defcustom org-e-odt-fontify-srcblocks t
2330 "Specify whether or not source blocks need to be fontified.
2331 Turn this option on if you want to colorize the source code
2332 blocks in the exported file. For colorization to work, you need
2333 to make available an enhanced version of `htmlfontify' library."
2335 :group
'org-export-e-odt
2338 (defcustom org-e-odt-prettify-xml t
; FIXME
2339 "Specify whether or not the xml output should be prettified.
2340 When this option is turned on, `indent-region' is run on all
2341 component xml buffers before they are saved. Turn this off for
2342 regular use. Turn this on if you need to examine the xml
2344 :group
'org-export-e-odt
2348 (defcustom org-e-odt-convert-processes
2350 "soffice --headless --convert-to %f%x --outdir %d %i")
2352 "unoconv -f %f -o %d %i"))
2353 "Specify a list of document converters and their usage.
2354 The converters in this list are offered as choices while
2355 customizing `org-e-odt-convert-process'.
2357 This variable is a list where each element is of the
2358 form (CONVERTER-NAME CONVERTER-CMD). CONVERTER-NAME is the name
2359 of the converter. CONVERTER-CMD is the shell command for the
2360 converter and can contain format specifiers. These format
2361 specifiers are interpreted as below:
2363 %i input file name in full
2364 %I input file name as a URL
2365 %f format of the output file
2366 %o output file name in full
2367 %O output file name as a URL
2368 %d output dir in full
2369 %D output dir as a URL.
2370 %x extra options as set in `org-e-odt-convert-capabilities'."
2371 :group
'org-export-e-odt
2375 (const :tag
"None" nil
)
2376 (alist :tag
"Converters"
2377 :key-type
(string :tag
"Converter Name")
2378 :value-type
(group (string :tag
"Command line")))))
2380 (defcustom org-e-odt-convert-process
"LibreOffice"
2381 "Use this converter to convert from \"odt\" format to other formats.
2382 During customization, the list of converter names are populated
2383 from `org-e-odt-convert-processes'."
2384 :group
'org-export-e-odt
2386 :type
'(choice :convert-widget
2388 (apply 'widget-convert
(widget-type w
)
2389 (eval (car (widget-get w
:args
)))))
2390 `((const :tag
"None" nil
)
2391 ,@(mapcar (lambda (c)
2392 `(const :tag
,(car c
) ,(car c
)))
2393 org-e-odt-convert-processes
))))
2395 (defcustom org-e-odt-convert-capabilities
2397 ("odt" "ott" "doc" "rtf" "docx")
2398 (("pdf" "pdf") ("odt" "odt") ("rtf" "rtf") ("ott" "ott")
2399 ("doc" "doc" ":\"MS Word 97\"") ("docx" "docx") ("html" "html")))
2402 (("pdf" "pdf") ("odt" "odt") ("html" "html")))
2404 ("ods" "ots" "xls" "csv" "xlsx")
2405 (("pdf" "pdf") ("ots" "ots") ("html" "html") ("csv" "csv") ("ods" "ods")
2406 ("xls" "xls") ("xlsx" "xlsx")))
2408 ("odp" "otp" "ppt" "pptx")
2409 (("pdf" "pdf") ("swf" "swf") ("odp" "odp") ("otp" "otp") ("ppt" "ppt")
2410 ("pptx" "pptx") ("odg" "odg"))))
2411 "Specify input and output formats of `org-e-odt-convert-process'.
2412 More correctly, specify the set of input and output formats that
2413 the user is actually interested in.
2415 This variable is an alist where each element is of the
2416 form (DOCUMENT-CLASS INPUT-FMT-LIST OUTPUT-FMT-ALIST).
2417 INPUT-FMT-LIST is a list of INPUT-FMTs. OUTPUT-FMT-ALIST is an
2418 alist where each element is of the form (OUTPUT-FMT
2419 OUTPUT-FILE-EXTENSION EXTRA-OPTIONS).
2421 The variable is interpreted as follows:
2422 `org-e-odt-convert-process' can take any document that is in
2423 INPUT-FMT-LIST and produce any document that is in the
2424 OUTPUT-FMT-LIST. A document converted to OUTPUT-FMT will have
2425 OUTPUT-FILE-EXTENSION as the file name extension. OUTPUT-FMT
2426 serves dual purposes:
2427 - It is used for populating completion candidates during
2428 `org-e-odt-convert' commands.
2429 - It is used as the value of \"%f\" specifier in
2430 `org-e-odt-convert-process'.
2432 EXTRA-OPTIONS is used as the value of \"%x\" specifier in
2433 `org-e-odt-convert-process'.
2435 DOCUMENT-CLASS is used to group a set of file formats in
2436 INPUT-FMT-LIST in to a single class.
2438 Note that this variable inherently captures how LibreOffice based
2439 converters work. LibreOffice maps documents of various formats
2440 to classes like Text, Web, Spreadsheet, Presentation etc and
2441 allow document of a given class (irrespective of it's source
2442 format) to be converted to any of the export formats associated
2445 See default setting of this variable for an typical
2447 :group
'org-export-e-odt
2451 (const :tag
"None" nil
)
2452 (alist :tag
"Capabilities"
2453 :key-type
(string :tag
"Document Class")
2455 (group (repeat :tag
"Input formats" (string :tag
"Input format"))
2456 (alist :tag
"Output formats"
2457 :key-type
(string :tag
"Output format")
2459 (group (string :tag
"Output file extension")
2461 (const :tag
"None" nil
)
2462 (string :tag
"Extra options"))))))))
2469 ;;;; Document Header (Styles)
2471 ;;;; Document Header (Scripts)
2473 ;;;; Document Header (Mathjax)
2486 ;;;; Statistics Cookie
2506 ;;;; Horizontal Rule
2507 ;;;; Inline Babel Call
2508 ;;;; Inline Src Block
2512 ;;;; Latex Environment
2521 ;;;; Property Drawer
2547 ;;; User Configurable Variables (MAYBE)
2555 (defcustom org-e-odt-format-headline-function nil
2556 "Function to format headline text.
2558 This function will be called with 5 arguments:
2559 TODO the todo keyword \(string or nil\).
2560 TODO-TYPE the type of todo \(symbol: `todo', `done', nil\)
2561 PRIORITY the priority of the headline \(integer or nil\)
2562 TEXT the main headline text \(string\).
2563 TAGS the tags string, separated with colons \(string or nil\).
2565 The function result will be used in the section format string.
2567 As an example, one could set the variable to the following, in
2568 order to reproduce the default set-up:
2570 \(defun org-e-odt-format-headline \(todo todo-type priority text tags\)
2571 \"Default format function for an headline.\"
2572 \(concat \(when todo
2573 \(format \"\\\\textbf{\\\\textsc{\\\\textsf{%s}}} \" todo\)\)
2575 \(format \"\\\\framebox{\\\\#%c} \" priority\)\)
2577 \(when tags \(format \"\\\\hfill{}\\\\textsc{%s}\" tags\)\)\)\)"
2578 :group
'org-export-e-odt
2585 (defcustom org-e-odt-active-timestamp-format
"\\textit{%s}"
2586 "A printf format string to be applied to active time-stamps."
2587 :group
'org-export-e-odt
2590 (defcustom org-e-odt-inactive-timestamp-format
"\\textit{%s}"
2591 "A printf format string to be applied to inactive time-stamps."
2592 :group
'org-export-e-odt
2595 (defcustom org-e-odt-diary-timestamp-format
"\\textit{%s}"
2596 "A printf format string to be applied to diary time-stamps."
2597 :group
'org-export-e-odt
2603 (defcustom org-e-odt-inline-image-rules
2604 '(("file" .
"\\.\\(jpeg\\|jpg\\|png\\|gif\\)\\'"))
2605 "Rules characterizing image files that can be inlined into HTML.
2607 A rule consists in an association whose key is the type of link
2608 to consider, and value is a regexp that will be matched against
2611 Note that, by default, the image extension *actually* allowed
2612 depend on the way the HTML file is processed. When used with
2613 pdflatex, pdf, jpg and png images are OK. When processing
2614 through dvi to Postscript, only ps and eps are allowed. The
2615 default we use here encompasses both."
2616 :group
'org-export-e-odt
2617 :type
'(alist :key-type
(string :tag
"Type")
2618 :value-type
(regexp :tag
"Path")))
2622 (defcustom org-e-odt-table-caption-above t
2623 "When non-nil, place caption string at the beginning of the table.
2624 Otherwise, place it near the end."
2625 :group
'org-export-e-odt
2630 (defcustom org-e-odt-format-drawer-function nil
2631 "Function called to format a drawer in HTML code.
2633 The function must accept two parameters:
2634 NAME the drawer name, like \"LOGBOOK\"
2635 CONTENTS the contents of the drawer.
2637 The function should return the string to be exported.
2639 For example, the variable could be set to the following function
2640 in order to mimic default behaviour:
2642 \(defun org-e-odt-format-drawer-default \(name contents\)
2643 \"Format a drawer element for HTML export.\"
2645 :group
'org-export-e-odt
2651 (defcustom org-e-odt-format-inlinetask-function nil
2652 "Function called to format an inlinetask in HTML code.
2654 The function must accept six parameters:
2655 TODO the todo keyword, as a string
2656 TODO-TYPE the todo type, a symbol among `todo', `done' and nil.
2657 PRIORITY the inlinetask priority, as a string
2658 NAME the inlinetask name, as a string.
2659 TAGS the inlinetask tags, as a string.
2660 CONTENTS the contents of the inlinetask, as a string.
2662 The function should return the string to be exported.
2664 For example, the variable could be set to the following function
2665 in order to mimic default behaviour:
2667 \(defun org-e-odt-format-inlinetask \(todo type priority name tags contents\)
2668 \"Format an inline task element for HTML export.\"
2669 \(let \(\(full-title
2672 \(format \"\\\\textbf{\\\\textsf{\\\\textsc{%s}}} \" todo\)\)
2673 \(when priority \(format \"\\\\framebox{\\\\#%c} \" priority\)\)
2675 \(when tags \(format \"\\\\hfill{}\\\\textsc{%s}\" tags\)\)\)\)\)
2676 \(format \(concat \"\\\\begin{center}\\n\"
2678 \"\\\\begin{minipage}[c]{.6\\\\textwidth}\\n\"
2680 \"\\\\rule[.8em]{\\\\textwidth}{2pt}\\n\\n\"
2682 \"\\\\end{minipage}}\"
2683 \"\\\\end{center}\"\)
2684 full-title contents\)\)"
2685 :group
'org-export-e-odt
2693 (defcustom org-e-odt-quotes
2694 '(("fr" ("\\(\\s-\\|[[(]\\)\"" .
"«~") ("\\(\\S-\\)\"" .
"~»") ("\\(\\s-\\|(\\)'" .
"'"))
2695 ("en" ("\\(\\s-\\|[[(]\\)\"" .
"``") ("\\(\\S-\\)\"" .
"''") ("\\(\\s-\\|(\\)'" .
"`")))
2696 "Alist for quotes to use when converting english double-quotes.
2698 The CAR of each item in this alist is the language code.
2699 The CDR of each item in this alist is a list of three CONS:
2700 - the first CONS defines the opening quote;
2701 - the second CONS defines the closing quote;
2702 - the last CONS defines single quotes.
2704 For each item in a CONS, the first string is a regexp
2705 for allowed characters before/after the quote, the second
2706 string defines the replacement string for this quote."
2707 :group
'org-export-e-odt
2709 (cons :tag
"Opening quote"
2710 (string :tag
"Regexp for char before")
2711 (string :tag
"Replacement quote "))
2712 (cons :tag
"Closing quote"
2713 (string :tag
"Regexp for char after ")
2714 (string :tag
"Replacement quote "))
2715 (cons :tag
"Single quote"
2716 (string :tag
"Regexp for char before")
2717 (string :tag
"Replacement quote "))))
2724 ;;; Internal Functions (HTML)
2726 ;; (defun org-e-odt-format-inline-image (path &optional caption label attr)
2727 ;; ;; FIXME: alt text missing here?
2728 ;; (let ((inline-image (format "<img src=\"%s\" alt=\"%s\"/>"
2729 ;; path (file-name-nondirectory path))))
2730 ;; (if (not label) inline-image
2731 ;; (org-e-odt-format-section inline-image "figure" label))))
2735 (defun org-e-odt-bibliography ()
2736 "Find bibliography, cut it out and return it."
2738 (let (beg end
(cnt 1) bib
)
2740 (goto-char (point-min))
2741 (when (re-search-forward
2742 "^[ \t]*<div \\(id\\|class\\)=\"bibliography\"" nil t
)
2743 (setq beg
(match-beginning 0))
2744 (while (re-search-forward "</?div\\>" nil t
)
2745 (setq cnt
(+ cnt
(if (string= (match-string 0) "<div") +1 -
1)))
2747 (and (looking-at ">") (forward-char 1))
2748 (setq bib
(buffer-substring beg
(point)))
2749 (delete-region beg
(point))
2750 (throw 'exit bib
))))
2755 (defun org-e-odt-format-table (lines olines
)
2756 (let ((org-e-odt-format-table-no-css nil
))
2757 (org-lparse-format-table lines olines
)))
2759 (defun org-e-odt-splice-attributes (tag attributes
)
2760 "Read attributes in string ATTRIBUTES, add and replace in HTML tag TAG."
2761 (if (not attributes
)
2763 (let (oldatt newatt
)
2764 (setq oldatt
(org-extract-attributes-from-string tag
)
2766 newatt
(cdr (org-extract-attributes-from-string attributes
)))
2768 (setq oldatt
(plist-put oldatt
(pop newatt
) (pop newatt
))))
2769 (if (string-match ">" tag
)
2771 (replace-match (concat (org-attributes-to-string oldatt
) ">")
2775 (defun org-export-splice-style (style extra
)
2776 "Splice EXTRA into STYLE, just before \"</style>\"."
2777 (if (and (stringp extra
)
2778 (string-match "\\S-" extra
)
2779 (string-match "</style>" style
))
2780 (concat (substring style
0 (match-beginning 0))
2782 (substring style
(match-beginning 0)))
2785 (defun org-e-odt-toc-entry-formatter
2786 (level snumber todo todo-type priority
2787 headline tags target extra-targets extra-class
)
2788 (org-e-odt-format-toc-entry snumber todo headline tags target
))
2790 (defun org-e-odt-make-string (n string
)
2791 (let (out) (dotimes (i n out
) (setq out
(concat string out
)))))
2793 (defun org-e-odt-toc-text (toc-entries)
2794 (let* ((prev-level (1- (nth 1 (car toc-entries
))))
2795 (start-level prev-level
))
2798 (let ((headline (nth 0 entry
))
2799 (level (nth 1 entry
)))
2800 (prog1 (org-e-odt-format-toc-item headline level prev-level
)
2801 (setq prev-level level
))))
2804 (defun* org-e-odt-format-toc-headline
2805 (todo todo-type priority text tags
2806 &key level section-number headline-label
&allow-other-keys
)
2809 (and org-export-with-section-numbers
2810 (concat section-number
". "))
2814 (org-e-odt-format-spaces 3)
2815 (org-e-odt-format-fontify tags
"tag")))))
2817 (setq text
(org-e-odt-format-fontify text
"todo")))
2819 (let ((org-e-odt-suppress-xref t
))
2820 (org-e-odt-format-link text
(concat "#" headline-label
))))
2822 (defun org-e-odt-toc (depth info
)
2823 (assert (wholenump depth
))
2824 (let* ((headlines (org-export-collect-headlines info depth
))
2826 (loop for headline in headlines collect
2827 (list (org-e-odt-format-headline--wrap
2828 headline info
'org-e-odt-format-toc-headline
)
2829 (org-export-get-relative-level headline info
)))))
2831 (let* ((lang-specific-heading "Table of Contents")) ; FIXME
2833 (org-e-odt-begin-toc lang-specific-heading depth
)
2834 (org-e-odt-toc-text toc-entries
)
2835 (org-e-odt-end-toc))))))
2837 (defun org-e-odt-begin-outline (level1 snumber title tags
2838 target extra-targets extra-class
)
2839 (let* ((class (format "outline-%d" level1
))
2840 (class (if extra-class
(concat class
" " extra-class
) class
))
2841 (id (format "outline-container-%s"
2842 (org-lparse-suffix-from-snumber snumber
)))
2843 (extra (concat (when id
(format " id=\"%s\"" id
))
2844 (when class
(format " class=\"%s\"" class
)))))
2845 (org-lparse-insert-tag "<div%s>" extra
)
2847 (org-lparse-format 'HEADING
2849 'HEADLINE title extra-targets tags snumber level1
)
2852 (defun org-e-odt-end-outline ()
2853 (org-lparse-insert-tag "</div>"))
2855 (defun org-e-odt-suffix-from-snumber (snumber)
2856 (let* ((snu (replace-regexp-in-string "\\." "-" snumber
))
2857 (href (cdr (assoc (concat "sec-" snu
)
2858 org-export-preferred-target-alist
))))
2859 (org-solidify-link-text (or href snu
))))
2861 (defun org-e-odt-format-outline (contents level1 snumber title
2862 tags target extra-targets extra-class
)
2865 ;; (defun org-e-odt-format-line (line)
2866 ;; (case org-lparse-dyn-current-environment
2867 ;; ((quote fixedwidth) (concat (org-e-odt-encode-plain-text line) "\n"))
2868 ;; (t (concat line "\n"))))
2870 (defun org-e-odt-fix-class-name (kwd) ; audit callers of this function
2871 "Turn todo keyword into a valid class name.
2872 Replaces invalid characters with \"_\"."
2874 (while (string-match "[^a-zA-Z0-9_]" kwd
)
2875 (setq kwd
(replace-match "_" t t kwd
))))
2878 (defun org-e-odt-format-internal-link (text href
&optional extra
)
2879 (org-e-odt-format-link text
(concat "#" href
) extra
))
2881 (defun org-e-odt-format-extra-targets (extra-targets)
2882 (if (not extra-targets
) ""
2883 (mapconcat (lambda (x)
2885 (setq x
(org-solidify-link-text
2886 (if (org-uuidgen-p x
) (concat "ID-" x
) x
)))
2887 (org-e-odt-format-anchor "" x
))) extra-targets
"")))
2889 (defun org-e-odt-format-org-tags (tags)
2891 (org-e-odt-format-fontify
2894 (org-e-odt-format-fontify
2895 x
(concat "" ;; org-e-odt-tag-class-prefix
2896 (org-e-odt-fix-class-name x
))))
2897 (org-split-string tags
":")
2898 (org-e-odt-format-spaces 1)) "tag")))
2900 (defun org-e-odt-format-section-number (&optional snumber level
)
2902 (and nil org-export-with-section-numbers
2903 ;; (not org-lparse-body-only)
2905 (org-e-odt-format-fontify snumber
(format "section-number-%d" level
))))
2907 ;; (defun org-e-odt-format-headline (title extra-targets tags
2908 ;; &optional snumber level)
2910 ;; (org-e-odt-format-extra-targets extra-targets)
2911 ;; (concat (org-e-odt-format-section-number snumber level) " ")
2913 ;; (and tags (concat (org-e-odt-format-spaces 3)
2914 ;; (org-e-odt-format-org-tags tags)))))
2916 (defun org-e-odt-get-coding-system-for-write ()
2917 (or org-e-odt-coding-system
2918 (and (boundp 'buffer-file-coding-system
) buffer-file-coding-system
)))
2920 (defun org-e-odt-get-coding-system-for-save ()
2921 (or org-e-odt-coding-system
2922 (and (boundp 'buffer-file-coding-system
) buffer-file-coding-system
)))
2924 ;; (defun org-e-odt-format-date (info)
2925 ;; (let ((date (plist-get info :date)))
2927 ;; ((and date (string-match "%" date))
2928 ;; (format-time-string date))
2930 ;; (t (format-time-string "%Y-%m-%d %T %Z")))))
2934 ;;; Internal Functions (Ngz)
2936 (defun org-e-odt--caption/label-string
(caption label info
)
2937 "Return caption and label HTML string for floats.
2939 CAPTION is a cons cell of secondary strings, the car being the
2940 standard caption and the cdr its short form. LABEL is a string
2941 representing the label. INFO is a plist holding contextual
2944 If there's no caption nor label, return the empty string.
2946 For non-floats, see `org-e-odt--wrap-label'."
2947 (setq label nil
) ;; FIXME
2949 (let ((label-str (if label
(format "\\label{%s}" label
) "")))
2951 ((and (not caption
) (not label
)) "")
2952 ((not caption
) (format "\\label{%s}\n" label
))
2953 ;; Option caption format with short name.
2955 (format "\\caption[%s]{%s%s}\n"
2956 (org-export-secondary-string (cdr caption
) 'e-odt info
)
2958 (org-export-secondary-string (car caption
) 'e-odt info
)))
2959 ;; Standard caption format.
2960 ;; (t (format "\\caption{%s%s}\n"
2962 ;; (org-export-secondary-string (car caption) 'e-odt info)))
2964 (t (org-export-secondary-string (car caption
) 'e-odt info
)))))
2966 (defun org-e-odt--find-verb-separator (s)
2967 "Return a character not used in string S.
2968 This is used to choose a separator for constructs like \\verb."
2969 (let ((ll "~,./?;':\"|!@#%^&-_=+abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ<>()[]{}"))
2970 (loop for c across ll
2971 when
(not (string-match (regexp-quote (char-to-string c
)) s
))
2972 return
(char-to-string c
))))
2974 (defun org-e-odt--quotation-marks (text info
)
2975 "Export quotation marks depending on language conventions.
2976 TEXT is a string containing quotation marks to be replaced. INFO
2977 is a plist used as a communication channel."
2980 (while (setq start
(string-match (car l
) text start
))
2981 (let ((new-quote (concat (match-string 1 text
) (cdr l
))))
2982 (setq text
(replace-match new-quote t t text
))))))
2983 (cdr (or (assoc (plist-get info
:language
) org-e-odt-quotes
)
2984 ;; Falls back on English.
2985 (assoc "en" org-e-odt-quotes
))))
2988 (defun org-e-odt--wrap-label (element output
)
2989 "Wrap label associated to ELEMENT around OUTPUT, if appropriate.
2990 This function shouldn't be used for floats. See
2991 `org-e-odt--caption/label-string'."
2992 ;; (let ((label (org-element-property :name element)))
2993 ;; (if (or (not output) (not label) (string= output "") (string= label ""))
2995 ;; (concat (format "\\label{%s}\n" label) output)))
3000 ;;; Transcode Helpers
3002 (defun* org-e-odt-format-headline
3003 (todo todo-type priority text tags
3004 &key level section-number headline-label
&allow-other-keys
)
3005 (concat (org-e-odt-todo todo
) (and todo
" ") text
3006 (and tags
(org-e-odt-format-spaces 3))
3007 (and tags
(org-e-odt-format-org-tags tags
))))
3011 (defun org-e-odt-htmlfontify-string (line)
3012 (let* ((hfy-html-quote-regex "\\([<\"&> ]\\)")
3013 (hfy-html-quote-map '(("\"" """)
3018 (" " "<text:tab/>")))
3019 (hfy-face-to-css 'org-e-odt-hfy-face-to-css
)
3020 (hfy-optimisations-1 (copy-seq hfy-optimisations
))
3021 (hfy-optimisations (add-to-list 'hfy-optimisations-1
3023 (hfy-begin-span-handler
3024 (lambda (style text-block text-id text-begins-block-p
)
3025 (insert (format "<text:span text:style-name=\"%s\">" style
))))
3026 (hfy-end-span-handler (lambda nil
(insert "</text:span>"))))
3027 (htmlfontify-string line
)))
3029 (defun org-e-odt-do-format-code
3030 (code &optional lang refs retain-labels num-start
)
3031 (let* ((lang (or (assoc-default lang org-src-lang-modes
) lang
))
3032 (lang-mode (and lang
(intern (format "%s-mode" lang
))))
3033 (code-lines (org-split-string code
"\n"))
3034 (code-length (length code-lines
))
3035 (use-htmlfontify-p (and (functionp lang-mode
)
3036 org-e-odt-fontify-srcblocks
3037 (require 'htmlfontify nil t
)
3038 (fboundp 'htmlfontify-string
)))
3039 (code (if (not use-htmlfontify-p
) code
3043 (font-lock-fontify-buffer)
3045 (fontifier (if use-htmlfontify-p
'org-e-odt-htmlfontify-string
3046 'org-e-odt-encode-plain-text
))
3047 (par-style (if use-htmlfontify-p
"OrgSrcBlock"
3048 "OrgFixedWidthBlock"))
3050 (assert (= code-length
(length (org-split-string code
"\n"))))
3052 (org-export-format-code
3054 (lambda (loc line-num ref
)
3056 (concat par-style
(and (= (incf i
) code-length
) "LastLine")))
3058 (setq loc
(concat loc
(and ref retain-labels
(format " (%s)" ref
))))
3059 (setq loc
(funcall fontifier loc
))
3061 (setq loc
(org-e-odt-format-target loc
(concat "coderef-" ref
))))
3062 (setq loc
(org-e-odt-format-stylized-paragraph par-style loc
))
3063 (if (not line-num
) loc
3064 (org-e-odt-format-tags
3065 '("<text:list-item>" .
"</text:list-item>") loc
)))
3068 ((not num-start
) code
)
3069 ((equal num-start
0)
3070 (org-e-odt-format-tags
3071 '("<text:list text:style-name=\"OrgSrcBlockNumberedLine\"%s>"
3072 .
"</text:list>") code
" text:continue-numbering=\"false\""))
3073 (t (org-e-odt-format-tags
3074 '("<text:list text:style-name=\"OrgSrcBlockNumberedLine\"%s>"
3075 .
"</text:list>") code
" text:continue-numbering=\"true\"")))))
3077 (defun org-e-odt-format-code (element info
)
3078 (let* ((lang (org-element-property :language element
))
3079 ;; Extract code and references.
3080 (code-info (org-export-unravel-code element
))
3081 (code (car code-info
))
3082 (refs (cdr code-info
))
3083 ;; Does the src block contain labels?
3084 (retain-labels (org-element-property :retain-labels element
))
3085 ;; Does it have line numbers?
3086 (num-start (case (org-element-property :number-lines element
)
3087 (continued (org-export-get-loc element info
))
3089 (org-e-odt-do-format-code code lang refs retain-labels num-start
)))
3095 (defun org-e-odt-template (contents info
)
3096 "Return complete document string after HTML conversion.
3097 CONTENTS is the transcoded contents string. RAW-DATA is the
3098 original parsed data. INFO is a plist holding export options."
3100 (org-e-odt-update-meta-file info
)
3102 (insert-file-contents
3103 (or org-e-odt-content-template-file
3104 (expand-file-name "OrgOdtContentTemplate.xml"
3105 org-e-odt-styles-dir
)))
3106 (goto-char (point-min))
3107 (re-search-forward "</office:text>" nil nil
)
3108 (goto-char (match-beginning 0))
3111 (insert (org-e-odt-format-preamble info
))
3112 ;; Table of Contents
3113 (let ((depth (plist-get info
:with-toc
)))
3114 (when (wholenump depth
) (insert (org-e-odt-toc depth info
))))
3116 ;; Copy styles.xml. Also dump htmlfontify styles, if there is any.
3117 (org-e-odt-update-styles-file info
)
3119 ;; Update styles.xml - take care of outline numbering
3120 (with-current-buffer
3121 (find-file-noselect (expand-file-name "styles.xml") t
)
3122 ;; Don't make automatic backup of styles.xml file. This setting
3123 ;; prevents the backed-up styles.xml file from being zipped in to
3124 ;; odt file. This is more of a hackish fix. Better alternative
3125 ;; would be to fix the zip command so that the output odt file
3126 ;; includes only the needed files and excludes any auto-generated
3127 ;; extra files like backups and auto-saves etc etc. Note that
3128 ;; currently the zip command zips up the entire temp directory so
3129 ;; that any auto-generated files created under the hood ends up in
3130 ;; the resulting odt file.
3131 (set (make-local-variable 'backup-inhibited
) t
)
3132 (org-e-odt-configure-outline-numbering))
3136 (buffer-substring-no-properties (point-min) (point-max))))
3140 ;;; Transcode Functions
3144 (defun org-e-odt-center-block (center-block contents info
)
3145 "Transcode a CENTER-BLOCK element from Org to HTML.
3146 CONTENTS holds the contents of the block. INFO is a plist
3147 holding contextual information."
3148 (org-e-odt--wrap-label center-block contents
))
3153 ;; Comments are ignored.
3158 ;; Comment Blocks are ignored.
3163 (defun org-e-odt-drawer (drawer contents info
)
3164 "Transcode a DRAWER element from Org to HTML.
3165 CONTENTS holds the contents of the block. INFO is a plist
3166 holding contextual information."
3167 (let* ((name (org-element-property :drawer-name drawer
))
3168 (output (if (functionp org-e-odt-format-drawer-function
)
3169 (funcall org-e-odt-format-drawer-function
3171 ;; If there's no user defined function: simply
3172 ;; display contents of the drawer.
3174 (org-e-odt--wrap-label drawer output
)))
3179 (defun org-e-odt-dynamic-block (dynamic-block contents info
)
3180 "Transcode a DYNAMIC-BLOCK element from Org to HTML.
3181 CONTENTS holds the contents of the block. INFO is a plist
3182 holding contextual information. See
3184 (org-e-odt--wrap-label dynamic-block contents
))
3189 (defun org-e-odt-emphasis (emphasis contents info
)
3190 "Transcode EMPHASIS from Org to HTML.
3191 CONTENTS is the contents of the emphasized text. INFO is a plist
3192 holding contextual information.."
3193 ;; (format (cdr (assoc (org-element-property :marker emphasis)
3194 ;; org-e-odt-emphasis-alist))
3196 (org-e-odt-format-fontify
3197 contents
(cadr (assoc
3198 (org-element-property :marker emphasis
)
3209 (defun org-e-odt-entity (entity contents info
)
3210 "Transcode an ENTITY object from Org to HTML.
3211 CONTENTS are the definition itself. INFO is a plist holding
3212 contextual information."
3213 ;; (let ((ent (org-element-property :latex entity)))
3214 ;; (if (org-element-property :latex-math-p entity)
3215 ;; (format "$%s$" ent)
3217 (org-element-property :utf-8 entity
))
3222 (defun org-e-odt-example-block (example-block contents info
)
3223 "Transcode a EXAMPLE-BLOCK element from Org to HTML.
3224 CONTENTS is nil. INFO is a plist holding contextual information."
3225 (let* ((options (or (org-element-property :options example-block
) ""))
3226 (value (org-export-handle-code example-block info nil nil t
)))
3227 (org-e-odt--wrap-label
3228 example-block
(org-e-odt-format-source-code-or-example value nil
))))
3233 (defun org-e-odt-export-snippet (export-snippet contents info
)
3234 "Transcode a EXPORT-SNIPPET object from Org to HTML.
3235 CONTENTS is nil. INFO is a plist holding contextual information."
3236 (when (eq (org-export-snippet-backend export-snippet
) 'e-odt
)
3237 (org-element-property :value export-snippet
)))
3242 (defun org-e-odt-export-block (export-block contents info
)
3243 "Transcode a EXPORT-BLOCK element from Org to HTML.
3244 CONTENTS is nil. INFO is a plist holding contextual information."
3245 (when (string= (org-element-property :type export-block
) "latex")
3246 (org-remove-indentation (org-element-property :value export-block
))))
3251 (defun org-e-odt-fixed-width (fixed-width contents info
)
3252 "Transcode a FIXED-WIDTH element from Org to HTML.
3253 CONTENTS is nil. INFO is a plist holding contextual information."
3254 (let* ((value (org-element-normalize-string
3255 (replace-regexp-in-string
3257 (org-element-property :value fixed-width
)))))
3258 (org-e-odt--wrap-label
3259 fixed-width
(org-e-odt-format-source-code-or-example value nil
))))
3262 ;;;; Footnote Definition
3264 ;; Footnote Definitions are ignored.
3267 ;;;; Footnote Reference
3269 (defun org-e-odt-footnote-def (raw info
) ; FIXME
3270 (if (equal (org-element-type raw
) 'org-data
)
3271 (org-trim (org-export-data raw
'e-odt info
)) ; fix paragraph
3273 (org-e-odt-format-stylized-paragraph
3274 'footnote
(org-trim (org-export-secondary-string raw
'e-odt info
)))))
3276 (defvar org-e-odt-footnote-separator
3277 (org-e-odt-format-fontify "," 'superscript
))
3279 (defun org-e-odt-footnote-reference (footnote-reference contents info
)
3280 "Transcode a FOOTNOTE-REFERENCE element from Org to HTML.
3281 CONTENTS is nil. INFO is a plist holding contextual information."
3283 ;; Insert separator between two footnotes in a row.
3284 (let ((prev (org-export-get-previous-element footnote-reference info
)))
3285 (when (eq (org-element-type prev
) 'footnote-reference
)
3286 org-e-odt-footnote-separator
))
3288 ((not (org-export-footnote-first-reference-p footnote-reference info
))
3289 (let* ((n (org-export-get-footnote-number footnote-reference info
)))
3290 (org-e-odt-format-footnote-reference n
"IGNORED" 100)))
3291 ;; Inline definitions are secondary strings.
3292 ((eq (org-element-property :type footnote-reference
) 'inline
)
3293 (let* ((raw (org-export-get-footnote-definition footnote-reference info
))
3294 (n (org-export-get-footnote-number footnote-reference info
))
3295 (def (org-e-odt-footnote-def raw info
)))
3296 (org-e-odt-format-footnote-reference n def
1)))
3297 ;; Non-inline footnotes definitions are full Org data.
3299 (let* ((raw (org-export-get-footnote-definition footnote-reference info
))
3300 (n (org-export-get-footnote-number footnote-reference info
))
3301 (def (org-e-odt-footnote-def raw info
)))
3302 (org-e-odt-format-footnote-reference n def
1))))))
3307 (defun org-e-odt-todo (todo)
3309 (org-e-odt-format-fontify
3311 "" ; org-e-odt-todo-kwd-class-prefix
3312 (org-e-odt-fix-class-name todo
))
3313 (list (if (member todo org-done-keywords
) "done" "todo")
3316 (defun org-e-odt-format-headline--wrap (headline info
3317 &optional format-function
3319 "Transcode an HEADLINE element from Org to ODT.
3320 CONTENTS holds the contents of the headline. INFO is a plist
3321 holding contextual information."
3322 (let* ((level (+ (org-export-get-relative-level headline info
)))
3323 (headline-number (org-export-get-headline-number headline info
))
3324 (section-number (and (org-export-numbered-headline-p headline info
)
3325 (mapconcat 'number-to-string
3326 headline-number
".")))
3327 (todo (and (plist-get info
:with-todo-keywords
)
3328 (let ((todo (org-element-property
3329 :todo-keyword headline
)))
3331 (org-export-secondary-string todo
'e-odt info
)))))
3332 (todo-type (and todo
(org-element-property :todo-type headline
)))
3333 (priority (and (plist-get info
:with-priority
)
3334 (org-element-property :priority headline
)))
3335 (text (org-export-secondary-string
3336 (org-element-property :title headline
) 'e-odt info
))
3337 (tags (and (plist-get info
:with-tags
)
3338 (org-element-property :tags headline
)))
3339 (headline-label (concat "sec-" (mapconcat 'number-to-string
3340 headline-number
"-")))
3341 (format-function (cond
3342 ((functionp format-function
) format-function
)
3343 ((functionp org-e-odt-format-headline-function
)
3345 (lambda (todo todo-type priority text tags
3347 (funcall org-e-odt-format-headline-function
3348 todo todo-type priority text tags
))))
3349 (t 'org-e-odt-format-headline
))))
3350 (apply format-function
3351 todo todo-type priority text tags
3352 :headline-label headline-label
:level level
3353 :section-number section-number extra-keys
)))
3355 (defun org-e-odt-headline (headline contents info
)
3356 "Transcode an HEADLINE element from Org to HTML.
3357 CONTENTS holds the contents of the headline. INFO is a plist
3358 holding contextual information."
3359 (let* ((numberedp (org-export-numbered-headline-p headline info
))
3360 ;; Get level relative to current parsed data.
3361 (level (org-export-get-relative-level headline info
))
3362 (text (org-export-secondary-string
3363 (org-element-property :title headline
) 'e-odt info
))
3364 ;; Create the headline text.
3365 (full-text (org-e-odt-format-headline--wrap headline info
)))
3367 ;; Case 1: This is a footnote section: ignore it.
3368 ((org-element-property :footnote-section-p headline
) nil
)
3369 ;; Case 2. This is a deep sub-tree: export it as a list item.
3370 ;; Also export as items headlines for which no section
3371 ;; format has been found.
3372 ((org-export-low-level-p headline info
) ; FIXME (or (not section-fmt))
3373 ;; Build the real contents of the sub-tree.
3374 (let* ((type (if numberedp
'unordered
'unordered
)) ; FIXME
3375 (itemized-body (org-e-odt-format-list-item
3376 contents type nil nil full-text
)))
3378 (and (org-export-first-sibling-p headline info
)
3379 (org-e-odt-begin-plain-list type
))
3381 (and (org-export-last-sibling-p headline info
)
3382 (org-e-odt-end-plain-list type
)))))
3383 ;; Case 3. Standard headline. Export it as a section.
3385 (let* ((extra-ids (list (org-element-property :custom-id headline
)
3386 (org-element-property :id headline
)))
3387 (extra-ids nil
) ; FIXME
3388 (id (concat "sec-" (mapconcat 'number-to-string
3389 (org-export-get-headline-number
3390 headline info
) "-"))))
3392 (org-e-odt-format-tags
3393 '("<text:h text:style-name=\"Heading_20_%s\" text:outline-level=\"%s\">" .
3395 (concat (org-e-odt-format-extra-targets extra-ids
)
3396 (if (not id
) full-text
(org-e-odt-format-target full-text id
) ))
3401 ;;;; Horizontal Rule
3403 (defun org-e-odt-horizontal-rule (horizontal-rule contents info
)
3404 "Transcode an HORIZONTAL-RULE object from Org to HTML.
3405 CONTENTS is nil. INFO is a plist holding contextual information."
3406 (let ((attr (mapconcat #'identity
3407 (org-element-property :attr_odt horizontal-rule
)
3409 (org-e-odt--wrap-label horizontal-rule
3410 (org-e-odt-format-horizontal-line))))
3413 ;;;; Inline Babel Call
3415 ;; Inline Babel Calls are ignored.
3418 ;;;; Inline Src Block
3420 (defun org-e-odt-inline-src-block (inline-src-block contents info
)
3421 "Transcode an INLINE-SRC-BLOCK element from Org to HTML.
3422 CONTENTS holds the contents of the item. INFO is a plist holding
3423 contextual information."
3424 (let* ((org-lang (org-element-property :language inline-src-block
))
3425 (code (org-element-property :value inline-src-block
))
3426 (separator (org-e-odt--find-verb-separator code
)))
3432 (defun org-e-odt-format-section (text class
&optional id
)
3433 (let ((extra (concat (when id
(format " id=\"%s\"" id
)))))
3434 (concat (format "<div class=\"%s\"%s>\n" class extra
) text
"</div>\n")))
3436 (defun org-e-odt-inlinetask (inlinetask contents info
)
3437 "Transcode an INLINETASK element from Org to ODT.
3438 CONTENTS holds the contents of the block. INFO is a plist
3439 holding contextual information."
3441 ;; If `org-e-odt-format-inlinetask-function' is provided, call it
3442 ;; with appropriate arguments.
3443 ((functionp org-e-odt-format-inlinetask-function
)
3444 (let ((format-function
3446 (lambda (todo todo-type priority text tags
3447 &key contents
&allow-other-keys
)
3448 (funcall org-e-odt-format-inlinetask-function
3449 todo todo-type priority text tags contents
)))))
3450 (org-e-odt-format-headline--wrap
3451 inlinetask info format-function
:contents contents
)))
3452 ;; Otherwise, use a default template.
3453 (t (org-e-odt--wrap-label
3455 (org-e-odt-format-stylized-paragraph
3456 nil
(org-e-odt-format-textbox
3457 (concat (org-e-odt-format-stylized-paragraph
3458 "OrgInlineTaskHeading" (org-e-odt-format-headline--wrap
3461 nil nil
"OrgInlineTaskFrame" " style:rel-width=\"100%\""))))))
3465 (defun org-e-odt-format-list-item (contents type checkbox
3466 &optional term-counter-id
3470 (org-e-odt-format-fontify (case checkbox
3473 (trans "[-]")) 'code
)))
3475 (org-e-odt-begin-list-item type term-counter-id headline
)
3476 ;; FIXME checkbox (and checkbox " ")
3478 (org-e-odt-end-list-item type
)))
3480 (defun org-e-odt-item (item contents info
)
3481 "Transcode an ITEM element from Org to HTML.
3482 CONTENTS holds the contents of the item. INFO is a plist holding
3483 contextual information."
3484 ;; Grab `:level' from plain-list properties, which is always the
3485 ;; first element above current item.
3486 (let* ((plain-list (org-export-get-parent item info
))
3487 (type (org-element-property :type plain-list
))
3488 (level (org-element-property :level plain-list
))
3489 (counter (org-element-property :counter item
))
3490 (checkbox (org-element-property :checkbox item
))
3491 (tag (let ((tag (org-element-property :tag item
)))
3492 (and tag
(org-export-secondary-string tag
'e-odt info
)))))
3493 (org-e-odt-format-list-item
3494 contents type checkbox
(or tag counter
))))
3499 (defun org-e-odt-keyword (keyword contents info
)
3500 "Transcode a KEYWORD element from Org to HTML.
3501 CONTENTS is nil. INFO is a plist holding contextual information."
3502 (let ((key (org-element-property :key keyword
))
3503 (value (org-element-property :value keyword
)))
3505 ((string= key
"LATEX") value
)
3506 ((string= key
"INDEX") (format "\\index{%s}" value
))
3507 ((string= key
"TARGET") nil
; FIXME
3508 ;; (format "\\label{%s}" (org-export-solidify-link-text value))
3510 ((string= key
"toc")
3511 (let ((value (downcase value
)))
3513 ((string-match "\\<headlines\\>" value
)
3514 (let ((depth (or (and (string-match "[0-9]+" value
)
3515 (string-to-number (match-string 0 value
)))
3516 (plist-get info
:with-toc
))))
3517 (when (wholenump depth
) (org-e-odt-toc depth info
))))
3518 ((string= "tables" value
) "FIXME")
3519 ((string= "figures" value
) "FIXME")
3520 ((string= "listings" value
)
3522 ;; At the moment, src blocks with a caption are wrapped
3523 ;; into a figure environment.
3527 ;;;; Latex Environment
3529 (defun org-e-odt-format-latex (latex-frag processing-type
)
3530 (let* ((prefix (case processing-type
3532 (mathml "ltxmathml/")))
3534 (concat prefix
(file-name-sans-extension
3535 (file-name-nondirectory (buffer-file-name)))))
3536 (cache-dir (file-name-directory (buffer-file-name )))
3537 (display-msg (case processing-type
3538 (dvipng "Creating LaTeX Image...")
3539 (mathml "Creating MathML snippet..."))))
3542 (org-format-latex cache-relpath cache-dir nil display-msg
3543 nil nil processing-type
)
3546 (defun org-e-odt-latex-environment (latex-environment contents info
)
3547 "Transcode a LATEX-ENVIRONMENT element from Org to HTML.
3548 CONTENTS is nil. INFO is a plist holding contextual information."
3549 (org-e-odt--wrap-label
3552 (org-remove-indentation
3553 (org-element-property :value latex-environment
)))
3554 (processing-type (plist-get info
:LaTeX-fragments
))
3555 (caption (org-element-property :caption latex-environment
))
3556 (short-caption (and (cdr caption
) (org-export-secondary-string
3557 (cdr caption
) 'e-odt info
)))
3558 (caption (and (car caption
) (org-export-secondary-string
3559 (car caption
) 'e-odt info
)))
3560 (label (org-element-property :name latex-environment
))
3562 (label (org-element-property :name latex-environment
)))
3564 ((member processing-type
'(t mathjax
))
3565 (org-e-odt-format-formula latex-environment info
))
3566 ((equal processing-type
'dvipng
)
3567 (org-e-odt-format-stylized-paragraph
3568 nil
(org-e-odt-link--inline-image latex-environment info
)))
3575 ;; (when latex-frag ; FIXME
3576 ;; (setq href (org-propertize href :title "LaTeX Fragment"
3577 ;; :description latex-frag)))
3579 ;; provide descriptions
3581 (defun org-e-odt-latex-fragment (latex-fragment contents info
)
3582 "Transcode a LATEX-FRAGMENT object from Org to HTML.
3583 CONTENTS is nil. INFO is a plist holding contextual information."
3584 (let* ((latex-frag (org-element-property :value latex-fragment
))
3585 (processing-type (plist-get info
:LaTeX-fragments
)))
3587 ((member processing-type
'(t mathjax
))
3588 (org-e-odt-format-formula latex-fragment info
))
3589 ((equal processing-type
'dvipng
)
3590 (org-e-odt-link--inline-image latex-fragment info
))
3596 (defun org-e-odt-line-break (line-break contents info
)
3597 "Transcode a LINE-BREAK object from Org to HTML.
3598 CONTENTS is nil. INFO is a plist holding contextual information."
3599 "<text:line-break/>\n")
3604 (defun org-e-odt-link--inline-image (element info
)
3605 "Return HTML code for an inline image.
3606 LINK is the link pointing to the inline image. INFO is a plist
3607 used as a communication channel."
3609 ((eq (org-element-type element
) 'link
)
3610 (let* ((type (org-element-property :type element
))
3611 (raw-path (org-element-property :path element
)))
3612 (cond ((member type
'("http" "https"))
3613 (concat type
":" raw-path
))
3614 ((file-name-absolute-p raw-path
)
3615 (expand-file-name raw-path
))
3617 ((member (org-element-type element
)
3618 '(latex-fragment latex-environment
))
3619 (let* ((latex-frag (org-remove-indentation
3620 (org-element-property
3622 (formula-link (org-e-odt-format-latex
3623 latex-frag
'dvipng
)))
3625 (string-match "file:\\([^]]*\\)" formula-link
)
3626 (match-string 1 formula-link
))))
3627 (t (error "what is this?"))))
3628 (href (org-e-odt-format-tags
3629 "<draw:image xlink:href=\"%s\" xlink:type=\"simple\" xlink:show=\"embed\" xlink:actuate=\"onLoad\"/>" ""
3630 (org-e-odt-copy-image-file src
)))
3631 ;; extract attributes from #+ATTR_ODT line.
3632 (attr-from (case (org-element-type element
)
3633 (link (org-export-get-parent-paragraph element info
))
3635 (attr (let ((raw-attr
3636 (mapconcat #'identity
3637 (org-element-property :attr_odt attr-from
)
3639 (unless (string= raw-attr
"") raw-attr
)))
3640 (attr (if (not attr
) "" (org-trim attr
)))
3641 ;; convert attributes to a plist.
3642 (attr-plist (org-e-odt-parse-block-attributes attr
))
3643 ;; handle `:anchor', `:style' and `:attributes' properties.
3645 (car (assoc-string (plist-get attr-plist
:anchor
)
3646 '(("as-char") ("paragraph") ("page")) t
)))
3648 (and user-frame-anchor
(plist-get attr-plist
:style
)))
3650 (and user-frame-anchor
(plist-get attr-plist
:attributes
)))
3652 (list user-frame-style user-frame-attrs user-frame-anchor
))
3653 ;; (embed-as (or embed-as user-frame-anchor "paragraph"))
3655 ;; handle `:width', `:height' and `:scale' properties.
3656 (size (org-e-odt-image-size-from-file
3657 src
(plist-get attr-plist
:width
)
3658 (plist-get attr-plist
:height
)
3659 (plist-get attr-plist
:scale
) nil
;; embed-as
3662 (width (car size
)) (height (cdr size
))
3666 (case (org-element-type element
)
3667 ((org-e-odt-standalone-image-p element info
) "paragraph")
3668 (latex-fragment "as-char")
3669 (latex-environment "paragraph")
3671 (captions (org-e-odt-format-label element info
'definition
))
3672 (entity (concat (and caption
"Captioned") embed-as
"Image")))
3673 (org-e-odt-format-entity entity href width height
3674 captions user-frame-params
)))
3676 (defun org-e-odt-format-entity (entity href width height
&optional
3677 captions user-frame-params
)
3678 (let* ((caption (car captions
)) (short-caption (cdr captions
))
3679 (entity-style (assoc-string entity org-e-odt-entity-frame-styles t
))
3680 default-frame-params frame-params
)
3683 (setq default-frame-params
(nth 2 entity-style
))
3684 (setq frame-params
(org-e-odt-merge-frame-params
3685 default-frame-params user-frame-params
))
3686 (apply 'org-e-odt-format-frame href width height frame-params
))
3688 (setq default-frame-params
(nth 3 entity-style
))
3689 (setq frame-params
(org-e-odt-merge-frame-params
3690 default-frame-params user-frame-params
))
3691 (apply 'org-e-odt-format-textbox
3692 (org-e-odt-format-stylized-paragraph
3695 (apply 'org-e-odt-format-frame href width height
3696 (let ((entity-style-1 (copy-sequence
3697 (nth 2 entity-style
))))
3698 (setcar (cdr entity-style-1
)
3700 (cadr entity-style-1
)
3702 (format " draw:name=\"%s\" "
3706 width height frame-params
)))))
3708 (defvar org-e-odt-standalone-image-predicate
3709 (function (lambda (paragraph)
3710 (or (org-element-property :caption paragraph
)
3711 (org-element-property :name paragraph
)))))
3713 (defun org-e-odt-standalone-image-p (element info
&optional predicate
)
3714 "Test if ELEMENT is a standalone image for the purpose ODT export.
3715 INFO is a plist holding contextual information.
3717 Return non-nil, if ELEMENT is of type paragraph and it's sole
3718 content, save for whitespaces, is a link that qualifies as an
3721 Return non-nil, if ELEMENT is of type link and it's containing
3722 paragraph has no other content save for leading and trailing
3725 Return nil, otherwise.
3727 Bind `org-e-odt-standalone-image-predicate' to constrain
3728 paragraph further. For example, to check for only captioned
3729 standalone images, do the following.
3731 \(setq org-e-odt-standalone-image-predicate
3732 \(lambda \(paragraph\)
3733 \(org-element-property :caption paragraph\)\)\)
3735 (let ((paragraph (case (org-element-type element
)
3737 (link (and (org-export-inline-image-p
3738 element org-e-odt-inline-image-rules
)
3739 (org-export-get-parent element info
)))
3742 (assert (eq (org-element-type paragraph
) 'paragraph
))
3743 (when (or (not (and (boundp 'org-e-odt-standalone-image-predicate
)
3744 (functionp org-e-odt-standalone-image-predicate
)))
3745 (funcall org-e-odt-standalone-image-predicate paragraph
))
3746 (let ((contents (org-element-contents paragraph
)))
3747 (loop for x in contents
3748 with inline-image-count
= 0
3750 ((eq (org-element-type x
) 'plain-text
)
3751 (not (org-string-nw-p x
)))
3752 ((eq (org-element-type x
) 'link
)
3753 (when (org-export-inline-image-p
3754 x org-e-odt-inline-image-rules
)
3755 (= (incf inline-image-count
) 1)))
3758 (defun org-e-odt-link (link desc info
)
3759 "Transcode a LINK object from Org to HTML.
3761 DESC is the description part of the link, or the empty string.
3762 INFO is a plist holding contextual information. See
3764 (let* ((type (org-element-property :type link
))
3765 (raw-path (org-element-property :path link
))
3766 ;; Ensure DESC really exists, or set it to nil.
3767 (desc (and (not (string= desc
"")) desc
))
3768 (imagep (org-export-inline-image-p
3769 link org-e-odt-inline-image-rules
))
3771 ((member type
'("http" "https" "ftp" "mailto"))
3772 (concat type
":" raw-path
))
3773 ((string= type
"file")
3774 (when (string-match "\\(.+\\)::.+" raw-path
)
3775 (setq raw-path
(match-string 1 raw-path
)))
3776 (if (file-name-absolute-p raw-path
)
3777 (concat "file://" (expand-file-name raw-path
))
3778 ;; TODO: Not implemented yet. Concat also:
3779 ;; (org-export-directory :HTML info)
3780 (concat "file://" raw-path
)))
3785 ((and (not desc
) (org-export-inline-image-p
3786 link org-e-odt-inline-image-rules
))
3787 (org-e-odt-link--inline-image link info
))
3788 ;; Radioed target: Target's name is obtained from original raw
3789 ;; link. Path is parsed and transcoded in order to have a proper
3790 ;; display of the contents.
3791 ((string= type
"radio")
3792 (org-e-odt-format-internal-link
3793 (org-export-secondary-string
3794 (org-element-parse-secondary-string
3795 path
(cdr (assq 'radio-target org-element-object-restrictions
)))
3797 (org-export-solidify-link-text path
)))
3798 ;; Links pointing to an headline: Find destination and build
3799 ;; appropriate referencing command.
3800 ((member type
'("custom-id" "fuzzy" "id"))
3801 (let ((destination (if (string= type
"fuzzy")
3802 (org-export-resolve-fuzzy-link link info
)
3803 (org-export-resolve-id-link link info
))))
3804 (case (org-element-type destination
)
3805 ;; Fuzzy link points nowhere.
3807 (org-e-odt-format-fontify
3808 (or desc
(org-export-secondary-string
3809 (org-element-property :raw-link link
)
3810 'e-odt info
)) 'emphasis
))
3811 ;; Fuzzy link points to an invisible target.
3813 ;; LINK points to an headline. If headlines are numbered
3814 ;; and the link has no description, display headline's
3815 ;; number. Otherwise, display description or headline's
3818 (let* ((headline-no (org-export-get-headline-number destination info
))
3819 (label (format "sec-%s" (mapconcat 'number-to-string
3821 (section-no (mapconcat 'number-to-string headline-no
".")))
3825 ((plist-get info
:section-numbers
) section-no
)
3826 (t (org-export-secondary-string
3827 (org-element-property :title destination
)
3829 (org-e-odt-format-internal-link desc label
)))
3830 ;; Fuzzy link points to a target. Do as above.
3833 ;; (setq number (cond
3834 ;; ((org-e-odt-standalone-image-p destination info)
3835 ;; (org-export-get-ordinal
3836 ;; (assoc 'link (org-element-contents destination))
3837 ;; info 'link 'org-e-odt-standalone-image-p))
3838 ;; (t (org-export-get-ordinal destination info))))
3839 ;; (setq desc (when number
3840 ;; (if (atom number) (number-to-string number)
3841 ;; (mapconcat 'number-to-string number ".")))))
3843 (let ((label-reference
3844 (org-e-odt-format-label destination info
'reference
)))
3845 (assert label-reference
)
3846 label-reference
)))))
3847 ;; Coderef: replace link with the reference name or the
3848 ;; equivalent line number.
3849 ((string= type
"coderef")
3850 (let* ((fmt (org-export-get-coderef-format path
(or desc
"%s")))
3851 (res (org-export-resolve-coderef path info
))
3852 (org-e-odt-suppress-xref nil
)
3853 (href (org-xml-format-href (concat "#coderef-" path
))))
3854 (format fmt
(org-e-odt-format-link res href
))))
3855 ;; Link type is handled by a special function.
3856 ((functionp (setq protocol
(nth 2 (assoc type org-link-protocols
))))
3857 (funcall protocol
(org-link-unescape path
) desc
'html
))
3858 ;; External link with a description part.
3859 ((and path desc
) (org-e-odt-format-link desc path
))
3860 ;; External link without a description part.
3861 (path (org-e-odt-format-link path path
))
3862 ;; No path, only description. Try to do something useful.
3863 (t (org-e-odt-format-fontify desc
'emphasis
)))))
3868 ;; Babel Calls are ignored.
3873 (defun org-e-odt-macro (macro contents info
)
3874 "Transcode a MACRO element from Org to HTML.
3875 CONTENTS is nil. INFO is a plist holding contextual information."
3876 ;; Use available tools.
3877 (org-export-expand-macro macro info
))
3882 (defun org-e-odt-paragraph (paragraph contents info
)
3883 "Transcode a PARAGRAPH element from Org to HTML.
3884 CONTENTS is the contents of the paragraph, as a string. INFO is
3885 the plist used as a communication channel."
3886 (let* ((style nil
) ; FIXME
3887 (class (cdr (assoc style
'((footnote .
"footnote")
3889 (extra (if class
(format " class=\"%s\"" class
) ""))
3890 (parent (org-export-get-parent paragraph info
))
3891 (parent-type (org-element-type parent
))
3892 (style (case parent-type
3893 (quote-block 'quote
)
3894 (center-block 'center
)
3895 (footnote-definition 'footnote
)
3897 (org-e-odt-format-stylized-paragraph style contents
)))
3902 (defun org-e-odt-plain-list (plain-list contents info
)
3903 "Transcode a PLAIN-LIST element from Org to HTML.
3904 CONTENTS is the contents of the list. INFO is a plist holding
3905 contextual information."
3906 (let* (arg1 ;; FIXME
3907 (type (org-element-property :type plain-list
))
3908 (attr (mapconcat #'identity
3909 (org-element-property :attr_odt plain-list
)
3911 (org-e-odt--wrap-label
3912 plain-list
(format "%s\n%s%s"
3913 (org-e-odt-begin-plain-list type
)
3914 contents
(org-e-odt-end-plain-list type
)))))
3918 (defun org-e-odt-convert-special-strings (string)
3919 "Convert special characters in STRING to ODT."
3920 (let ((all org-e-odt-special-string-regexps
)
3922 (while (setq a
(pop all
))
3923 (setq re
(car a
) rpl
(cdr a
) start
0)
3924 (while (string-match re string start
)
3925 (setq string
(replace-match rpl t nil string
))))
3928 ;; (defun org-e-odt-encode-plain-text (s)
3929 ;; "Convert plain text characters to HTML equivalent.
3930 ;; Possible conversions are set in `org-export-html-protect-char-alist'."
3931 ;; (let ((cl org-e-odt-protect-char-alist) c)
3932 ;; (while (setq c (pop cl))
3934 ;; (while (string-match (car c) s start)
3935 ;; (setq s (replace-match (cdr c) t t s)
3936 ;; start (1+ (match-beginning 0))))))
3939 (defun org-e-odt-plain-text (text info
)
3940 "Transcode a TEXT string from Org to HTML.
3941 TEXT is the string to transcode. INFO is a plist holding
3942 contextual information."
3943 (setq text
(org-e-odt-encode-plain-text text t
))
3944 ;; Protect %, #, &, $, ~, ^, _, { and }.
3945 ;; (while (string-match "\\([^\\]\\|^\\)\\([%$#&{}~^_]\\)" text)
3947 ;; (replace-match (format "\\%s" (match-string 2 text)) nil t text 2)))
3949 ;; (setq text (replace-regexp-in-string
3950 ;; "\\(?:[^\\]\\|^\\)\\(\\\\\\)\\(?:[^%$#&{}~^_\\]\\|$\\)"
3951 ;; "$\\backslash$" text nil t 1))
3952 ;; HTML into \HTML{} and TeX into \TeX{}.
3953 ;; (let ((case-fold-search nil)
3955 ;; (while (string-match "\\<\\(\\(?:La\\)?TeX\\)\\>" text start)
3956 ;; (setq text (replace-match
3957 ;; (format "\\%s{}" (match-string 1 text)) nil t text)
3958 ;; start (match-end 0))))
3959 ;; Handle quotation marks
3960 ;; (setq text (org-e-odt--quotation-marks text info))
3961 ;; Convert special strings.
3962 ;; (when (plist-get info :with-special-strings)
3963 ;; (while (string-match (regexp-quote "...") text)
3964 ;; (setq text (replace-match "\\ldots{}" nil t text))))
3965 (when (plist-get info
:with-special-strings
)
3966 (setq text
(org-e-odt-convert-special-strings text
)))
3967 ;; Handle break preservation if required.
3968 (when (plist-get info
:preserve-breaks
)
3969 (setq text
(replace-regexp-in-string "\\(\\\\\\\\\\)?[ \t]*\n" " \\\\\\\\\n"
3975 ;;;; Property Drawer
3977 (defun org-e-odt-property-drawer (property-drawer contents info
)
3978 "Transcode a PROPERTY-DRAWER element from Org to HTML.
3979 CONTENTS is nil. INFO is a plist holding contextual
3981 ;; The property drawer isn't exported but we want separating blank
3982 ;; lines nonetheless.
3988 (defun org-e-odt-quote-block (quote-block contents info
)
3989 "Transcode a QUOTE-BLOCK element from Org to HTML.
3990 CONTENTS holds the contents of the block. INFO is a plist
3991 holding contextual information."
3992 (org-e-odt--wrap-label quote-block contents
))
3997 (defun org-e-odt-quote-section (quote-section contents info
)
3998 "Transcode a QUOTE-SECTION element from Org to HTML.
3999 CONTENTS is nil. INFO is a plist holding contextual information."
4000 (let ((value (org-remove-indentation
4001 (org-element-property :value quote-section
))))
4002 (when value
(org-e-odt-format-source-code-or-example value nil
))))
4007 (defun org-e-odt-section (section contents info
) ; FIXME
4008 "Transcode a SECTION element from Org to HTML.
4009 CONTENTS holds the contents of the section. INFO is a plist
4010 holding contextual information."
4015 (defun org-e-odt-radio-target (radio-target text info
)
4016 "Transcode a RADIO-TARGET object from Org to HTML.
4017 TEXT is the text of the target. INFO is a plist holding
4018 contextual information."
4019 (org-e-odt-format-anchor
4020 text
(org-export-solidify-link-text
4021 (org-element-property :value radio-target
))))
4026 (defun org-e-odt-special-block (special-block contents info
)
4027 "Transcode a SPECIAL-BLOCK element from Org to HTML.
4028 CONTENTS holds the contents of the block. INFO is a plist
4029 holding contextual information."
4030 (let ((type (downcase (org-element-property :type special-block
))))
4031 (org-e-odt--wrap-label
4033 (format "\\begin{%s}\n%s\\end{%s}" type contents type
))))
4038 (defun org-e-odt-src-block (src-block contents info
)
4039 "Transcode a SRC-BLOCK element from Org to HTML.
4040 CONTENTS holds the contents of the item. INFO is a plist holding
4041 contextual information."
4042 (let* ((lang (org-element-property :language src-block
))
4043 (caption (org-element-property :caption src-block
))
4044 (short-caption (and (cdr caption
) (org-export-secondary-string
4045 (cdr caption
) 'e-odt info
)))
4046 (caption (and (car caption
) (org-export-secondary-string
4047 (car caption
) 'e-odt info
)))
4048 (label (org-element-property :name src-block
)))
4049 ;; FIXME: Handle caption
4050 ;; caption-str (when caption)
4051 ;; (main (org-export-secondary-string (car caption) 'e-odt info))
4052 ;; (secondary (org-export-secondary-string (cdr caption) 'e-odt info))
4053 ;; (caption-str (org-e-odt--caption/label-string caption label info))
4054 (let* ((captions (org-e-odt-format-label src-block info
'definition
))
4055 (caption (car captions
)) (short-caption (cdr captions
)))
4057 (and caption
(org-e-odt-format-stylized-paragraph 'listing caption
))
4058 (org-e-odt-format-code src-block info
)))))
4061 ;;;; Statistics Cookie
4063 (defun org-e-odt-statistics-cookie (statistics-cookie contents info
)
4064 "Transcode a STATISTICS-COOKIE object from Org to HTML.
4065 CONTENTS is nil. INFO is a plist holding contextual information."
4066 (let ((cookie-value (org-element-property :value statistics-cookie
)))
4067 (org-e-odt-format-fontify cookie-value
'code
)))
4072 (defun org-e-odt-subscript (subscript contents info
)
4073 "Transcode a SUBSCRIPT object from Org to HTML.
4074 CONTENTS is the contents of the object. INFO is a plist holding
4075 contextual information."
4076 ;; (format (if (= (length contents) 1) "$_%s$" "$_{\\mathrm{%s}}$") contents)
4077 (org-e-odt-format-fontify contents
'subscript
))
4082 (defun org-e-odt-superscript (superscript contents info
)
4083 "Transcode a SUPERSCRIPT object from Org to HTML.
4084 CONTENTS is the contents of the object. INFO is a plist holding
4085 contextual information."
4086 ;; (format (if (= (length contents) 1) "$^%s$" "$^{\\mathrm{%s}}$") contents)
4087 (org-e-odt-format-fontify contents
'superscript
))
4092 (defun org-e-odt-get-colwidth (c)
4093 (let ((col-widths (plist-get table-info
:width
)))
4094 (or (and org-lparse-table-is-styled
(aref col-widths c
)) 0)))
4096 (defun org-e-odt-table-row (fields &optional text-for-empty-fields
)
4097 (incf org-e-odt-table-rownum
)
4099 (org-e-odt-format-table-row
4102 (when (and (string= x
"") text-for-empty-fields
)
4103 (setq x text-for-empty-fields
))
4105 (let ((horiz-span (org-e-odt-get-colwidth i
)))
4106 (org-e-odt-format-table-cell
4107 x org-e-odt-table-rownum i horiz-span
)))
4110 (defun org-e-odt-table-preamble ()
4111 (let ((colgroup-vector (plist-get table-info
:column-groups
)) ;; FIXME
4112 c gr colgropen preamble
)
4113 (unless (aref colgroup-vector
0)
4114 (setf (aref colgroup-vector
0) 'start
))
4115 (dotimes (c columns-number preamble
)
4116 (setq gr
(aref colgroup-vector c
))
4120 (when (memq gr
'(start start-end
))
4121 (prog1 (if colgropen
"</colgroup>\n<colgroup>" "\n<colgroup>")
4122 (setq colgropen t
)))
4123 (let* ((colalign-vector (plist-get table-info
:alignment
)) ;; FIXME
4124 (align (cdr (assoc (aref colalign-vector c
)
4127 ("c" .
"center")))))
4128 (alignspec (if (and (boundp 'org-e-odt-format-table-no-css
)
4129 org-e-odt-format-table-no-css
)
4130 " align=\"%s\"" " class=\"%s\""))
4131 (extra (format alignspec align
)))
4132 (format "<col%s />" extra
))
4133 (when (memq gr
'(end start-end
))
4134 (setq colgropen nil
)
4136 (concat preamble
(if colgropen
"</colgroup>"))))
4138 (defun org-e-odt-list-table (lines caption-from info
)
4139 (let* ((splice nil
) head
4140 (org-e-odt-table-rownum -
1)
4143 org-e-odt-table-cur-rowgrp-is-hdr
4144 org-e-odt-table-rowgrp-open
4146 (org-lparse-table-style 'org-table
)
4147 org-lparse-table-is-styled
)
4150 (setq org-lparse-table-is-styled nil
)
4151 (mapconcat 'org-e-odt-table-row lines
"\n"))
4153 (setq org-lparse-table-is-styled t
)
4156 (org-e-odt-begin-table caption-from info
)
4157 ;; FIXME (org-e-odt-table-preamble)
4158 (org-e-odt-begin-table-rowgroup head
)
4163 ((equal line
'hline
) (org-e-odt-begin-table-rowgroup))
4164 (t (org-e-odt-table-row line
))))
4167 (org-e-odt-end-table-rowgroup)
4168 (org-e-odt-end-table))))))
4170 (defun org-e-odt-transcode-table-row (row)
4171 (if (string-match org-table-hline-regexp row
) 'hline
4174 (org-export-secondary-string
4175 (let ((cell (org-element-parse-secondary-string
4177 (cdr (assq 'table org-element-string-restrictions
)))))
4180 (org-split-string row
"[ \t]*|[ \t]*"))))
4182 (defun org-e-odt-org-table-to-list-table (lines &optional splice
)
4183 "Convert org-table to list-table.
4184 LINES is a list of the form (ROW1 ROW2 ROW3 ...) where each
4185 element is a `string' representing a single row of org-table.
4186 Thus each ROW has vertical separators \"|\" separating the table
4187 fields. A ROW could also be a row-group separator of the form
4188 \"|---...|\". Return a list of the form (ROW1 ROW2 ROW3
4189 ...). ROW could either be symbol `'hline' or a list of the
4190 form (FIELD1 FIELD2 FIELD3 ...) as appropriate."
4194 (while (setq line
(pop lines
))
4195 (unless (string-match "^[ \t]*|-" line
)
4196 (push (org-e-odt-transcode-table-row line
) lines-1
))))
4197 (t (while (setq line
(pop lines
))
4199 ((string-match "^[ \t]*|-" line
)
4200 (when lines
(push 'hline lines-1
)))
4201 (t (push (org-e-odt-transcode-table-row line
) lines-1
))))))
4202 (nreverse lines-1
)))
4204 (defun org-e-odt-table-table (raw-table)
4206 (with-current-buffer (get-buffer-create "*org-export-table*")
4208 (let ((output (with-temp-buffer
4211 (re-search-forward "^[ \t]*|[^|]" nil t
)
4212 (table-generate-source 'html
"*org-export-table*")
4213 (with-current-buffer "*org-export-table*"
4214 (org-trim (buffer-string))))))
4215 (kill-buffer (get-buffer "*org-export-table*"))
4218 (defun org-e-odt-table (table contents info
)
4219 "Transcode a TABLE element from Org to HTML.
4220 CONTENTS is nil. INFO is a plist holding contextual information."
4221 (let* ((raw-table (org-element-property :raw-table table
))
4222 (table-type (org-element-property :type table
)))
4225 ;; (org-e-odt-table-table raw-table)
4228 (let* ((table-info (org-export-table-format-info raw-table
))
4229 (columns-number (length (plist-get table-info
:alignment
)))
4230 (lines (org-split-string
4231 (org-export-clean-table
4232 raw-table
(plist-get table-info
:special-column-p
)) "\n"))
4234 (genealogy (org-export-get-genealogy table info
))
4235 (parent (car genealogy
))
4236 (parent-type (org-element-type parent
)))
4237 (org-e-odt-list-table
4238 (org-e-odt-org-table-to-list-table lines
) table info
))))))
4243 (defun org-e-odt-target (target contents info
)
4244 "Transcode a TARGET object from Org to HTML.
4245 CONTENTS is nil. INFO is a plist holding contextual
4247 (org-e-odt-format-anchor
4248 "" (org-export-solidify-link-text (org-element-property :value target
))))
4253 (defun org-e-odt-time-stamp (time-stamp contents info
)
4254 "Transcode a TIME-STAMP object from Org to HTML.
4255 CONTENTS is nil. INFO is a plist holding contextual
4257 ;; (let ((value (org-element-property :value time-stamp))
4258 ;; (type (org-element-property :type time-stamp))
4259 ;; (appt-type (org-element-property :appt-type time-stamp)))
4260 ;; (concat (cond ((eq appt-type 'scheduled)
4261 ;; (format "\\textbf{\\textsc{%s}} " org-scheduled-string))
4262 ;; ((eq appt-type 'deadline)
4263 ;; (format "\\textbf{\\textsc{%s}} " org-deadline-string))
4264 ;; ((eq appt-type 'closed)
4265 ;; (format "\\textbf{\\textsc{%s}} " org-closed-string)))
4266 ;; (cond ((memq type '(active active-range))
4267 ;; (format org-e-odt-active-timestamp-format value))
4268 ;; ((memq type '(inactive inactive-range))
4269 ;; (format org-e-odt-inactive-timestamp-format value))
4271 ;; (format org-e-odt-diary-timestamp-format value)))))
4272 (let ((value (org-element-property :value time-stamp
))
4273 (type (org-element-property :type time-stamp
))
4274 (appt-type (org-element-property :appt-type time-stamp
)))
4275 (setq value
(org-export-secondary-string value
'e-odt info
))
4276 (org-e-odt-format-fontify
4278 (org-e-odt-format-fontify
4279 (cond ((eq appt-type
'scheduled
) org-scheduled-string
)
4280 ((eq appt-type
'deadline
) org-deadline-string
)
4281 ((eq appt-type
'closed
) org-closed-string
)) "timestamp-kwd")
4282 ;; FIXME: (org-translate-time value)
4283 (org-e-odt-format-fontify value
"timestamp"))
4284 "timestamp-wrapper")))
4289 (defun org-e-odt-verbatim (verbatim contents info
)
4290 "Transcode a VERBATIM object from Org to HTML.
4291 CONTENTS is nil. INFO is a plist used as a communication
4294 verbatim
(org-element-property :value verbatim
) info
))
4299 (defun org-e-odt-verse-block (verse-block contents info
)
4300 "Transcode a VERSE-BLOCK element from Org to HTML.
4301 CONTENTS is nil. INFO is a plist holding contextual information."
4302 ;; Replace each newline character with line break. Also replace
4303 ;; each blank line with a line break.
4304 (setq contents
(replace-regexp-in-string
4305 "^ *\\\\\\\\$" "<br/>\n"
4306 (replace-regexp-in-string
4307 "\\(\\\\\\\\\\)?[ \t]*\n" " <br/>\n"
4308 (org-remove-indentation
4309 (org-export-secondary-string
4310 (org-element-property :value verse-block
)
4313 ;; Replace each white space at beginning of a line with a
4314 ;; non-breaking space.
4315 (while (string-match "^[ \t]+" contents
)
4316 (let ((new-str (org-e-odt-format-spaces
4317 (length (match-string 0 contents
)))))
4318 (setq contents
(replace-match new-str nil t contents
))))
4320 (org-e-odt--wrap-label
4321 verse-block
(format "<p class=\"verse\">\n%s</p>" contents
)))
4326 ;;; Filter Functions
4328 ;;;; Filter Settings
4331 ;;; Interactive functions
4333 (defun org-e-odt-export-to-odt
4334 (&optional subtreep visible-only body-only ext-plist pub-dir
)
4335 "Export current buffer to a HTML file.
4337 If narrowing is active in the current buffer, only export its
4340 If a region is active, export that region.
4342 When optional argument SUBTREEP is non-nil, export the sub-tree
4343 at point, extracting information from the headline properties
4346 When optional argument VISIBLE-ONLY is non-nil, don't export
4347 contents of hidden elements.
4349 When optional argument BODY-ONLY is non-nil, only write code
4350 between \"\\begin{document}\" and \"\\end{document}\".
4352 EXT-PLIST, when provided, is a property list with external
4353 parameters overriding Org default settings, but still inferior to
4354 file-local settings.
4356 When optional argument PUB-DIR is set, use it as the publishing
4359 Return output file's name."
4361 (setq debug-on-error t
)
4363 ;; (let* ((outfile (org-export-output-file-name ".html" subtreep pub-dir))
4364 ;; (outfile "content.xml"))
4365 ;; (org-export-to-file
4366 ;; 'e-odt outfile subtreep visible-only body-only ext-plist))
4368 (let* ((outbuf (org-e-odt-init-outfile))
4369 (target (org-export-output-file-name ".odt" subtreep pub-dir
))
4370 (outdir (file-name-directory (buffer-file-name outbuf
)))
4371 (default-directory outdir
))
4373 ;; FIXME: for copying embedded images
4374 (setq org-current-export-file
4375 (file-name-directory
4376 (org-export-output-file-name ".odt" subtreep nil
)))
4378 (org-export-to-buffer
4380 (memq 'subtree optns
) (memq 'visible optns
) (memq 'body optns
))
4382 (setq org-lparse-opt-plist nil
) ; FIXME
4383 (org-e-odt-save-as-outfile target
;; info
4388 (if (not org-e-odt-preferred-output-format
) target
4389 (or (org-e-odt-convert target org-e-odt-preferred-output-format
)
4396 (defun org-e-odt-reachable-p (in-fmt out-fmt
)
4397 "Return non-nil if IN-FMT can be converted to OUT-FMT."
4399 (let ((reachable-formats (org-e-odt-do-reachable-formats in-fmt
)))
4400 (dolist (e reachable-formats
)
4401 (let ((out-fmt-spec (assoc out-fmt
(cdr e
))))
4403 (throw 'done
(cons (car e
) out-fmt-spec
))))))))
4405 (defun org-e-odt-do-convert (in-file out-fmt
&optional prefix-arg
)
4406 "Workhorse routine for `org-e-odt-convert'."
4407 (require 'browse-url
)
4408 (let* ((in-file (expand-file-name (or in-file buffer-file-name
)))
4409 (dummy (or (file-readable-p in-file
)
4410 (error "Cannot read %s" in-file
)))
4411 (in-fmt (file-name-extension in-file
))
4412 (out-fmt (or out-fmt
(error "Output format unspecified")))
4413 (how (or (org-e-odt-reachable-p in-fmt out-fmt
)
4414 (error "Cannot convert from %s format to %s format?"
4416 (convert-process (car how
))
4417 (out-file (concat (file-name-sans-extension in-file
) "."
4418 (nth 1 (or (cdr how
) out-fmt
))))
4419 (extra-options (or (nth 2 (cdr how
)) ""))
4420 (out-dir (file-name-directory in-file
))
4421 (cmd (format-spec convert-process
4422 `((?i .
,(shell-quote-argument in-file
))
4423 (?I .
,(browse-url-file-url in-file
))
4426 (?O .
,(browse-url-file-url out-file
))
4427 (?d .
, (shell-quote-argument out-dir
))
4428 (?D .
,(browse-url-file-url out-dir
))
4429 (?x .
,extra-options
)))))
4430 (when (file-exists-p out-file
)
4431 (delete-file out-file
))
4433 (message "Executing %s" cmd
)
4434 (let ((cmd-output (shell-command-to-string cmd
)))
4435 (message "%s" cmd-output
))
4438 ((file-exists-p out-file
)
4439 (message "Exported to %s" out-file
)
4441 (message "Opening %s..." out-file
)
4442 (org-open-file out-file
))
4445 (message "Export to %s failed" out-file
)
4448 (defun org-e-odt-do-reachable-formats (in-fmt)
4449 "Return verbose info about formats to which IN-FMT can be converted.
4450 Return a list where each element is of the
4451 form (CONVERTER-PROCESS . OUTPUT-FMT-ALIST). See
4452 `org-e-odt-convert-processes' for CONVERTER-PROCESS and see
4453 `org-e-odt-convert-capabilities' for OUTPUT-FMT-ALIST."
4455 (and org-e-odt-convert-process
4456 (cadr (assoc-string org-e-odt-convert-process
4457 org-e-odt-convert-processes t
))))
4459 (and org-e-odt-convert-process
4460 (cadr (assoc-string org-e-odt-convert-process
4461 org-e-odt-convert-processes t
))
4462 org-e-odt-convert-capabilities
))
4465 (dolist (c capabilities
)
4466 (when (member in-fmt
(nth 1 c
))
4467 (push (cons converter
(nth 2 c
)) reachable-formats
))))
4470 (defun org-e-odt-reachable-formats (in-fmt)
4471 "Return list of formats to which IN-FMT can be converted.
4472 The list of the form (OUTPUT-FMT-1 OUTPUT-FMT-2 ...)."
4474 (mapc (lambda (e) (add-to-list 'l e
))
4475 (apply 'append
(mapcar
4476 (lambda (e) (mapcar 'car
(cdr e
)))
4477 (org-e-odt-do-reachable-formats in-fmt
))))
4480 (defun org-e-odt-convert-read-params ()
4481 "Return IN-FILE and OUT-FMT params for `org-e-odt-do-convert'.
4482 This is a helper routine for interactive use."
4483 (let* ((input (if (featurep 'ido
) 'ido-completing-read
'completing-read
))
4484 (in-file (read-file-name "File to be converted: "
4485 nil buffer-file-name t
))
4486 (in-fmt (file-name-extension in-file
))
4487 (out-fmt-choices (org-e-odt-reachable-formats in-fmt
))
4489 (or (and out-fmt-choices
4490 (funcall input
"Output format: "
4491 out-fmt-choices nil nil nil
))
4493 "No known converter or no known output formats for %s files"
4495 (list in-file out-fmt
)))
4498 (defun org-e-odt-convert (&optional in-file out-fmt prefix-arg
)
4499 "Convert IN-FILE to format OUT-FMT using a command line converter.
4500 IN-FILE is the file to be converted. If unspecified, it defaults
4501 to variable `buffer-file-name'. OUT-FMT is the desired output
4502 format. Use `org-e-odt-convert-process' as the converter.
4503 If PREFIX-ARG is non-nil then the newly converted file is opened
4504 using `org-open-file'."
4506 (append (org-e-odt-convert-read-params) current-prefix-arg
))
4507 (org-e-odt-do-convert in-file out-fmt prefix-arg
))
4509 ;;; FIXMES, TODOS, FOR REVIEW etc
4511 ;;;; org-format-table-html
4512 ;;;; org-format-org-table-html
4513 ;;;; org-format-table-table-html
4514 ;;;; org-table-number-fraction
4515 ;;;; org-table-number-regexp
4516 ;;;; org-e-odt-table-caption-above
4519 ;;;; "<span style=\"visibility:hidden;\">%s</span>"
4520 ;;;; Remove display properties
4522 ;;;; org-e-odt-with-timestamp
4523 ;;;; org-e-odt-html-helper-timestamp
4525 ;;;; org-export-as-html-and-open
4526 ;;;; org-export-as-html-batch
4527 ;;;; org-export-as-html-to-buffer
4528 ;;;; org-replace-region-by-html
4529 ;;;; org-export-region-as-html
4530 ;;;; org-export-as-html
4532 ;;;; (org-export-directory :html opt-plist)
4533 ;;;; (plist-get opt-plist :html-extension)
4534 ;;;; org-e-odt-toplevel-hlevel
4535 ;;;; org-e-odt-coding-system
4536 ;;;; org-e-odt-coding-system
4537 ;;;; org-e-odt-inline-image-extensions
4538 ;;;; org-e-odt-protect-char-alist
4539 ;;;; org-e-odt-table-use-header-tags-for-first-column
4540 ;;;; org-e-odt-todo-kwd-class-prefix
4541 ;;;; org-e-odt-tag-class-prefix
4542 ;;;; org-e-odt-footnote-separator
4545 ;;; Library Initializations
4549 ;; Let Org open all OpenDocument files using system-registered app
4550 (add-to-list 'org-file-apps
4551 (cons (concat "\\." (car desc
) "\\'") 'system
))
4552 ;; Let Emacs open all OpenDocument files in archive mode
4553 (add-to-list 'auto-mode-alist
4554 (cons (concat "\\." (car desc
) "\\'") 'archive-mode
)))
4555 org-e-odt-file-extensions
)
4557 (defvar org-e-odt-display-outline-level
2)
4558 (defun org-e-odt-enumerate-element (element info
&optional predicate n
)
4559 (let* ((numbered-parent-headline-at-<=-n
4561 (lambda (element n info
)
4562 (loop for x in
(org-export-get-genealogy element info
)
4563 thereis
(and (eq (org-element-type x
) 'headline
)
4564 (<= (org-export-get-relative-level x info
) n
)
4565 (org-export-numbered-headline-p x info
)
4569 (lambda (element scope info
&optional predicate
)
4572 (or scope
(plist-get info
:parse-tree
))
4573 (org-element-type element
)
4575 (and (or (not predicate
) (funcall predicate el info
))
4579 info
'first-match
)))))
4580 (scope (funcall numbered-parent-headline-at-
<=-n
4581 element
(or n org-e-odt-display-outline-level
) info
))
4582 (ordinal (funcall enumerate element scope info predicate
))
4587 (mapconcat 'number-to-string
4588 (org-export-get-headline-number scope info
) "."))
4592 (number-to-string ordinal
))))
4593 ;; (message "%s:\t%s" (org-element-property :name element) tag)
4596 (provide 'org-e-odt
)
4598 ;;; org-e-odt.el ends here