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/>.
34 (defvar org-e-odt-translate-alist
35 '((babel-call . org-e-odt-babel-call
)
36 (bold . org-e-odt-bold
)
37 (center-block . org-e-odt-center-block
)
38 (clock . org-e-odt-clock
)
39 (code . org-e-odt-code
)
40 (comment . org-e-odt-comment
)
41 (comment-block . org-e-odt-comment-block
)
42 (drawer . org-e-odt-drawer
)
43 (dynamic-block . org-e-odt-dynamic-block
)
44 (entity . org-e-odt-entity
)
45 (example-block . org-e-odt-example-block
)
46 (export-block . org-e-odt-export-block
)
47 (export-snippet . org-e-odt-export-snippet
)
48 (fixed-width . org-e-odt-fixed-width
)
49 (footnote-definition . org-e-odt-footnote-definition
)
50 (footnote-reference . org-e-odt-footnote-reference
)
51 (headline . org-e-odt-headline
)
52 (horizontal-rule . org-e-odt-horizontal-rule
)
53 (inline-babel-call . org-e-odt-inline-babel-call
)
54 (inline-src-block . org-e-odt-inline-src-block
)
55 (inlinetask . org-e-odt-inlinetask
)
56 (italic . org-e-odt-italic
)
57 (item . org-e-odt-item
)
58 (keyword . org-e-odt-keyword
)
59 (latex-environment . org-e-odt-latex-environment
)
60 (latex-fragment . org-e-odt-latex-fragment
)
61 (line-break . org-e-odt-line-break
)
62 (link . org-e-odt-link
)
63 (macro . org-e-odt-macro
)
64 (paragraph . org-e-odt-paragraph
)
65 (plain-list . org-e-odt-plain-list
)
66 (plain-text . org-e-odt-plain-text
)
67 (planning . org-e-odt-planning
)
68 (property-drawer . org-e-odt-property-drawer
)
69 (quote-block . org-e-odt-quote-block
)
70 (quote-section . org-e-odt-quote-section
)
71 (radio-target . org-e-odt-radio-target
)
72 (section . org-e-odt-section
)
73 (special-block . org-e-odt-special-block
)
74 (src-block . org-e-odt-src-block
)
75 (statistics-cookie . org-e-odt-statistics-cookie
)
76 (strike-through . org-e-odt-strike-through
)
77 (subscript . org-e-odt-subscript
)
78 (superscript . org-e-odt-superscript
)
79 (table . org-e-odt-table
)
80 (table-cell . org-e-odt-table-cell
)
81 (table-row . org-e-odt-table-row
)
82 (target . org-e-odt-target
)
83 (template . org-e-odt-template
)
84 (timestamp . org-e-odt-timestamp
)
85 (underline . org-e-odt-underline
)
86 (verbatim . org-e-odt-verbatim
)
87 (verse-block . org-e-odt-verse-block
))
88 "Alist between element or object types and translators.")
90 (defconst org-e-odt-options-alist
92 ;; (:agenda-style nil nil org-agenda-export-html-style)
93 ;; (:convert-org-links nil nil org-e-odt-link-org-files-as-html)
94 ;; ;; FIXME Use (org-xml-encode-org-text-skip-links s) ??
95 ;; ;; (:expand-quoted-html nil "@" org-e-odt-expand)
96 ;; (:inline-images nil nil org-e-odt-inline-images)
97 ;; ;; (:link-home nil nil org-e-odt-link-home) FIXME
98 ;; ;; (:link-up nil nil org-e-odt-link-up) FIXME
99 ;; (:style nil nil org-e-odt-style)
100 ;; (:style-extra nil nil org-e-odt-style-extra)
101 ;; (:style-include-default nil nil org-e-odt-style-include-default)
102 ;; (:style-include-scripts nil nil org-e-odt-style-include-scripts)
103 ;; ;; (:timestamp nil nil org-e-odt-with-timestamp)
104 ;; (:html-extension nil nil org-e-odt-extension)
105 ;; (:html-postamble nil nil org-e-odt-postamble)
106 ;; (:html-preamble nil nil org-e-odt-preamble)
107 ;; (:html-table-tag nil nil org-e-odt-table-tag)
108 ;; (:xml-declaration nil nil org-e-odt-xml-declaration)
109 (:odt-styles-file
"ODT_STYLES_FILE" nil nil t
)
110 (:LaTeX-fragments nil
"LaTeX" org-export-with-LaTeX-fragments
))
111 "Alist between ODT export properties and ways to set them.
112 See `org-export-options-alist' for more information on the
113 structure of the values.")
117 ;; org-e-odt-preprocess-latex-fragments
118 ;; org-export-as-e-odt-and-open
119 ;; org-export-as-e-odt-batch
120 ;; org-export-as-e-odt
122 (defun org-e-odt-get-style-name-for-entity (category &optional entity
)
123 (let ((entity (or entity
'default
)))
125 (cdr (assoc entity
(cdr (assoc category
126 org-e-odt-org-styles-alist
))))
127 (cdr (assoc entity
(cdr (assoc category
128 org-e-odt-default-org-styles-alist
))))
129 (error "Cannot determine style name for entity %s of type %s"
132 ;; Following variable is let bound when `org-do-lparse' is in
133 ;; progress. See org-html.el.
135 (defun org-e-odt-format-preamble (info)
136 (let* ((title (org-export-data (plist-get info
:title
) info
))
137 (author (and (plist-get info
:with-author
)
138 (let ((auth (plist-get info
:author
)))
139 (and auth
(org-export-data auth info
)))))
140 (date (plist-get info
:date
))
141 (iso-date (org-e-odt-format-date date
))
142 (date (org-e-odt-format-date date
"%d %b %Y"))
143 (email (plist-get info
:email
))
144 ;; switch on or off above vars based on user settings
145 (author (and (plist-get info
:with-author
) (or author email
)))
146 ;; (date (and (plist-get info :time-stamp-file) date))
147 (email (and (plist-get info
:with-email
) email
)))
152 (org-e-odt-format-stylized-paragraph
153 'title
(format "\n<text:title>%s</text:title>" title
))
155 "\n<text:p text:style-name=\"OrgTitle\"/>"))
157 ((and author
(not email
))
160 (org-e-odt-format-stylized-paragraph
162 (format "<text:initial-creator>%s</text:initial-creator>" author
))
164 "\n<text:p text:style-name=\"OrgSubtitle\"/>"))
168 (org-e-odt-format-stylized-paragraph
170 (org-e-odt-format-link
171 (format "<text:initial-creator>%s</text:initial-creator>" author
)
172 (concat "mailto:" email
)))
174 "\n<text:p text:style-name=\"OrgSubtitle\"/>")))
178 (org-e-odt-format-stylized-paragraph
180 (org-e-odt-format-tags
181 '("<text:date style:data-style-name=\"%s\" text:date-value=\"%s\">"
183 date
"N75" iso-date
))
185 "<text:p text:style-name=\"OrgSubtitle\"/>")))))
187 (defun org-e-odt-begin-section (style &optional name
)
188 (let ((default-name (car (org-e-odt-add-automatic-style "Section"))))
189 (format "<text:section text:style-name=\"%s\" text:name=\"%s\">"
190 style
(or name default-name
))))
192 (defun org-e-odt-end-section ()
195 (defun org-e-odt-begin-paragraph (&optional style
)
196 (format "<text:p%s>" (org-e-odt-get-extra-attrs-for-paragraph-style style
)))
198 (defun org-e-odt-end-paragraph ()
201 (defun org-e-odt-get-extra-attrs-for-paragraph-style (style)
205 ((stringp style
) style
)
206 ((symbolp style
) (org-e-odt-get-style-name-for-entity
209 (error "Don't know how to handle paragraph style %s" style
))
210 (format " text:style-name=\"%s\"" style-name
)))
212 (defun org-e-odt-format-stylized-paragraph (style text
)
213 (format "\n<text:p%s>%s</text:p>"
214 (org-e-odt-get-extra-attrs-for-paragraph-style style
)
217 (defun org-e-odt-format-author (&optional author
)
218 (when (setq author
(or author
(plist-get org-lparse-opt-plist
:author
)))
219 (format "<dc:creator>%s</dc:creator>" author
)))
221 (defun org-e-odt-format-date (&optional org-ts fmt
)
224 (and (stringp org-ts
)
225 (string-match org-ts-regexp0 org-ts
)
227 (org-fix-decoded-time
228 (org-parse-time-string (match-string 0 org-ts
) t
)))))
231 (fmt (format-time-string fmt time
))
232 (t (setq date
(format-time-string "%Y-%m-%dT%H:%M:%S%z" time
))
233 (format "%s:%s" (substring date
0 -
2) (substring date -
2)))))))
235 (defun org-e-odt-begin-annotation (&optional author date
)
237 "<office:annotation>\n"
238 (and author
(org-e-odt-format-author author
))
239 (org-e-odt-format-tags
240 '("<dc:date>" .
"</dc:date>")
241 (org-e-odt-format-date
242 (or date
(plist-get org-lparse-opt-plist
:date
))))
243 (org-e-odt-begin-paragraph)))
245 (defun org-e-odt-end-annotation ()
246 "</office:annotation>")
248 (defun org-e-odt-begin-plain-list (ltype)
249 (let* ((style-name (org-e-odt-get-style-name-for-entity 'list ltype
))
251 ;; (if (or org-lparse-list-table-p
252 ;; (and (= 1 (length org-lparse-list-stack))
253 ;; (null org-e-odt-list-stack-stashed)))
254 ;; " text:continue-numbering=\"false\""
255 ;; " text:continue-numbering=\"true\"")
257 " text:continue-numbering=\"true\""
260 (format " text:style-name=\"%s\"" style-name
)))))
262 ((ordered unordered descriptive
)
264 ;; (org-e-odt-end-paragraph)
265 (format "<text:list%s>" extra
)))
266 (t (error "Unknown list type: %s" ltype
)))))
268 (defun org-e-odt-end-plain-list (ltype)
269 (if ltype
"</text:list>"
270 (error "Unknown list type: %s" ltype
)))
272 (defun org-e-odt-begin-list-item (ltype &optional arg headline
)
275 (assert (not headline
) t
)
276 (let* ((counter arg
) (extra ""))
277 (concat "<text:list-item>" ;; (org-e-odt-begin-paragraph)
279 ;; (if (= (length org-lparse-list-stack)
280 ;; (length org-e-odt-list-stack-stashed))
281 ;; "<text:list-header>" "<text:list-item>")
284 (let* ((id arg
) (extra ""))
287 ;; (org-e-odt-begin-paragraph)
288 (if headline
(org-e-odt-format-target headline id
)
289 (org-e-odt-format-bookmark "" id
)))
290 ;; (if (= (length org-lparse-list-stack)
291 ;; (length org-e-odt-list-stack-stashed))
292 ;; "<text:list-header>" "<text:list-item>")
295 (assert (not headline
) t
)
296 (let ((term (or arg
"(no term)")))
298 (org-e-odt-format-tags
299 '("<text:list-item>" .
"</text:list-item>")
300 (org-e-odt-format-stylized-paragraph 'definition-term term
))
301 (org-e-odt-begin-list-item 'unordered
)
302 (org-e-odt-begin-plain-list 'descriptive
)
303 (org-e-odt-begin-list-item 'unordered
))))
304 (t (error "Unknown list type"))))
306 (defun org-e-odt-end-list-item (ltype)
309 ;; (org-lparse-insert-tag
310 ;; (if (= (length org-lparse-list-stack)
311 ;; (length org-e-odt-list-stack-stashed))
312 ;; (prog1 "</text:list-header>"
313 ;; (setq org-e-odt-list-stack-stashed nil))
314 ;; "</text:list-item>")
320 (org-e-odt-end-list-item 'unordered
)
321 (org-e-odt-end-plain-list 'descriptive
)
322 (org-e-odt-end-list-item 'unordered
)
324 (t (error "Unknown list type"))))
326 (defun org-e-odt-write-automatic-styles ()
327 "Write automatic styles to \"content.xml\"."
329 (find-file-noselect (expand-file-name "content.xml") t
)
330 ;; position the cursor
331 (goto-char (point-min))
332 (re-search-forward " </office:automatic-styles>" nil t
)
333 (goto-char (match-beginning 0))
334 ;; write automatic table styles
335 (loop for
(style-name props
) in
336 (plist-get org-e-odt-automatic-styles
'Table
) do
337 (when (setq props
(or (plist-get props
:rel-width
) 96))
338 (insert (format org-e-odt-table-style-format style-name props
))))))
340 (defun org-e-odt-update-display-level (&optional level
)
342 (find-file-noselect (expand-file-name "content.xml") t
)
343 ;; position the cursor.
344 (goto-char (point-min))
345 ;; remove existing sequence decls.
346 (when (re-search-forward "<text:sequence-decls" nil t
)
347 (delete-region (match-beginning 0)
348 (re-search-forward "</text:sequence-decls>" nil nil
)))
351 <text:sequence-decls>")
352 (loop for x in org-e-odt-category-map-alist
354 <text:sequence-decl text:display-outline-level=\"%d\" text:name=\"%s\"/>"
357 </text:sequence-decls>")))
359 (defun org-e-odt-add-automatic-style (object-type &optional object-props
)
360 "Create an automatic style of type OBJECT-TYPE with param OBJECT-PROPS.
361 OBJECT-PROPS is (typically) a plist created by passing
362 \"#+ATTR_ODT: \" option of the object in question to
363 `org-e-odt-parse-block-attributes'.
365 Use `org-e-odt-object-counters' to generate an automatic
366 OBJECT-NAME and STYLE-NAME. If OBJECT-PROPS is non-nil, add a
367 new entry in `org-e-odt-automatic-styles'. Return (OBJECT-NAME
369 (assert (stringp object-type
))
370 (let* ((object (intern object-type
))
372 (seqno (1+ (or (plist-get org-e-odt-object-counters seqvar
) 0)))
373 (object-name (format "%s%d" object-type seqno
)) style-name
)
374 (setq org-e-odt-object-counters
375 (plist-put org-e-odt-object-counters seqvar seqno
))
377 (setq style-name
(format "Org%s" object-name
))
378 (setq org-e-odt-automatic-styles
379 (plist-put org-e-odt-automatic-styles object
380 (append (list (list style-name object-props
))
381 (plist-get org-e-odt-automatic-styles object
)))))
382 (cons object-name style-name
)))
384 (defun org-e-odt-begin-toc (lang-specific-heading max-level
)
387 <text:table-of-content text:style-name=\"Sect2\" text:protected=\"true\" text:name=\"Table of Contents1\">
388 <text:table-of-content-source text:outline-level=\"%d\">
389 <text:index-title-template text:style-name=\"Contents_20_Heading\">%s</text:index-title-template>
390 " max-level lang-specific-heading
)
392 (let ((entry-templates ""))
393 (loop for level from
1 upto
10
394 do
(setq entry-templates
395 (concat entry-templates
398 <text:table-of-content-entry-template text:outline-level=\"%d\" text:style-name=\"Contents_20_%d\">
399 <text:index-entry-link-start text:style-name=\"Internet_20_link\"/>
400 <text:index-entry-chapter/>
401 <text:index-entry-text/>
402 <text:index-entry-link-end/>
403 </text:table-of-content-entry-template>
408 </text:table-of-content-source>
411 <text:index-title text:style-name=\"Sect1\" text:name=\"Table of Contents1_Head\">
412 <text:p text:style-name=\"Contents_20_Heading\">%s</text:p>
414 " lang-specific-heading
)))
416 (defun org-e-odt-end-toc ()
419 </text:table-of-content>
422 (defun org-e-odt-format-toc-entry (snumber todo headline tags href
)
425 (setq headline
(concat
426 (and org-export-with-section-numbers
427 (concat snumber
". "))
431 (org-e-odt-format-spaces 3)
432 (org-e-odt-format-fontify tags
"tag")))))
434 (setq headline
(org-e-odt-format-fontify headline
"todo")))
436 (let ((org-e-odt-suppress-xref t
))
437 (org-e-odt-format-link headline
(concat "#" href
))))
439 (defun org-e-odt-format-toc-item (toc-entry level org-last-level
)
440 (let ((style (format "Contents_20_%d" level
)))
441 (concat "\n" (org-e-odt-format-stylized-paragraph style toc-entry
) "\n")))
443 ;; Following variable is let bound during 'ORG-LINK callback. See
446 (defun org-e-odt-format-link (desc href
&optional attr
)
448 ((and (= (string-to-char href
) ?
#) (not org-e-odt-suppress-xref
))
449 (setq href
(substring href
1))
450 (let ((xref-format "text"))
452 (setq desc
(format "%d" desc
) xref-format
"number"))
454 (setq desc
(mapconcat 'identity desc
".") xref-format
"chapter"))
455 (setq href
(concat org-e-odt-bookmark-prefix href
))
456 (org-e-odt-format-tags-simple
457 '("<text:bookmark-ref text:reference-format=\"%s\" text:ref-name=\"%s\">" .
458 "</text:bookmark-ref>")
459 desc xref-format href
)))
460 (org-lparse-link-description-is-image
461 (org-e-odt-format-tags
462 '("<draw:a xlink:type=\"simple\" xlink:href=\"%s\" %s>" .
"</draw:a>")
463 desc href
(or attr
"")))
465 (org-e-odt-format-tags-simple
466 '("<text:a xlink:type=\"simple\" xlink:href=\"%s\" %s>" .
"</text:a>")
467 desc href
(or attr
"")))))
469 (defun org-e-odt-format-spaces (n)
473 " " (org-e-odt-format-tags "<text:s text:c=\"%d\"/>" "" (1- n
))))
476 (defun org-e-odt-format-tabs (&optional n
)
477 (let ((tab "<text:tab/>")
481 (defun org-e-odt-format-line-break ()
482 (org-e-odt-format-tags "<text:line-break/>" ""))
484 (defun org-e-odt-format-horizontal-line ()
485 (org-e-odt-format-stylized-paragraph 'horizontal-line
""))
487 (defun org-e-odt-encode-plain-text (line &optional no-whitespace-filling
)
488 (setq line
(org-e-html-encode-plain-text line
))
489 (if no-whitespace-filling line
490 (org-e-odt-fill-tabs-and-spaces line
)))
492 (defun org-e-odt-format-line (line)
493 (case org-lparse-dyn-current-environment
495 (org-e-odt-format-stylized-paragraph
496 'fixedwidth
(org-e-odt-encode-plain-text line
)) "\n"))
497 (t (concat line
"\n"))))
499 (defun org-e-odt-format-comment (fmt &rest args
)
500 (let ((comment (apply 'format fmt args
)))
501 (format "\n<!-- %s -->\n" comment
)))
503 (defun org-e-odt-format-org-entity (wd)
504 (org-entity-get-representation wd
'utf8
))
506 (defun org-e-odt-fill-tabs-and-spaces (line)
507 (replace-regexp-in-string
508 "\\([\t]\\|\\([ ]+\\)\\)" (lambda (s)
510 ((string= s
"\t") (org-e-odt-format-tabs))
511 (t (org-e-odt-format-spaces (length s
))))) line
))
513 (defun org-e-odt-hfy-face-to-css (fn)
514 "Create custom style for face FN.
515 When FN is the default face, use it's foreground and background
516 properties to create \"OrgSrcBlock\" paragraph style. Otherwise
517 use it's color attribute to create a character style whose name
518 is obtained from FN. Currently all attributes of FN other than
521 The style name for a face FN is derived using the following
522 operations on the face name in that order - de-dash, CamelCase
523 and prefix with \"OrgSrc\". For example,
524 `font-lock-function-name-face' is associated with
525 \"OrgSrcFontLockFunctionNameFace\"."
526 (let* ((css-list (hfy-face-to-style fn
))
527 (style-name ((lambda (fn)
530 'capitalize
(split-string
531 (hfy-face-or-def-to-name fn
) "-")
533 (color-val (cdr (assoc "color" css-list
)))
534 (background-color-val (cdr (assoc "background" css-list
)))
535 (style (and org-e-odt-create-custom-styles-for-srcblocks
538 (format org-src-block-paragraph-format
539 background-color-val color-val
))
543 <style:style style:name=\"%s\" style:family=\"text\">
544 <style:text-properties fo:color=\"%s\"/>
545 </style:style>" style-name color-val
))))))
546 (cons style-name style
)))
548 (defun org-e-odt-insert-custom-styles-for-srcblocks (styles)
549 "Save STYLES used for colorizing of source blocks.
550 Update styles.xml with styles that were collected as part of
551 `org-e-odt-hfy-face-to-css' callbacks."
554 (find-file-noselect (expand-file-name "styles.xml") t
)
555 (goto-char (point-min))
556 (when (re-search-forward "</office:styles>" nil t
)
557 (goto-char (match-beginning 0))
558 (insert "\n<!-- Org Htmlfontify Styles -->\n" styles
"\n")))))
560 (defun org-e-odt-remap-stylenames (style-name)
562 (cdr (assoc style-name
'(("timestamp-wrapper" .
"OrgTimestampWrapper")
563 ("timestamp" .
"OrgTimestamp")
564 ("timestamp-kwd" .
"OrgTimestampKeyword")
568 ("target" .
"OrgTarget"))))
571 (defun org-e-odt-format-fontify (text style
&optional id
)
575 (org-e-odt-remap-stylenames style
))
577 (org-e-odt-get-style-name-for-entity 'character style
))
579 (assert (< 1 (length style
)))
580 (let ((parent-style (pop style
)))
581 (mapconcat (lambda (s)
582 ;; (assert (stringp s) t)
583 (org-e-odt-remap-stylenames s
)) style
"")
584 (org-e-odt-remap-stylenames parent-style
)))
585 (t (error "Don't how to handle style %s" style
)))))
586 (org-e-odt-format-tags-simple
587 '("<text:span text:style-name=\"%s\">" .
"</text:span>")
590 (defun org-e-odt-relocate-relative-path (path dir
)
591 (if (file-name-absolute-p path
) path
592 (file-relative-name (expand-file-name path dir
)
593 (expand-file-name "eyecandy" dir
))))
595 (defun org-e-odt-format-formula (element info
)
597 ((eq (org-element-type element
) 'link
) ; FIXME
598 (let* ((type (org-element-property :type element
))
599 (raw-path (org-element-property :path element
)))
601 ((file-name-absolute-p raw-path
)
602 (expand-file-name raw-path
))
604 ((member (org-element-type element
)
605 '(latex-fragment latex-environment
))
606 (let* ((latex-frag (org-remove-indentation
607 (org-element-property
609 (formula-link (org-e-odt-format-latex
610 latex-frag
'mathml
)))
612 (string-match "file:\\([^]]*\\)" formula-link
)
613 (match-string 1 formula-link
))))
614 (t (error "what is this?"))))
616 (case (org-element-type element
)
617 (link (org-export-get-parent-paragraph element info
))
619 (captions (org-e-odt-format-label caption-from info
'definition
))
620 (caption (car captions
))
622 (org-e-odt-format-tags
623 "<draw:object xlink:href=\"%s\" xlink:type=\"simple\" xlink:show=\"embed\" xlink:actuate=\"onLoad\"/>" ""
624 (file-name-directory (org-e-odt-copy-formula-file src
))))
625 (embed-as (if caption
'paragraph
'character
))
628 ((eq embed-as
'character
)
629 (org-e-odt-format-entity "InlineFormula" href width height
))
631 (let ((table-info nil
)
633 '(:alignment
["c" "c"]
634 :column-groups
[nil nil
]
636 :special-column-p nil
:width
[8 1]))
637 (org-lparse-table-ncols 2)) ; FIXME
638 (org-e-odt-list-table ; FIXME
641 (org-e-odt-format-entity
642 "CaptionedDisplayFormula" href width height captions
)
643 (let* ((org-e-odt-category-map-alist
644 '(("__Table__" "Table" "value")
645 ("__Figure__" "Illustration" "value")
646 ("__MathFormula__" "Text" "math-label")
647 ("__DvipngImage__" "Equation" "value")
648 ("__Listing__" "Listing" "value"))))
649 (car (org-e-odt-format-label caption-from info
'definition
)))))
650 '(table (:attr_odt
(":style \"OrgEquation\""))) info
))))))
652 (defun org-e-odt-copy-formula-file (path)
653 "Returns the internal name of the file"
654 (let* ((src-file (expand-file-name
655 path
(file-name-directory org-current-export-file
)))
656 (target-dir (format "Formula-%04d/"
657 (incf org-e-odt-embedded-formulas-count
)))
658 (target-file (concat target-dir
"content.xml")))
659 (message "Embedding %s as %s ..."
660 (substring-no-properties path
) target-file
)
662 (make-directory target-dir
)
663 (org-e-odt-create-manifest-file-entry
664 "application/vnd.oasis.opendocument.formula" target-dir
"1.2")
666 (case (org-e-odt-is-formula-link-p src-file
)
668 (copy-file src-file target-file
'overwrite
))
670 (org-e-odt-zip-extract-one src-file
"content.xml" target-dir
))
672 (error "%s is not a formula file" src-file
)))
674 (org-e-odt-create-manifest-file-entry "text/xml" target-file
)
677 (defun org-e-odt-is-formula-link-p (file)
678 (let ((case-fold-search nil
))
680 ((string-match "\\.\\(mathml\\|mml\\)\\'" file
)
682 ((string-match "\\.odf\\'" file
)
685 (defun org-e-odt-format-org-link (opt-plist type-1 path fragment desc attr
687 "Make a OpenDocument link.
688 OPT-PLIST is an options list.
689 TYPE-1 is the device-type of the link (THIS://foo.html).
690 PATH is the path of the link (http://THIS#location).
691 FRAGMENT is the fragment part of the link, if any (foo.html#THIS).
692 DESC is the link description, if any.
693 ATTR is a string of other attributes of the a element."
694 (declare (special org-lparse-par-open
))
697 (and (member type-1
'("http" "https" "file"))
698 (org-lparse-should-inline-p path descp
)
700 (type (if (equal type-1
"id") "file" type-1
))
704 ;; check for inlined images
705 ((and (member type
'("file"))
708 filename org-e-odt-inline-image-extensions
)
710 (org-e-odt-format-inline-image thefile
))
711 ;; check for embedded formulas
712 ((and (member type
'("file"))
714 (org-e-odt-is-formula-link-p filename
)
716 (org-e-odt-format-formula thefile
))
717 ((string= type
"coderef")
718 (let* ((ref fragment
)
719 (lineno-or-ref (cdr (assoc ref org-export-code-refs
)))
720 (desc (and descp desc
))
721 (org-e-odt-suppress-xref nil
)
722 (href (org-xml-format-href (concat "#coderef-" ref
))))
724 ((and (numberp lineno-or-ref
) (not desc
))
725 (org-e-odt-format-link lineno-or-ref href
))
726 ((and (numberp lineno-or-ref
) desc
727 (string-match (regexp-quote (concat "(" ref
")")) desc
))
728 (format (replace-match "%s" t t desc
)
729 (org-e-odt-format-link lineno-or-ref href
)))
732 (if (and desc
(string-match
733 (regexp-quote (concat "(" ref
")"))
735 (replace-match "%s" t t desc
)
738 (org-e-odt-format-link (org-xml-format-desc desc
) href
)))))
740 (when (string= type
"file")
743 ((file-name-absolute-p path
)
744 (concat "file://" (expand-file-name path
)))
745 (t (org-e-odt-relocate-relative-path
746 thefile org-current-export-file
)))))
748 (when (and (member type
'("" "http" "https" "file")) fragment
)
749 (setq thefile
(concat thefile
"#" fragment
)))
751 (setq thefile
(org-xml-format-href thefile
))
753 (when (not (member type
'("" "file")))
754 (setq thefile
(concat type
":" thefile
)))
756 (let ((org-e-odt-suppress-xref nil
))
757 (org-e-odt-format-link
758 (org-xml-format-desc desc
) thefile attr
)))))))
760 (defun org-e-odt-format-anchor (text name
&optional class
)
761 (org-e-odt-format-target text name
))
763 (defun org-e-odt-format-bookmark (text id
)
765 (org-e-odt-format-tags "<text:bookmark text:name=\"%s\"/>" text id
)
768 (defun org-e-odt-format-target (text id
)
769 (let ((name (concat org-e-odt-bookmark-prefix id
)))
771 (and id
(org-e-odt-format-tags
772 "<text:bookmark-start text:name=\"%s\"/>" "" name
))
773 (org-e-odt-format-bookmark text id
)
774 (and id
(org-e-odt-format-tags
775 "<text:bookmark-end text:name=\"%s\"/>" "" name
)))))
777 (defun org-e-odt-format-footnote (n def
)
778 (setq n
(format "%d" n
))
779 (let ((id (concat "fn" n
))
780 (note-class "footnote")
781 (par-style "Footnote"))
782 (org-e-odt-format-tags-simple
783 '("<text:note text:id=\"%s\" text:note-class=\"%s\">" .
"</text:note>")
785 (org-e-odt-format-tags-simple
786 '("<text:note-citation>" .
"</text:note-citation>") n
)
787 (org-e-odt-format-tags-simple
788 '("<text:note-body>" .
"</text:note-body>") def
))
791 (defun org-e-odt-format-footnote-reference (n def refcnt
)
793 (org-e-odt-format-footnote n def
)
794 (org-e-odt-format-footnote-ref n
)))
796 (defun org-e-odt-format-footnote-ref (n)
797 (setq n
(format "%d" n
))
798 (let ((note-class "footnote")
800 (ref-name (concat "fn" n
)))
801 (org-e-odt-format-tags-simple
802 '("<text:span text:style-name=\"%s\">" .
"</text:span>")
803 (org-e-odt-format-tags-simple
804 '("<text:note-ref text:note-class=\"%s\" text:reference-format=\"%s\" text:ref-name=\"%s\">" .
"</text:note-ref>")
805 n note-class ref-format ref-name
)
808 (defun org-e-odt-element-attributes (element info
)
809 (let* ((raw-attr (org-element-property :attr_odt element
))
810 (raw-attr (and raw-attr
811 (org-trim (mapconcat #'identity raw-attr
" ")))))
812 (unless (and raw-attr
(string-match "\\`(.*)\\'" raw-attr
))
813 (setq raw-attr
(format "(%s)" raw-attr
)))
814 (ignore-errors (read raw-attr
))))
816 (defun org-e-odt-format-object-description (title description
)
817 (concat (and title
(org-e-odt-format-tags
818 '("<svg:title>" .
"</svg:title>")
819 (org-e-odt-encode-plain-text title t
)))
820 (and description
(org-e-odt-format-tags
821 '("<svg:desc>" .
"</svg:desc>")
822 (org-e-odt-encode-plain-text description t
)))))
824 (defun org-e-odt-format-frame (text width height style
&optional
828 (if width
(format " svg:width=\"%0.2fcm\"" width
) "")
829 (if height
(format " svg:height=\"%0.2fcm\"" height
) "")
831 (format " text:anchor-type=\"%s\"" (or anchor-type
"paragraph")))))
832 (org-e-odt-format-tags
833 '("<draw:frame draw:style-name=\"%s\"%s>" .
"</draw:frame>")
834 (concat text
(org-e-odt-format-object-description
835 (get-text-property 0 :title text
)
836 (get-text-property 0 :description text
)))
839 (defun org-e-odt-format-textbox (text width height style
&optional
841 (org-e-odt-format-frame
842 (org-e-odt-format-tags
843 '("<draw:text-box %s>" .
"</draw:text-box>")
844 text
(concat (format " fo:min-height=\"%0.2fcm\"" (or height
.2))
846 (format " fo:min-width=\"%0.2fcm\"" (or width
.2)))))
847 width nil style extra anchor-type
))
849 (defun org-e-odt-merge-frame-params(default-frame-params user-frame-params
)
850 (if (not user-frame-params
) default-frame-params
851 (assert (= (length default-frame-params
) 3))
852 (assert (= (length user-frame-params
) 3))
853 (loop for user-frame-param in user-frame-params
854 for default-frame-param in default-frame-params
855 collect
(or user-frame-param default-frame-param
))))
857 (defun org-e-odt-copy-image-file (path)
858 "Returns the internal name of the file"
859 (let* ((image-type (file-name-extension path
))
860 (media-type (format "image/%s" image-type
))
861 (src-file (expand-file-name
862 path
(file-name-directory org-current-export-file
)))
863 (target-dir "Images/")
865 (format "%s%04d.%s" target-dir
866 (incf org-e-odt-embedded-images-count
) image-type
)))
867 (message "Embedding %s as %s ..."
868 (substring-no-properties path
) target-file
)
870 (when (= 1 org-e-odt-embedded-images-count
)
871 (make-directory target-dir
)
872 (org-e-odt-create-manifest-file-entry "" target-dir
))
874 (copy-file src-file target-file
'overwrite
)
875 (org-e-odt-create-manifest-file-entry media-type target-file
)
878 (defun org-e-odt-do-image-size (probe-method file
&optional dpi anchor-type
)
879 (setq dpi
(or dpi org-e-odt-pixels-per-inch
))
880 (setq anchor-type
(or anchor-type
"paragraph"))
881 (flet ((size-in-cms (size-in-pixels)
882 (flet ((pixels-to-cms (pixels)
883 (let* ((cms-per-inch 2.54)
884 (inches (/ pixels dpi
)))
885 (* cms-per-inch inches
))))
887 (cons (pixels-to-cms (car size-in-pixels
))
888 (pixels-to-cms (cdr size-in-pixels
)))))))
891 (size-in-cms (ignore-errors ; Emacs could be in batch mode
893 (image-size (create-image file
) 'pixels
))))
896 (let ((dim (shell-command-to-string
897 (format "identify -format \"%%w:%%h\" \"%s\"" file
))))
898 (when (string-match "\\([0-9]+\\):\\([0-9]+\\)" dim
)
899 (cons (string-to-number (match-string 1 dim
))
900 (string-to-number (match-string 2 dim
)))))))
902 (cdr (assoc-string anchor-type
903 org-e-odt-default-image-sizes-alist
))))))
905 (defun org-e-odt-image-size-from-file (file &optional user-width
906 user-height scale dpi embed-as
)
907 (unless (file-name-absolute-p file
)
908 (setq file
(expand-file-name
909 file
(file-name-directory org-current-export-file
))))
910 (let* (size width height
)
911 (unless (and user-height user-width
)
912 (loop for probe-method in org-e-odt-image-size-probe-method
914 do
(setq size
(org-e-odt-do-image-size
915 probe-method file dpi embed-as
)))
916 (or size
(error "Cannot determine Image size. Aborting ..."))
917 (setq width
(car size
) height
(cdr size
)))
920 (setq width
(* width scale
) height
(* height scale
)))
921 ((and user-height user-width
)
922 (setq width user-width height user-height
))
924 (setq width
(* user-height
(/ width height
)) height user-height
))
926 (setq height
(* user-width
(/ height width
)) width user-width
))
928 ;; ensure that an embedded image fits comfortably within a page
929 (let ((max-width (car org-e-odt-max-image-size
))
930 (max-height (cdr org-e-odt-max-image-size
)))
931 (when (or (> width max-width
) (> height max-height
))
932 (let* ((scale1 (/ max-width width
))
933 (scale2 (/ max-height height
))
934 (scale (min scale1 scale2
)))
935 (setq width
(* scale width
) height
(* scale height
)))))
936 (cons width height
)))
938 (defun org-e-odt-format-label (element info op
)
940 (case (org-element-type element
)
941 (link (org-export-get-parent-paragraph element info
))
943 ;; get label and caption.
944 (label (org-element-property :name caption-from
))
945 (caption (org-element-property :caption caption-from
))
946 (short-caption (cdr caption
))
947 ;; transcode captions.
948 (caption (and (car caption
) (org-export-data (car caption
) info
)))
949 (short-caption (and short-caption
950 (org-export-data short-caption info
))))
951 (when (or label caption
)
952 (let* ((default-category
954 ((eq (org-element-type element
) 'table
)
956 ((org-e-odt-standalone-image-p element info
)
958 ((member (org-element-type element
)
959 '(latex-environment latex-fragment
))
960 (let ((processing-type (plist-get info
:LaTeX-fragments
)))
962 ((eq processing-type
'dvipng
) "__DvipngImage__")
963 ((eq processing-type
'mathjax
) "__MathFormula__")
964 ((eq processing-type
't
) "__MathFormula__")
965 (t (error "Handle LaTeX:verbatim")))))
966 ((eq (org-element-type element
) 'src-block
)
968 (t (error "Handle enumeration of %S" element
))))
971 ((member (org-element-type element
)
972 '(table latex-environment src-block
))
974 ((org-e-odt-standalone-image-p element info
)
975 'org-e-odt-standalone-image-p
)
976 (t (error "Handle enumeration of %S" element
))))
977 (seqno (org-e-odt-enumerate-element
978 element info predicate
)) ; FIXME
979 ;; handle label props.
980 (label-props (assoc default-category org-e-odt-category-map-alist
))
981 ;; identify opendocument counter
982 (counter (nth 1 label-props
))
983 ;; identify label style
984 (label-style (nth 2 label-props
))
985 ;; grok language setting
986 (en-strings (assoc-default "en" org-e-odt-category-strings
))
987 (lang (plist-get info
:language
)) ; FIXME
988 (lang-strings (assoc-default lang org-e-odt-category-strings
))
989 ;; retrieve localized category sting
990 (pos (- (length org-e-odt-category-map-alist
)
991 (length (memq label-props org-e-odt-category-map-alist
))))
992 (category (or (nth pos lang-strings
) (nth pos en-strings
))))
995 ;; assign an internal label, if user has not provided one
996 (setq label
(or label
(format "%s-%s" default-category seqno
)))
997 (setq label
(org-solidify-link-text label
))
1001 (cadr (assoc-string label-style org-e-odt-label-styles t
))
1003 (?n .
,(org-e-odt-format-tags-simple
1004 '("<text:sequence text:ref-name=\"%s\" text:name=\"%s\" text:formula=\"ooow:%s+1\" style:num-format=\"1\">" .
"</text:sequence>")
1005 seqno label counter counter
))
1006 (?c .
,(or caption
""))))
1010 (setq label
(org-solidify-link-text label
))
1011 (let* ((fmt (cddr (assoc-string label-style org-e-odt-label-styles t
)))
1014 (org-e-odt-format-tags-simple
1015 '("<text:sequence-ref text:reference-format=\"%s\" text:ref-name=\"%s\">"
1016 .
"</text:sequence-ref>")
1017 (format-spec fmt2
`((?e .
,category
)
1018 (?n .
,seqno
))) fmt1 label
)))
1019 (t (error "Unknow %S on label" op
)))))))
1021 (defun org-e-odt-format-tags-1 (tag text prefix suffix
&rest args
)
1024 (concat prefix
(apply 'format
(car tag
) args
) text suffix
1025 (format (cdr tag
))))
1026 ((stringp tag
) ; singleton tag
1027 (concat prefix
(apply 'format tag args
) text
))))
1029 (defun org-e-odt-format-tags (tag text
&rest args
)
1030 (apply 'org-e-odt-format-tags-1 tag text
"\n" "\n" args
))
1032 (defun org-e-odt-format-tags-simple (tag text
&rest args
)
1033 (apply 'org-e-odt-format-tags-1 tag text nil nil args
))
1035 (defun org-e-odt-init-outfile ()
1036 (unless (executable-find "zip")
1037 ;; Not at all OSes ship with zip by default
1038 (error "Executable \"zip\" needed for creating OpenDocument files"))
1040 (let* ((outdir (make-temp-file
1041 (format org-e-odt-tmpdir-prefix
'odt
) t
)) ; FIXME
1042 (content-file (expand-file-name "content.xml" outdir
)))
1045 (setq org-e-odt-manifest-file-entries nil
1046 org-e-odt-embedded-images-count
0
1047 org-e-odt-embedded-formulas-count
0
1048 org-e-odt-section-count
0
1049 org-e-odt-entity-labels-alist nil
1050 org-e-odt-list-stack-stashed nil
1051 org-e-odt-automatic-styles nil
1052 org-e-odt-object-counters nil
1053 org-e-odt-entity-counts-plist nil
)
1055 ;; let `htmlfontify' know that we are interested in collecting
1058 (setq hfy-user-sheet-assoc nil
)
1061 (with-current-buffer
1062 (find-file-noselect content-file t
)
1065 (defun org-e-odt-save-as-outfile (target opt-plist
)
1066 ;; write automatic styles
1067 (org-e-odt-write-automatic-styles)
1069 ;; update display levels
1070 (org-e-odt-update-display-level org-e-odt-display-outline-level
)
1072 ;; write styles file
1073 ;; (when (equal org-lparse-backend 'odt) FIXME
1076 ;; (org-e-odt-update-styles-file opt-plist)
1078 ;; create mimetype file
1079 (let ((mimetype (org-e-odt-write-mimetype-file ;; org-lparse-backend FIXME
1081 (org-e-odt-create-manifest-file-entry mimetype
"/" "1.2"))
1083 ;; create a manifest entry for content.xml
1084 (org-e-odt-create-manifest-file-entry "text/xml" "content.xml")
1086 ;; write out the manifest entries before zipping
1087 (org-e-odt-write-manifest-file)
1089 (let ((xml-files '("mimetype" "META-INF/manifest.xml" "content.xml"
1091 (zipdir default-directory
))
1092 (when (or t
(equal org-lparse-backend
'odt
)) ; FIXME
1093 (push "styles.xml" xml-files
))
1094 (message "Switching to directory %s" (expand-file-name zipdir
))
1096 ;; save all xml files
1097 (mapc (lambda (file)
1098 (with-current-buffer
1099 (find-file-noselect (expand-file-name file
) t
)
1100 ;; prettify output if needed
1101 (when org-e-odt-prettify-xml
1102 (indent-region (point-min) (point-max)))
1106 (let* ((target-name (file-name-nondirectory target
))
1107 (target-dir (file-name-directory target
))
1108 (cmds `(("zip" "-mX0" ,target-name
"mimetype")
1109 ("zip" "-rmTq" ,target-name
"."))))
1110 (when (file-exists-p target
)
1111 ;; FIXME: If the file is locked this throws a cryptic error
1112 (delete-file target
))
1114 (let ((coding-system-for-write 'no-conversion
) exitcode err-string
)
1115 (message "Creating odt file...")
1118 (message "Running %s" (mapconcat 'identity cmd
" "))
1120 (with-output-to-string
1122 (apply 'call-process
(car cmd
)
1123 nil standard-output nil
(cdr cmd
)))))
1124 (or (zerop exitcode
)
1125 (ignore (message "%s" err-string
))
1126 (error "Unable to create odt file (%S)" exitcode
)))
1129 ;; move the file from outdir to target-dir
1130 (rename-file target-name target-dir
)
1132 ;; kill all xml buffers
1133 (mapc (lambda (file)
1135 (find-file-noselect (expand-file-name file zipdir
) t
)))
1138 (delete-directory zipdir
)))
1139 (message "Created %s" target
)
1140 (set-buffer (find-file-noselect target t
)))
1143 (defun org-e-odt-create-manifest-file-entry (&rest args
)
1144 (push args org-e-odt-manifest-file-entries
))
1146 (defun org-e-odt-write-manifest-file ()
1147 (make-directory "META-INF")
1148 (let ((manifest-file (expand-file-name "META-INF/manifest.xml")))
1149 (with-current-buffer
1150 (find-file-noselect manifest-file t
)
1152 "<?xml version=\"1.0\" encoding=\"UTF-8\"?>
1153 <manifest:manifest xmlns:manifest=\"urn:oasis:names:tc:opendocument:xmlns:manifest:1.0\" manifest:version=\"1.2\">\n")
1155 (lambda (file-entry)
1156 (let* ((version (nth 2 file-entry
))
1158 (format " manifest:version=\"%s\"" version
)
1161 (format org-e-odt-manifest-file-entry-tag
1162 (nth 0 file-entry
) (nth 1 file-entry
) extra
))))
1163 org-e-odt-manifest-file-entries
)
1164 (insert "\n</manifest:manifest>"))))
1166 (defun org-e-odt-update-meta-file (info) ; FIXME opt-plist
1167 (let ((title (org-export-data (plist-get info
:title
) info
))
1168 (author (or (let ((auth (plist-get info
:author
)))
1169 (and auth
(org-export-data auth info
))) ""))
1170 (date (org-e-odt-format-date (plist-get info
:date
)))
1171 (email (plist-get info
:email
))
1172 (keywords (plist-get info
:keywords
))
1173 (description (plist-get info
:description
)))
1176 "<?xml version=\"1.0\" encoding=\"UTF-8\"?>
1177 <office:document-meta
1178 xmlns:office=\"urn:oasis:names:tc:opendocument:xmlns:office:1.0\"
1179 xmlns:xlink=\"http://www.w3.org/1999/xlink\"
1180 xmlns:dc=\"http://purl.org/dc/elements/1.1/\"
1181 xmlns:meta=\"urn:oasis:names:tc:opendocument:xmlns:meta:1.0\"
1182 xmlns:ooo=\"http://openoffice.org/2004/office\"
1183 office:version=\"1.2\">
1185 (org-e-odt-format-author author
) "\n"
1186 (format "<meta:initial-creator>%s</meta:initial-creator>\n" author
)
1187 (format "<dc:date>%s</dc:date>\n" date
)
1188 (format "<meta:creation-date>%s</meta:creation-date>\n" date
)
1189 (format "<meta:generator>%s</meta:generator>\n"
1190 (concat (and org-export-creator-info org-export-creator-string
)))
1191 (format "<meta:keyword>%s</meta:keyword>\n" keywords
)
1192 (format "<dc:subject>%s</dc:subject>\n" description
)
1193 (format "<dc:title>%s</dc:title>\n" title
)
1195 " </office:meta>\n" "</office:document-meta>")
1196 nil
(expand-file-name "meta.xml")))
1198 ;; create a manifest entry for meta.xml
1199 (org-e-odt-create-manifest-file-entry "text/xml" "meta.xml"))
1201 (defun org-e-odt-update-styles-file (info)
1202 ;; write styles file
1203 (let ((styles-file (plist-get info
:odt-styles-file
)))
1204 (org-e-odt-copy-styles-file (and styles-file
1205 (read (org-trim styles-file
))))
1207 ;; FIXME: Who is opening an empty styles.xml before this point?
1208 (with-current-buffer
1209 (find-file-noselect (expand-file-name "styles.xml") t
)
1210 (revert-buffer t t
)))
1212 ;; Write custom styles for source blocks
1213 (org-e-odt-insert-custom-styles-for-srcblocks
1216 (format " %s\n" (cddr style
)))
1217 hfy-user-sheet-assoc
"")))
1219 (defun org-e-odt-write-mimetype-file (format)
1220 ;; create mimetype file
1223 (odt "application/vnd.oasis.opendocument.text")
1224 (odf "application/vnd.oasis.opendocument.formula")
1225 (t (error "Unknown OpenDocument backend %S" org-lparse-backend
)))))
1226 (write-region mimetype nil
(expand-file-name "mimetype"))
1229 (declare-function org-create-math-formula
"org"
1230 (latex-frag &optional mathml-file
))
1232 (defun org-e-odt-get (what &optional opt-plist
)
1234 (EXPORT-DIR (org-export-directory :html opt-plist
))
1235 (TABLE-FIRST-COLUMN-AS-LABELS nil
)
1236 (CODING-SYSTEM-FOR-WRITE 'utf-8
)
1237 (CODING-SYSTEM-FOR-SAVE 'utf-8
)
1238 (t (error "Unknown property: %s" what
))))
1240 (defun org-e-odt-do-preprocess-latex-fragments ()
1241 "Convert LaTeX fragments to images."
1242 (let* ((latex-frag-opt (plist-get org-lparse-opt-plist
:LaTeX-fragments
))
1243 (latex-frag-opt ; massage the options
1244 (or (and (member latex-frag-opt
'(mathjax t
))
1245 (not (and (fboundp 'org-format-latex-mathml-available-p
)
1246 (org-format-latex-mathml-available-p)))
1247 (prog1 org-lparse-latex-fragment-fallback
1250 "LaTeX to MathML converter not available. "
1251 (format "Using %S instead."
1252 org-lparse-latex-fragment-fallback
)))))
1254 cache-dir display-msg
)
1256 ((eq latex-frag-opt
'dvipng
)
1257 (setq cache-dir
"ltxpng/")
1258 (setq display-msg
"Creating LaTeX image %s"))
1259 ((member latex-frag-opt
'(mathjax t
))
1260 (setq latex-frag-opt
'mathml
)
1261 (setq cache-dir
"ltxmathml/")
1262 (setq display-msg
"Creating MathML formula %s")))
1263 (when (and org-current-export-file
)
1265 (concat cache-dir
(file-name-sans-extension
1266 (file-name-nondirectory org-current-export-file
)))
1267 org-current-export-dir nil display-msg
1268 nil nil latex-frag-opt
))))
1270 (eval-after-load 'org-odt
1271 '(ad-deactivate 'org-format-latex-as-mathml
))
1275 ;; (defadvice org-format-latex-as-mathml ; FIXME
1276 ;; (after org-e-odt-protect-latex-fragment activate)
1277 ;; "Encode LaTeX fragment as XML.
1278 ;; Do this when translation to MathML fails."
1279 ;; (when (or (not (> (length ad-return-value) 0))
1280 ;; (get-text-property 0 'org-protected ad-return-value))
1281 ;; (setq ad-return-value
1282 ;; (org-propertize (org-e-odt-encode-plain-text (ad-get-arg 0))
1283 ;; 'org-protected t))))
1285 (defun org-e-odt-zip-extract-one (archive member
&optional target
)
1287 (let* ((target (or target default-directory
))
1288 (archive (expand-file-name archive
))
1289 (archive-zip-extract
1290 (list "unzip" "-qq" "-o" "-d" target
))
1291 exit-code command-output
)
1292 (setq command-output
1294 (setq exit-code
(archive-zip-extract archive member
))
1296 (unless (zerop exit-code
)
1297 (message command-output
)
1298 (error "Extraction failed"))))
1300 (defun org-e-odt-zip-extract (archive members
&optional target
)
1301 (when (atom members
) (setq members
(list members
)))
1302 (mapc (lambda (member)
1303 (org-e-odt-zip-extract-one archive member target
))
1306 (defun org-e-odt-copy-styles-file (&optional styles-file
)
1307 ;; Non-availability of styles.xml is not a critical error. For now
1308 ;; throw an error purely for aesthetic reasons.
1309 (setq styles-file
(or styles-file
1310 org-e-odt-styles-file
1311 (expand-file-name "OrgOdtStyles.xml"
1312 org-e-odt-styles-dir
)
1313 (error "org-e-odt: Missing styles file?")))
1315 ((listp styles-file
)
1316 (let ((archive (nth 0 styles-file
))
1317 (members (nth 1 styles-file
)))
1318 (org-e-odt-zip-extract archive members
)
1321 (when (org-file-image-p member
)
1322 (let* ((image-type (file-name-extension member
))
1323 (media-type (format "image/%s" image-type
)))
1324 (org-e-odt-create-manifest-file-entry media-type member
))))
1326 ((and (stringp styles-file
) (file-exists-p styles-file
))
1327 (let ((styles-file-type (file-name-extension styles-file
)))
1329 ((string= styles-file-type
"xml")
1330 (copy-file styles-file
(expand-file-name "styles.xml") t
))
1331 ((member styles-file-type
'("odt" "ott"))
1332 (org-e-odt-zip-extract styles-file
"styles.xml")))))
1334 (error (format "Invalid specification of styles.xml file: %S"
1335 org-e-odt-styles-file
))))
1337 ;; create a manifest entry for styles.xml
1338 (org-e-odt-create-manifest-file-entry "text/xml" "styles.xml"))
1340 (defun org-e-odt-configure-outline-numbering ()
1341 "Outline numbering is retained only upto LEVEL.
1342 To disable outline numbering pass a LEVEL of 0."
1343 (goto-char (point-min))
1345 "<text:outline-level-style\\([^>]*\\)text:level=\"\\([^\"]*\\)\"\\([^>]*\\)>")
1347 "<text:outline-level-style\\1text:level=\"\\2\" style:num-format=\"\">"))
1348 (while (re-search-forward regex nil t
)
1349 (unless (let ((sec-num (plist-get info
:section-numbers
))
1350 (level (string-to-number (match-string 2))))
1351 (if (wholenump sec-num
) (<= level sec-num
) sec-num
))
1352 (replace-match replacement t nil
))))
1356 (defun org-export-as-odf (latex-frag &optional odf-file
)
1357 "Export LATEX-FRAG as OpenDocument formula file ODF-FILE.
1358 Use `org-create-math-formula' to convert LATEX-FRAG first to
1359 MathML. When invoked as an interactive command, use
1360 `org-latex-regexps' to infer LATEX-FRAG from currently active
1361 region. If no LaTeX fragments are found, prompt for it. Push
1362 MathML source to kill ring, if `org-export-copy-to-kill-ring' is
1366 (setq frag
(and (setq frag
(and (region-active-p)
1367 (buffer-substring (region-beginning)
1369 (loop for e in org-latex-regexps
1370 thereis
(when (string-match (nth 1 e
) frag
)
1371 (match-string (nth 2 e
) frag
)))))
1372 (read-string "LaTeX Fragment: " frag nil frag
))
1373 ,(let ((odf-filename (expand-file-name
1375 (file-name-sans-extension
1376 (or (file-name-nondirectory buffer-file-name
)))
1378 (file-name-directory buffer-file-name
))))
1379 (read-file-name "ODF filename: " nil odf-filename nil
1380 (file-name-nondirectory odf-filename
)))))
1381 (let* ((org-lparse-backend 'odf
)
1382 org-lparse-opt-plist
1383 (filename (or odf-file
1386 (file-name-sans-extension
1387 (or (file-name-nondirectory buffer-file-name
)))
1389 (file-name-directory buffer-file-name
))))
1390 (buffer (find-file-noselect (org-e-odt-init-outfile filename
)))
1391 (coding-system-for-write 'utf-8
)
1392 (save-buffer-coding-system 'utf-8
))
1394 (set-buffer-file-coding-system coding-system-for-write
)
1395 (let ((mathml (org-create-math-formula latex-frag
)))
1396 (unless mathml
(error "No Math formula created"))
1398 (or (org-export-push-to-kill-ring
1399 (upcase (symbol-name org-lparse-backend
)))
1400 (message "Exporting... done")))
1401 (org-e-odt-save-as-outfile filename nil
; FIXME
1405 (defun org-export-as-odf-and-open ()
1406 "Export LaTeX fragment as OpenDocument formula and immediately open it.
1407 Use `org-export-as-odf' to read LaTeX fragment and OpenDocument
1410 (org-lparse-and-open
1411 nil nil nil
(call-interactively 'org-export-as-odf
)))
1416 ;;; Driver Starts here
1419 (require 'format-spec
)
1420 (eval-when-compile (require 'cl
) (require 'table
))
1426 ;; FIXME: it already exists in org-e-odt.el
1427 ;;; Function Declarations
1429 (declare-function org-element-property
"org-element" (property element
))
1430 (declare-function org-element-normalize-string
"org-element" (s))
1432 (declare-function org-export-data
"org-export" (data info
))
1433 (declare-function org-export-directory
"org-export" (type plist
))
1434 (declare-function org-export-expand-macro
"org-export" (macro info
))
1435 (declare-function org-export-first-sibling-p
"org-export" (headline info
))
1436 (declare-function org-export-footnote-first-reference-p
"org-export"
1437 (footnote-reference info
))
1438 (declare-function org-export-get-coderef-format
"org-export" (path desc
))
1439 (declare-function org-export-get-footnote-definition
"org-export"
1440 (footnote-reference info
))
1441 (declare-function org-export-get-footnote-number
"org-export" (footnote info
))
1442 (declare-function org-export-get-previous-element
"org-export" (blob info
))
1443 (declare-function org-export-get-relative-level
"org-export" (headline info
))
1444 (declare-function org-export-handle-code
1445 "org-export" (element info
&optional num-fmt ref-fmt delayed
))
1446 (declare-function org-export-included-file
"org-export" (keyword backend info
))
1447 (declare-function org-export-inline-image-p
"org-export"
1448 (link &optional extensions
))
1449 (declare-function org-export-last-sibling-p
"org-export" (headline info
))
1450 (declare-function org-export-low-level-p
"org-export" (headline info
))
1451 (declare-function org-export-output-file-name
1452 "org-export" (extension &optional subtreep pub-dir
))
1453 (declare-function org-export-resolve-coderef
"org-export" (ref info
))
1454 (declare-function org-export-resolve-fuzzy-link
"org-export" (link info
))
1455 (declare-function org-export-resolve-radio-link
"org-export" (link info
))
1456 (declare-function org-export-solidify-link-text
"org-export" (s))
1458 org-export-to-buffer
"org-export"
1459 (backend buffer
&optional subtreep visible-only body-only ext-plist
))
1461 org-export-to-file
"org-export"
1462 (backend file
&optional subtreep visible-only body-only ext-plist
))
1464 (declare-function org-id-find-id-file
"org-id" (id))
1465 (declare-function htmlize-region
"ext:htmlize" (beg end
))
1466 (declare-function org-pop-to-buffer-same-window
1467 "org-compat" (&optional buffer-or-name norecord label
))
1473 (declare-function hfy-face-to-style
"htmlfontify" (fn))
1474 (declare-function hfy-face-or-def-to-name
"htmlfontify" (fn))
1475 (declare-function archive-zip-extract
"arc-mode.el" (archive name
))
1477 ;;; Internal Variables
1479 ;;;; ODT Internal Variables
1481 (defconst org-e-odt-lib-dir
1482 (file-name-directory load-file-name
)
1483 "Location of ODT exporter.
1484 Use this to infer values of `org-e-odt-styles-dir' and
1485 `org-e-odt-schema-dir'.")
1487 (defvar org-e-odt-data-dir
1488 (expand-file-name "../../etc/" org-e-odt-lib-dir
)
1489 "Data directory for ODT exporter.
1490 Use this to infer values of `org-e-odt-styles-dir' and
1491 `org-e-odt-schema-dir'.")
1493 (defconst org-e-odt-special-string-regexps
1494 '(("\\\\-" .
"­\\1") ; shy
1495 ("---\\([^-]\\)" .
"—\\1") ; mdash
1496 ("--\\([^-]\\)" .
"–\\1") ; ndash
1497 ("\\.\\.\\." .
"…")) ; hellip
1498 "Regular expressions for special string conversion.")
1500 (defconst org-e-odt-schema-dir-list
1502 (and org-e-odt-data-dir
1503 (expand-file-name "./schema/" org-e-odt-data-dir
)) ; bail out
1505 (and (boundp 'org-e-odt-data-dir
) org-e-odt-data-dir
; see make install
1506 (expand-file-name "./schema/" org-e-odt-data-dir
))))
1507 "List of directories to search for OpenDocument schema files.
1508 Use this list to set the default value of
1509 `org-e-odt-schema-dir'. The entries in this list are
1510 populated heuristically based on the values of `org-e-odt-lib-dir'
1511 and `org-e-odt-data-dir'.")
1513 (defconst org-e-odt-styles-dir-list
1515 (and org-e-odt-data-dir
1516 (expand-file-name "./styles/" org-e-odt-data-dir
)) ; bail out
1518 (and (boundp 'org-e-odt-data-dir
) org-e-odt-data-dir
; see make install
1519 (expand-file-name "./styles/" org-e-odt-data-dir
)))
1520 (expand-file-name "../../etc/styles/" org-e-odt-lib-dir
) ; git
1521 (expand-file-name "./etc/styles/" org-e-odt-lib-dir
) ; elpa
1522 (expand-file-name "./org/" data-directory
) ; system
1524 "List of directories to search for OpenDocument styles files.
1525 See `org-e-odt-styles-dir'. The entries in this list are populated
1526 heuristically based on the values of `org-e-odt-lib-dir' and
1527 `org-e-odt-data-dir'.")
1529 (defconst org-e-odt-styles-dir
1532 (message "Debug (org-e-odt): Searching for OpenDocument styles files...")
1533 (mapc (lambda (styles-dir)
1535 (message "Debug (org-e-odt): Trying %s..." styles-dir
)
1536 (when (and (file-readable-p
1538 "OrgOdtContentTemplate.xml" styles-dir
))
1541 "OrgOdtStyles.xml" styles-dir
)))
1542 (message "Debug (org-e-odt): Using styles under %s"
1544 (throw 'styles-dir styles-dir
))))
1545 org-e-odt-styles-dir-list
)
1548 (error "Error (org-e-odt): Cannot find factory styles files. Aborting."))
1550 "Directory that holds auxiliary XML files used by the ODT exporter.
1552 This directory contains the following XML files -
1553 \"OrgOdtStyles.xml\" and \"OrgOdtContentTemplate.xml\". These
1554 XML files are used as the default values of
1555 `org-e-odt-styles-file' and
1556 `org-e-odt-content-template-file'.
1558 The default value of this variable varies depending on the
1559 version of org in use and is initialized from
1560 `org-e-odt-styles-dir-list'. Note that the user could be using org
1561 from one of: org's own private git repository, GNU ELPA tar or
1564 (defconst org-e-odt-tmpdir-prefix
"%s-")
1565 (defconst org-e-odt-bookmark-prefix
"OrgXref.")
1567 (defconst org-e-odt-manifest-file-entry-tag
1569 <manifest:file-entry manifest:media-type=\"%s\" manifest:full-path=\"%s\"%s/>")
1573 (defvar org-lparse-dyn-first-heading-pos
) ; let bound during org-do-lparse
1575 (defvar org-e-odt-suppress-xref nil
)
1576 (defvar org-e-odt-file-extensions
1577 '(("odt" .
"OpenDocument Text")
1578 ("ott" .
"OpenDocument Text Template")
1579 ("odm" .
"OpenDocument Master Document")
1580 ("ods" .
"OpenDocument Spreadsheet")
1581 ("ots" .
"OpenDocument Spreadsheet Template")
1582 ("odg" .
"OpenDocument Drawing (Graphics)")
1583 ("otg" .
"OpenDocument Drawing Template")
1584 ("odp" .
"OpenDocument Presentation")
1585 ("otp" .
"OpenDocument Presentation Template")
1586 ("odi" .
"OpenDocument Image")
1587 ("odf" .
"OpenDocument Formula")
1588 ("odc" .
"OpenDocument Chart")))
1590 (defconst org-e-odt-default-org-styles-alist
1591 '((paragraph .
((default .
"Text_20_body")
1592 (fixedwidth .
"OrgFixedWidthBlock")
1593 (verse .
"OrgVerse")
1594 (quote .
"Quotations")
1595 (blockquote .
"Quotations")
1596 (center .
"OrgCenter")
1598 (right .
"OrgRight")
1599 (title .
"OrgTitle")
1600 (subtitle .
"OrgSubtitle")
1601 (footnote .
"Footnote")
1602 (src .
"OrgSrcBlock")
1603 (illustration .
"Illustration")
1605 (listing .
"Listing")
1606 (definition-term .
"Text_20_body_20_bold")
1607 (horizontal-line .
"Horizontal_20_Line")))
1608 (character .
((bold .
"Bold")
1609 (italic .
"Emphasis")
1611 (verbatim .
"OrgCode")
1612 (strike .
"Strikethrough")
1613 (underline .
"Underline")
1614 (subscript .
"OrgSubscript")
1615 (superscript .
"OrgSuperscript")))
1616 (list .
((ordered .
"OrgNumberedList")
1617 (unordered .
"OrgBulletedList")
1618 (descriptive .
"OrgDescriptionList"))))
1619 "Default styles for various entities.")
1621 (defvar org-e-odt-org-styles-alist org-e-odt-default-org-styles-alist
)
1624 ;;;_. control callbacks
1625 ;;;_ , document body
1627 (defvar org-lparse-body-only
) ; let bound during org-do-lparse
1628 (defvar org-lparse-opt-plist
) ; bound during org-do-lparse
1629 (defvar org-lparse-list-stack
) ; dynamically bound in org-do-lparse
1630 (defvar org-e-odt-list-stack-stashed
)
1631 (defvar org-lparse-table-ncols
)
1632 (defvar org-e-odt-table-rowgrp-open
)
1633 (defvar org-e-odt-table-rownum
)
1634 (defvar org-e-odt-table-cur-rowgrp-is-hdr
)
1635 (defvar org-lparse-table-is-styled
)
1636 (defvar org-lparse-table-rowgrp-info
)
1637 (defvar org-lparse-table-colalign-vector
)
1639 (defvar org-e-odt-table-style nil
1640 "Table style specified by \"#+ATTR_ODT: <style-name>\" line.
1641 This is set during `org-e-odt-begin-table'.")
1643 (defvar org-e-odt-table-style-spec nil
1644 "Entry for `org-e-odt-table-style' in `org-e-odt-table-styles'.")
1647 (defvar org-e-odt-table-style-format
1649 <style:style style:name=\"%s\" style:family=\"table\">
1650 <style:table-properties style:rel-width=\"%d%%\" fo:margin-top=\"0cm\" fo:margin-bottom=\"0.20cm\" table:align=\"center\"/>
1653 "Template for auto-generated Table styles.")
1655 (defvar org-e-odt-automatic-styles
'()
1656 "Registry of automatic styles for various OBJECT-TYPEs.
1657 The variable has the following form:
1659 \(\(OBJECT-NAME-A.1 OBJECT-PROPS-A.1\)
1660 \(OBJECT-NAME-A.2 OBJECT-PROPS-A.2\) ...\)\)
1662 \(\(OBJECT-NAME-B.1 OBJECT-PROPS-B.1\)
1663 \(OBJECT-NAME-B.2 OBJECT-PROPS-B.2\) ...\)\)
1666 OBJECT-TYPEs could be \"Section\", \"Table\", \"Figure\" etc.
1667 OBJECT-PROPS is (typically) a plist created by passing
1668 \"#+ATTR_ODT: \" option to `org-e-odt-parse-block-attributes'.
1670 Use `org-e-odt-add-automatic-style' to add update this variable.'")
1672 (defvar org-e-odt-object-counters nil
1673 "Running counters for various OBJECT-TYPEs.
1674 Use this to generate automatic names and style-names. See
1675 `org-e-odt-add-automatic-style'.")
1677 (defvar org-e-odt-table-indentedp nil
)
1678 (defvar org-lparse-table-colalign-info
)
1679 (defvar org-lparse-link-description-is-image nil
)
1682 (defvar org-src-block-paragraph-format
1683 "<style:style style:name=\"OrgSrcBlock\" style:family=\"paragraph\" style:parent-style-name=\"Preformatted_20_Text\">
1684 <style:paragraph-properties fo:background-color=\"%s\" fo:padding=\"0.049cm\" fo:border=\"0.51pt solid #000000\" style:shadow=\"none\">
1685 <style:background-image/>
1686 </style:paragraph-properties>
1687 <style:text-properties fo:color=\"%s\"/>
1689 "Custom paragraph style for colorized source and example blocks.
1690 This style is much the same as that of \"OrgFixedWidthBlock\"
1691 except that the foreground and background colors are set
1692 according to the default face identified by the `htmlfontify'.")
1694 (defvar hfy-optimisations
)
1695 (defvar org-e-odt-embedded-formulas-count
0)
1696 (defvar org-e-odt-entity-frame-styles
1697 '(("As-CharImage" "__Figure__" ("OrgInlineImage" nil
"as-char"))
1698 ("ParagraphImage" "__Figure__" ("OrgDisplayImage" nil
"paragraph"))
1699 ("PageImage" "__Figure__" ("OrgPageImage" nil
"page"))
1700 ("CaptionedAs-CharImage" "__Figure__"
1701 ("OrgCaptionedImage"
1702 " style:rel-width=\"100%\" style:rel-height=\"scale\"" "paragraph")
1703 ("OrgInlineImage" nil
"as-char"))
1704 ("CaptionedParagraphImage" "__Figure__"
1705 ("OrgCaptionedImage"
1706 " style:rel-width=\"100%\" style:rel-height=\"scale\"" "paragraph")
1707 ("OrgImageCaptionFrame" nil
"paragraph"))
1708 ("CaptionedPageImage" "__Figure__"
1709 ("OrgCaptionedImage"
1710 " style:rel-width=\"100%\" style:rel-height=\"scale\"" "paragraph")
1711 ("OrgPageImageCaptionFrame" nil
"page"))
1712 ("InlineFormula" "__MathFormula__" ("OrgInlineFormula" nil
"as-char"))
1713 ("DisplayFormula" "__MathFormula__" ("OrgDisplayFormula" nil
"as-char"))
1714 ("CaptionedDisplayFormula" "__MathFormula__"
1715 ("OrgCaptionedFormula" nil
"paragraph")
1716 ("OrgFormulaCaptionFrame" nil
"as-char"))))
1718 (defvar org-e-odt-embedded-images-count
0)
1720 (defvar org-e-odt-image-size-probe-method
1721 (append (and (executable-find "identify") '(imagemagick)) ; See Bug#10675
1723 "Ordered list of methods for determining image sizes.")
1725 (defvar org-e-odt-default-image-sizes-alist
1726 '(("as-char" .
(5 .
0.4))
1727 ("paragraph" .
(5 .
5)))
1728 "Hardcoded image dimensions one for each of the anchor
1731 ;; A4 page size is 21.0 by 29.7 cms
1732 ;; The default page settings has 2cm margin on each of the sides. So
1733 ;; the effective text area is 17.0 by 25.7 cm
1734 (defvar org-e-odt-max-image-size
'(17.0 .
20.0)
1735 "Limiting dimensions for an embedded image.")
1737 (defvar org-e-odt-entity-labels-alist nil
1738 "Associate Labels with the Labeled entities.
1739 Each element of the alist is of the form (LABEL-NAME
1740 CATEGORY-NAME SEQNO LABEL-STYLE-NAME). LABEL-NAME is same as
1741 that specified by \"#+LABEL: ...\" line. CATEGORY-NAME is the
1742 type of the entity that LABEL-NAME is attached to. CATEGORY-NAME
1743 can be one of \"Table\", \"Figure\" or \"Equation\". SEQNO is
1744 the unique number assigned to the referenced entity on a
1745 per-CATEGORY basis. It is generated sequentially and is 1-based.
1746 LABEL-STYLE-NAME is a key `org-e-odt-label-styles'.
1748 See `org-e-odt-add-label-definition' and
1749 `org-e-odt-fixup-label-references'.")
1751 (defvar org-e-odt-entity-counts-plist nil
1752 "Plist of running counters of SEQNOs for each of the CATEGORY-NAMEs.
1753 See `org-e-odt-entity-labels-alist' for known CATEGORY-NAMEs.")
1755 (defvar org-e-odt-label-styles
1756 '(("math-formula" "%c" "text" "(%n)")
1757 ("math-label" "(%n)" "text" "(%n)")
1758 ("category-and-value" "%e %n: %c" "category-and-value" "%e %n")
1759 ("value" "%e %n: %c" "value" "%n"))
1760 "Specify how labels are applied and referenced.
1761 This is an alist where each element is of the
1762 form (LABEL-STYLE-NAME LABEL-ATTACH-FMT LABEL-REF-MODE
1765 LABEL-ATTACH-FMT controls how labels and captions are attached to
1766 an entity. It may contain following specifiers - %e, %n and %c.
1767 %e is replaced with the CATEGORY-NAME. %n is replaced with
1768 \"<text:sequence ...> SEQNO </text:sequence>\". %c is replaced
1769 with CAPTION. See `org-e-odt-format-label-definition'.
1771 LABEL-REF-MODE and LABEL-REF-FMT controls how label references
1772 are generated. The following XML is generated for a label
1773 reference - \"<text:sequence-ref
1774 text:reference-format=\"LABEL-REF-MODE\" ...> LABEL-REF-FMT
1775 </text:sequence-ref>\". LABEL-REF-FMT may contain following
1776 specifiers - %e and %n. %e is replaced with the CATEGORY-NAME.
1777 %n is replaced with SEQNO. See
1778 `org-e-odt-format-label-reference'.")
1780 (defcustom org-e-odt-category-strings
1781 '(("en" "Table" "Figure" "Equation" "Equation" "Listing"))
1782 "Specify category strings for various captionable entities.
1783 Captionable entity can be one of a Table, an Embedded Image, a
1784 LaTeX fragment (generated with dvipng) or a Math Formula.
1786 For example, when `org-export-default-language' is \"en\", an
1787 embedded image will be captioned as \"Figure 1: Orgmode Logo\".
1788 If you want the images to be captioned instead as \"Illustration
1789 1: Orgmode Logo\", then modify the entry for \"en\" as shown
1792 \(setq org-e-odt-category-strings
1793 '\(\(\"en\" \"Table\" \"Illustration\"
1794 \"Equation\" \"Equation\"\)\)\)"
1795 :group
'org-export-e-odt
1797 :type
'(repeat (list (string :tag
"Language tag")
1798 (choice :tag
"Table"
1799 (const :tag
"Use Default" nil
)
1800 (string :tag
"Category string"))
1801 (choice :tag
"Figure"
1802 (const :tag
"Use Default" nil
)
1803 (string :tag
"Category string"))
1804 (choice :tag
"Math Formula"
1805 (const :tag
"Use Default" nil
)
1806 (string :tag
"Category string"))
1807 (choice :tag
"Dvipng Image"
1808 (const :tag
"Use Default" nil
)
1809 (string :tag
"Category string"))
1810 (choice :tag
"Listing"
1811 (const :tag
"Use Default" nil
)
1812 (string :tag
"Category string")))))
1814 (defvar org-e-odt-category-map-alist
1815 '(("__Table__" "Table" "value")
1816 ("__Figure__" "Illustration" "value")
1817 ("__MathFormula__" "Text" "math-formula")
1818 ("__DvipngImage__" "Equation" "value")
1819 ("__Listing__" "Listing" "value")
1820 ;; ("__Table__" "Table" "category-and-value")
1821 ;; ("__Figure__" "Figure" "category-and-value")
1822 ;; ("__DvipngImage__" "Equation" "category-and-value")
1824 "Map a CATEGORY-HANDLE to OD-VARIABLE and LABEL-STYLE.
1825 This is a list where each entry is of the form \\(CATEGORY-HANDLE
1826 OD-VARIABLE LABEL-STYLE\\). CATEGORY_HANDLE identifies the
1827 captionable entity in question. OD-VARIABLE is the OpenDocument
1828 sequence counter associated with the entity. These counters are
1830 \"<text:sequence-decls>...</text:sequence-decls>\" block of
1831 `org-e-odt-content-template-file'. LABEL-STYLE is a key
1832 into `org-e-odt-label-styles' and specifies how a given entity
1833 should be captioned and referenced.
1835 The position of a CATEGORY-HANDLE in this list is used as an
1836 index in to per-language entry for
1837 `org-e-odt-category-strings' to retrieve a CATEGORY-NAME.
1838 This CATEGORY-NAME is then used for qualifying the user-specified
1839 captions on export.")
1841 (defvar org-e-odt-manifest-file-entries nil
)
1842 (defvar hfy-user-sheet-assoc
) ; bound during org-do-lparse
1843 (defvar org-lparse-latex-fragment-fallback
) ; set by org-do-lparse
1846 ;;;; HTML Internal Variables
1848 (defvar html-table-tag nil
) ; dynamically scoped into this.
1850 ;; FIXME: it already exists in org-e-odt.el
1851 (defconst org-e-odt-cvt-link-fn
1853 "Function to convert link URLs to exportable URLs.
1854 Takes two arguments, TYPE and PATH.
1855 Returns exportable url as (TYPE PATH), or nil to signal that it
1856 didn't handle this case.
1857 Intended to be locally bound around a call to `org-export-as-html'." )
1862 (defvar org-e-odt-format-table-no-css
)
1863 (defvar htmlize-buffer-places
) ; from htmlize.el
1864 (defvar body-only
) ; dynamically scoped into this.
1866 (defvar org-e-odt-table-rowgrp-open
)
1867 (defvar org-e-odt-table-rownum
)
1868 (defvar org-e-odt-table-cur-rowgrp-is-hdr
)
1869 (defvar org-lparse-table-is-styled
)
1872 (defvar org-e-odt-headline-formatter
1873 (lambda (level snumber todo todo-type priority
1874 title tags target extra-targets extra-class
)
1875 (concat snumber
" " title
)))
1879 ;;; User Configuration Variables
1881 (defgroup org-export-e-odt nil
1882 "Options for exporting Org mode files to ODT."
1883 :tag
"Org Export ODT"
1886 (defcustom org-e-odt-protect-char-alist
1890 "Alist of characters to be converted by `org-e-html-protect'."
1891 :group
'org-export-e-html
1892 :type
'(repeat (cons (string :tag
"Character")
1893 (string :tag
"ODT equivalent"))))
1894 (defcustom org-e-odt-schema-dir
1897 (message "Debug (org-e-odt): Searching for OpenDocument schema files...")
1899 (lambda (schema-dir)
1901 (message "Debug (org-e-odt): Trying %s..." schema-dir
)
1902 (when (and (file-readable-p
1903 (expand-file-name "od-manifest-schema-v1.2-cs01.rnc"
1906 (expand-file-name "od-schema-v1.2-cs01.rnc"
1909 (expand-file-name "schemas.xml" schema-dir
)))
1910 (message "Debug (org-e-odt): Using schema files under %s"
1912 (throw 'schema-dir schema-dir
))))
1913 org-e-odt-schema-dir-list
)
1914 (message "Debug (org-e-odt): No OpenDocument schema files installed")
1917 "Directory that contains OpenDocument schema files.
1919 This directory contains:
1920 1. rnc files for OpenDocument schema
1921 2. a \"schemas.xml\" file that specifies locating rules needed
1922 for auto validation of OpenDocument XML files.
1924 Use the customize interface to set this variable. This ensures
1925 that `rng-schema-locating-files' is updated and auto-validation
1926 of OpenDocument XML takes place based on the value
1927 `rng-nxml-auto-validate-flag'.
1929 The default value of this variable varies depending on the
1930 version of org in use and is initialized from
1931 `org-e-odt-schema-dir-list'. The OASIS schema files are available
1932 only in the org's private git repository. It is *not* bundled
1933 with GNU ELPA tar or standard Emacs distribution."
1935 (const :tag
"Not set" nil
)
1936 (directory :tag
"Schema directory"))
1937 :group
'org-export-e-odt
1941 "Set `org-e-odt-schema-dir'.
1942 Also add it to `rng-schema-locating-files'."
1943 (let ((schema-dir value
))
1947 (expand-file-name "od-manifest-schema-v1.2-cs01.rnc" schema-dir
))
1949 (expand-file-name "od-schema-v1.2-cs01.rnc" schema-dir
))
1951 (expand-file-name "schemas.xml" schema-dir
)))
1954 (message "Error (org-e-odt): %s has no OpenDocument schema files"
1957 (when org-e-odt-schema-dir
1958 (eval-after-load 'rng-loc
1959 '(add-to-list 'rng-schema-locating-files
1960 (expand-file-name "schemas.xml"
1961 org-e-odt-schema-dir
))))))
1963 (defcustom org-e-odt-content-template-file nil
1964 "Template file for \"content.xml\".
1965 The exporter embeds the exported content just before
1966 \"</office:text>\" element.
1968 If unspecified, the file named \"OrgOdtContentTemplate.xml\"
1969 under `org-e-odt-styles-dir' is used."
1971 :group
'org-export-e-odt
1974 (defcustom org-e-odt-styles-file nil
1975 "Default styles file for use with ODT export.
1976 Valid values are one of:
1978 2. path to a styles.xml file
1979 3. path to a *.odt or a *.ott file
1980 4. list of the form (ODT-OR-OTT-FILE (FILE-MEMBER-1 FILE-MEMBER-2
1983 In case of option 1, an in-built styles.xml is used. See
1984 `org-e-odt-styles-dir' for more information.
1986 In case of option 3, the specified file is unzipped and the
1987 styles.xml embedded therein is used.
1989 In case of option 4, the specified ODT-OR-OTT-FILE is unzipped
1990 and FILE-MEMBER-1, FILE-MEMBER-2 etc are copied in to the
1991 generated odt file. Use relative path for specifying the
1992 FILE-MEMBERS. styles.xml must be specified as one of the
1995 Use options 1, 2 or 3 only if styles.xml alone suffices for
1996 achieving the desired formatting. Use option 4, if the styles.xml
1997 references additional files like header and footer images for
1998 achieving the desired formatting.
2000 Use \"#+ODT_STYLES_FILE: ...\" directive to set this variable on
2001 a per-file basis. For example,
2003 #+ODT_STYLES_FILE: \"/path/to/styles.xml\" or
2004 #+ODT_STYLES_FILE: (\"/path/to/file.ott\" (\"styles.xml\" \"image/hdr.png\"))."
2005 :group
'org-export-e-odt
2009 (const :tag
"Factory settings" nil
)
2010 (file :must-match t
:tag
"styles.xml")
2011 (file :must-match t
:tag
"ODT or OTT file")
2012 (list :tag
"ODT or OTT file + Members"
2013 (file :must-match t
:tag
"ODF Text or Text Template file")
2014 (cons :tag
"Members"
2015 (file :tag
" Member" "styles.xml")
2016 (repeat (file :tag
"Member"))))))
2019 (defcustom org-e-odt-inline-image-extensions
2020 '("png" "jpeg" "jpg" "gif")
2021 "Extensions of image files that can be inlined into HTML."
2022 :type
'(repeat (string :tag
"Extension"))
2023 :group
'org-export-e-odt
2026 (defcustom org-e-odt-pixels-per-inch display-pixels-per-inch
2027 "Scaling factor for converting images pixels to inches.
2028 Use this for sizing of embedded images. See Info node `(org)
2029 Images in ODT export' for more information."
2031 :group
'org-export-e-odt
2034 (defcustom org-e-odt-create-custom-styles-for-srcblocks t
2035 "Whether custom styles for colorized source blocks be automatically created.
2036 When this option is turned on, the exporter creates custom styles
2037 for source blocks based on the advice of `htmlfontify'. Creation
2038 of custom styles happen as part of `org-e-odt-hfy-face-to-css'.
2040 When this option is turned off exporter does not create such
2043 Use the latter option if you do not want the custom styles to be
2044 based on your current display settings. It is necessary that the
2045 styles.xml already contains needed styles for colorizing to work.
2047 This variable is effective only if
2048 `org-e-odt-fontify-srcblocks' is turned on."
2049 :group
'org-export-e-odt
2053 (defcustom org-e-odt-preferred-output-format nil
2054 "Automatically post-process to this format after exporting to \"odt\".
2055 Interactive commands `org-export-as-e-odt' and
2056 `org-export-as-e-odt-and-open' export first to \"odt\" format and
2057 then use `org-e-odt-convert-process' to convert the
2058 resulting document to this format. During customization of this
2059 variable, the list of valid values are populated based on
2060 `org-e-odt-convert-capabilities'."
2061 :group
'org-export-e-odt
2063 :type
'(choice :convert-widget
2065 (apply 'widget-convert
(widget-type w
)
2066 (eval (car (widget-get w
:args
)))))
2067 `((const :tag
"None" nil
)
2068 ,@(mapcar (lambda (c)
2069 `(const :tag
,c
,c
))
2070 (org-e-odt-reachable-formats "odt")))))
2072 (defcustom org-e-odt-table-styles
2073 '(("OrgEquation" "OrgEquation"
2074 ((use-first-column-styles . t
)
2075 (use-last-column-styles . t
))))
2076 "Specify how Table Styles should be derived from a Table Template.
2077 This is a list where each element is of the
2078 form (TABLE-STYLE-NAME TABLE-TEMPLATE-NAME TABLE-CELL-OPTIONS).
2080 TABLE-STYLE-NAME is the style associated with the table through
2081 `org-e-odt-table-style'.
2083 TABLE-TEMPLATE-NAME is a set of - upto 9 - automatic
2084 TABLE-CELL-STYLE-NAMEs and PARAGRAPH-STYLE-NAMEs (as defined
2085 below) that is included in
2086 `org-e-odt-content-template-file'.
2088 TABLE-CELL-STYLE-NAME := TABLE-TEMPLATE-NAME + TABLE-CELL-TYPE +
2090 PARAGRAPH-STYLE-NAME := TABLE-TEMPLATE-NAME + TABLE-CELL-TYPE +
2092 TABLE-CELL-TYPE := \"FirstRow\" | \"LastColumn\" |
2093 \"FirstRow\" | \"LastRow\" |
2094 \"EvenRow\" | \"OddRow\" |
2095 \"EvenColumn\" | \"OddColumn\" | \"\"
2096 where \"+\" above denotes string concatenation.
2098 TABLE-CELL-OPTIONS is an alist where each element is of the
2099 form (TABLE-CELL-STYLE-SELECTOR . ON-OR-OFF).
2100 TABLE-CELL-STYLE-SELECTOR := `use-first-row-styles' |
2101 `use-last-row-styles' |
2102 `use-first-column-styles' |
2103 `use-last-column-styles' |
2104 `use-banding-rows-styles' |
2105 `use-banding-columns-styles' |
2106 `use-first-row-styles'
2107 ON-OR-OFF := `t' | `nil'
2109 For example, with the following configuration
2111 \(setq org-e-odt-table-styles
2112 '\(\(\"TableWithHeaderRowsAndColumns\" \"Custom\"
2113 \(\(use-first-row-styles . t\)
2114 \(use-first-column-styles . t\)\)\)
2115 \(\"TableWithHeaderColumns\" \"Custom\"
2116 \(\(use-first-column-styles . t\)\)\)\)\)
2118 1. A table associated with \"TableWithHeaderRowsAndColumns\"
2119 style will use the following table-cell styles -
2120 \"CustomFirstRowTableCell\", \"CustomFirstColumnTableCell\",
2121 \"CustomTableCell\" and the following paragraph styles
2122 \"CustomFirstRowTableParagraph\",
2123 \"CustomFirstColumnTableParagraph\", \"CustomTableParagraph\"
2126 2. A table associated with \"TableWithHeaderColumns\" style will
2127 use the following table-cell styles -
2128 \"CustomFirstColumnTableCell\", \"CustomTableCell\" and the
2129 following paragraph styles
2130 \"CustomFirstColumnTableParagraph\", \"CustomTableParagraph\"
2133 Note that TABLE-TEMPLATE-NAME corresponds to the
2134 \"<table:table-template>\" elements contained within
2135 \"<office:styles>\". The entries (TABLE-STYLE-NAME
2136 TABLE-TEMPLATE-NAME TABLE-CELL-OPTIONS) correspond to
2137 \"table:template-name\" and \"table:use-first-row-styles\" etc
2138 attributes of \"<table:table>\" element. Refer ODF-1.2
2139 specification for more information. Also consult the
2140 implementation filed under `org-e-odt-get-table-cell-styles'.
2142 The TABLE-STYLE-NAME \"OrgEquation\" is used internally for
2143 formatting of numbered display equations. Do not delete this
2144 style from the list."
2145 :group
'org-export-e-odt
2148 (const :tag
"None" nil
)
2149 (repeat :tag
"Table Styles"
2150 (list :tag
"Table Style Specification"
2151 (string :tag
"Table Style Name")
2152 (string :tag
"Table Template Name")
2153 (alist :options
(use-first-row-styles
2155 use-first-column-styles
2156 use-last-column-styles
2157 use-banding-rows-styles
2158 use-banding-columns-styles
)
2160 :value-type
(const :tag
"True" t
))))))
2161 (defcustom org-e-odt-fontify-srcblocks t
2162 "Specify whether or not source blocks need to be fontified.
2163 Turn this option on if you want to colorize the source code
2164 blocks in the exported file. For colorization to work, you need
2165 to make available an enhanced version of `htmlfontify' library."
2167 :group
'org-export-e-odt
2170 (defcustom org-e-odt-prettify-xml t
; FIXME
2171 "Specify whether or not the xml output should be prettified.
2172 When this option is turned on, `indent-region' is run on all
2173 component xml buffers before they are saved. Turn this off for
2174 regular use. Turn this on if you need to examine the xml
2176 :group
'org-export-e-odt
2180 (defcustom org-e-odt-convert-processes
2182 "soffice --headless --convert-to %f%x --outdir %d %i")
2184 "unoconv -f %f -o %d %i"))
2185 "Specify a list of document converters and their usage.
2186 The converters in this list are offered as choices while
2187 customizing `org-e-odt-convert-process'.
2189 This variable is a list where each element is of the
2190 form (CONVERTER-NAME CONVERTER-CMD). CONVERTER-NAME is the name
2191 of the converter. CONVERTER-CMD is the shell command for the
2192 converter and can contain format specifiers. These format
2193 specifiers are interpreted as below:
2195 %i input file name in full
2196 %I input file name as a URL
2197 %f format of the output file
2198 %o output file name in full
2199 %O output file name as a URL
2200 %d output dir in full
2201 %D output dir as a URL.
2202 %x extra options as set in `org-e-odt-convert-capabilities'."
2203 :group
'org-export-e-odt
2207 (const :tag
"None" nil
)
2208 (alist :tag
"Converters"
2209 :key-type
(string :tag
"Converter Name")
2210 :value-type
(group (string :tag
"Command line")))))
2212 (defcustom org-e-odt-convert-process
"LibreOffice"
2213 "Use this converter to convert from \"odt\" format to other formats.
2214 During customization, the list of converter names are populated
2215 from `org-e-odt-convert-processes'."
2216 :group
'org-export-e-odt
2218 :type
'(choice :convert-widget
2220 (apply 'widget-convert
(widget-type w
)
2221 (eval (car (widget-get w
:args
)))))
2222 `((const :tag
"None" nil
)
2223 ,@(mapcar (lambda (c)
2224 `(const :tag
,(car c
) ,(car c
)))
2225 org-e-odt-convert-processes
))))
2227 (defcustom org-e-odt-convert-capabilities
2229 ("odt" "ott" "doc" "rtf" "docx")
2230 (("pdf" "pdf") ("odt" "odt") ("rtf" "rtf") ("ott" "ott")
2231 ("doc" "doc" ":\"MS Word 97\"") ("docx" "docx") ("html" "html")))
2234 (("pdf" "pdf") ("odt" "odt") ("html" "html")))
2236 ("ods" "ots" "xls" "csv" "xlsx")
2237 (("pdf" "pdf") ("ots" "ots") ("html" "html") ("csv" "csv") ("ods" "ods")
2238 ("xls" "xls") ("xlsx" "xlsx")))
2240 ("odp" "otp" "ppt" "pptx")
2241 (("pdf" "pdf") ("swf" "swf") ("odp" "odp") ("otp" "otp") ("ppt" "ppt")
2242 ("pptx" "pptx") ("odg" "odg"))))
2243 "Specify input and output formats of `org-e-odt-convert-process'.
2244 More correctly, specify the set of input and output formats that
2245 the user is actually interested in.
2247 This variable is an alist where each element is of the
2248 form (DOCUMENT-CLASS INPUT-FMT-LIST OUTPUT-FMT-ALIST).
2249 INPUT-FMT-LIST is a list of INPUT-FMTs. OUTPUT-FMT-ALIST is an
2250 alist where each element is of the form (OUTPUT-FMT
2251 OUTPUT-FILE-EXTENSION EXTRA-OPTIONS).
2253 The variable is interpreted as follows:
2254 `org-e-odt-convert-process' can take any document that is in
2255 INPUT-FMT-LIST and produce any document that is in the
2256 OUTPUT-FMT-LIST. A document converted to OUTPUT-FMT will have
2257 OUTPUT-FILE-EXTENSION as the file name extension. OUTPUT-FMT
2258 serves dual purposes:
2259 - It is used for populating completion candidates during
2260 `org-e-odt-convert' commands.
2261 - It is used as the value of \"%f\" specifier in
2262 `org-e-odt-convert-process'.
2264 EXTRA-OPTIONS is used as the value of \"%x\" specifier in
2265 `org-e-odt-convert-process'.
2267 DOCUMENT-CLASS is used to group a set of file formats in
2268 INPUT-FMT-LIST in to a single class.
2270 Note that this variable inherently captures how LibreOffice based
2271 converters work. LibreOffice maps documents of various formats
2272 to classes like Text, Web, Spreadsheet, Presentation etc and
2273 allow document of a given class (irrespective of it's source
2274 format) to be converted to any of the export formats associated
2277 See default setting of this variable for an typical
2279 :group
'org-export-e-odt
2283 (const :tag
"None" nil
)
2284 (alist :tag
"Capabilities"
2285 :key-type
(string :tag
"Document Class")
2287 (group (repeat :tag
"Input formats" (string :tag
"Input format"))
2288 (alist :tag
"Output formats"
2289 :key-type
(string :tag
"Output format")
2291 (group (string :tag
"Output file extension")
2293 (const :tag
"None" nil
)
2294 (string :tag
"Extra options"))))))))
2301 ;;;; Document Header (Styles)
2303 ;;;; Document Header (Scripts)
2305 ;;;; Document Header (Mathjax)
2318 ;;;; Statistics Cookie
2338 ;;;; Horizontal Rule
2339 ;;;; Inline Babel Call
2340 ;;;; Inline Src Block
2344 ;;;; Latex Environment
2353 ;;;; Property Drawer
2379 ;;; User Configurable Variables (MAYBE)
2387 (defcustom org-e-odt-format-headline-function nil
2388 "Function to format headline text.
2390 This function will be called with 5 arguments:
2391 TODO the todo keyword \(string or nil\).
2392 TODO-TYPE the type of todo \(symbol: `todo', `done', nil\)
2393 PRIORITY the priority of the headline \(integer or nil\)
2394 TEXT the main headline text \(string\).
2395 TAGS the tags string, separated with colons \(string or nil\).
2397 The function result will be used in the section format string.
2399 As an example, one could set the variable to the following, in
2400 order to reproduce the default set-up:
2402 \(defun org-e-odt-format-headline \(todo todo-type priority text tags\)
2403 \"Default format function for an headline.\"
2404 \(concat \(when todo
2405 \(format \"\\\\textbf{\\\\textsc{\\\\textsf{%s}}} \" todo\)\)
2407 \(format \"\\\\framebox{\\\\#%c} \" priority\)\)
2409 \(when tags \(format \"\\\\hfill{}\\\\textsc{%s}\" tags\)\)\)\)"
2410 :group
'org-export-e-odt
2417 (defcustom org-e-odt-active-timestamp-format
"\\textit{%s}"
2418 "A printf format string to be applied to active timestamps."
2419 :group
'org-export-e-odt
2422 (defcustom org-e-odt-inactive-timestamp-format
"\\textit{%s}"
2423 "A printf format string to be applied to inactive timestamps."
2424 :group
'org-export-e-odt
2427 (defcustom org-e-odt-diary-timestamp-format
"\\textit{%s}"
2428 "A printf format string to be applied to diary timestamps."
2429 :group
'org-export-e-odt
2435 (defcustom org-e-odt-inline-image-rules
2436 '(("file" .
"\\.\\(jpeg\\|jpg\\|png\\|gif\\)\\'"))
2437 "Rules characterizing image files that can be inlined into HTML.
2439 A rule consists in an association whose key is the type of link
2440 to consider, and value is a regexp that will be matched against
2443 Note that, by default, the image extension *actually* allowed
2444 depend on the way the HTML file is processed. When used with
2445 pdflatex, pdf, jpg and png images are OK. When processing
2446 through dvi to Postscript, only ps and eps are allowed. The
2447 default we use here encompasses both."
2448 :group
'org-export-e-odt
2449 :type
'(alist :key-type
(string :tag
"Type")
2450 :value-type
(regexp :tag
"Path")))
2454 (defcustom org-e-odt-table-caption-above t
2455 "When non-nil, place caption string at the beginning of the table.
2456 Otherwise, place it near the end."
2457 :group
'org-export-e-odt
2462 (defcustom org-e-odt-format-drawer-function nil
2463 "Function called to format a drawer in HTML code.
2465 The function must accept two parameters:
2466 NAME the drawer name, like \"LOGBOOK\"
2467 CONTENTS the contents of the drawer.
2469 The function should return the string to be exported.
2471 For example, the variable could be set to the following function
2472 in order to mimic default behaviour:
2474 \(defun org-e-odt-format-drawer-default \(name contents\)
2475 \"Format a drawer element for HTML export.\"
2477 :group
'org-export-e-odt
2483 (defcustom org-e-odt-format-inlinetask-function nil
2484 "Function called to format an inlinetask in HTML code.
2486 The function must accept six parameters:
2487 TODO the todo keyword, as a string
2488 TODO-TYPE the todo type, a symbol among `todo', `done' and nil.
2489 PRIORITY the inlinetask priority, as a string
2490 NAME the inlinetask name, as a string.
2491 TAGS the inlinetask tags, as a string.
2492 CONTENTS the contents of the inlinetask, as a string.
2494 The function should return the string to be exported.
2496 For example, the variable could be set to the following function
2497 in order to mimic default behaviour:
2499 \(defun org-e-odt-format-inlinetask \(todo type priority name tags contents\)
2500 \"Format an inline task element for HTML export.\"
2501 \(let \(\(full-title
2504 \(format \"\\\\textbf{\\\\textsf{\\\\textsc{%s}}} \" todo\)\)
2505 \(when priority \(format \"\\\\framebox{\\\\#%c} \" priority\)\)
2507 \(when tags \(format \"\\\\hfill{}\\\\textsc{%s}\" tags\)\)\)\)\)
2508 \(format \(concat \"\\\\begin{center}\\n\"
2510 \"\\\\begin{minipage}[c]{.6\\\\textwidth}\\n\"
2512 \"\\\\rule[.8em]{\\\\textwidth}{2pt}\\n\\n\"
2514 \"\\\\end{minipage}}\"
2515 \"\\\\end{center}\"\)
2516 full-title contents\)\)"
2517 :group
'org-export-e-odt
2525 (defcustom org-e-odt-quotes
2526 '(("fr" ("\\(\\s-\\|[[(]\\)\"" .
"«~") ("\\(\\S-\\)\"" .
"~»") ("\\(\\s-\\|(\\)'" .
"'"))
2527 ("en" ("\\(\\s-\\|[[(]\\)\"" .
"``") ("\\(\\S-\\)\"" .
"''") ("\\(\\s-\\|(\\)'" .
"`")))
2528 "Alist for quotes to use when converting english double-quotes.
2530 The CAR of each item in this alist is the language code.
2531 The CDR of each item in this alist is a list of three CONS:
2532 - the first CONS defines the opening quote;
2533 - the second CONS defines the closing quote;
2534 - the last CONS defines single quotes.
2536 For each item in a CONS, the first string is a regexp
2537 for allowed characters before/after the quote, the second
2538 string defines the replacement string for this quote."
2539 :group
'org-export-e-odt
2541 (cons :tag
"Opening quote"
2542 (string :tag
"Regexp for char before")
2543 (string :tag
"Replacement quote "))
2544 (cons :tag
"Closing quote"
2545 (string :tag
"Regexp for char after ")
2546 (string :tag
"Replacement quote "))
2547 (cons :tag
"Single quote"
2548 (string :tag
"Regexp for char before")
2549 (string :tag
"Replacement quote "))))
2556 ;;; Internal Functions (HTML)
2558 ;; (defun org-e-odt-format-inline-image (path &optional caption label attr)
2559 ;; ;; FIXME: alt text missing here?
2560 ;; (let ((inline-image (format "<img src=\"%s\" alt=\"%s\"/>"
2561 ;; path (file-name-nondirectory path))))
2562 ;; (if (not label) inline-image
2563 ;; (org-e-odt-format-section inline-image "figure" label))))
2567 (defun org-e-odt-bibliography ()
2568 "Find bibliography, cut it out and return it."
2570 (let (beg end
(cnt 1) bib
)
2572 (goto-char (point-min))
2573 (when (re-search-forward
2574 "^[ \t]*<div \\(id\\|class\\)=\"bibliography\"" nil t
)
2575 (setq beg
(match-beginning 0))
2576 (while (re-search-forward "</?div\\>" nil t
)
2577 (setq cnt
(+ cnt
(if (string= (match-string 0) "<div") +1 -
1)))
2579 (and (looking-at ">") (forward-char 1))
2580 (setq bib
(buffer-substring beg
(point)))
2581 (delete-region beg
(point))
2582 (throw 'exit bib
))))
2587 (defun org-e-odt-format-table (lines olines
)
2588 (let ((org-e-odt-format-table-no-css nil
))
2589 (org-lparse-format-table lines olines
)))
2591 (defun org-e-odt-splice-attributes (tag attributes
)
2592 "Read attributes in string ATTRIBUTES, add and replace in HTML tag TAG."
2593 (if (not attributes
)
2595 (let (oldatt newatt
)
2596 (setq oldatt
(org-extract-attributes-from-string tag
)
2598 newatt
(cdr (org-extract-attributes-from-string attributes
)))
2600 (setq oldatt
(plist-put oldatt
(pop newatt
) (pop newatt
))))
2601 (if (string-match ">" tag
)
2603 (replace-match (concat (org-attributes-to-string oldatt
) ">")
2607 (defun org-export-splice-style (style extra
)
2608 "Splice EXTRA into STYLE, just before \"</style>\"."
2609 (if (and (stringp extra
)
2610 (string-match "\\S-" extra
)
2611 (string-match "</style>" style
))
2612 (concat (substring style
0 (match-beginning 0))
2614 (substring style
(match-beginning 0)))
2617 (defun org-e-odt-toc-entry-formatter
2618 (level snumber todo todo-type priority
2619 headline tags target extra-targets extra-class
)
2620 (org-e-odt-format-toc-entry snumber todo headline tags target
))
2622 (defun org-e-odt-make-string (n string
)
2623 (let (out) (dotimes (i n out
) (setq out
(concat string out
)))))
2625 (defun org-e-odt-toc-text (toc-entries)
2626 (let* ((prev-level (1- (nth 1 (car toc-entries
))))
2627 (start-level prev-level
))
2630 (let ((headline (nth 0 entry
))
2631 (level (nth 1 entry
)))
2632 (prog1 (org-e-odt-format-toc-item headline level prev-level
)
2633 (setq prev-level level
))))
2636 (defun* org-e-odt-format-toc-headline
2637 (todo todo-type priority text tags
2638 &key level section-number headline-label
&allow-other-keys
)
2641 (and org-export-with-section-numbers
2642 (concat section-number
". "))
2646 (org-e-odt-format-spaces 3)
2647 (org-e-odt-format-fontify tags
"tag")))))
2649 (setq text
(org-e-odt-format-fontify text
"todo")))
2651 (let ((org-e-odt-suppress-xref t
))
2652 (org-e-odt-format-link text
(concat "#" headline-label
))))
2654 (defun org-e-odt-toc (depth info
)
2655 (assert (wholenump depth
))
2656 (let* ((headlines (org-export-collect-headlines info depth
))
2658 (loop for headline in headlines collect
2659 (list (org-e-odt-format-headline--wrap
2660 headline info
'org-e-odt-format-toc-headline
)
2661 (org-export-get-relative-level headline info
)))))
2663 (let* ((lang-specific-heading "Table of Contents")) ; FIXME
2665 (org-e-odt-begin-toc lang-specific-heading depth
)
2666 (org-e-odt-toc-text toc-entries
)
2667 (org-e-odt-end-toc))))))
2669 (defun org-e-odt-begin-outline (level1 snumber title tags
2670 target extra-targets extra-class
)
2671 (let* ((class (format "outline-%d" level1
))
2672 (class (if extra-class
(concat class
" " extra-class
) class
))
2673 (id (format "outline-container-%s"
2674 (org-lparse-suffix-from-snumber snumber
)))
2675 (extra (concat (when id
(format " id=\"%s\"" id
))
2676 (when class
(format " class=\"%s\"" class
)))))
2677 (org-lparse-insert-tag "<div%s>" extra
)
2679 (org-lparse-format 'HEADING
2681 'HEADLINE title extra-targets tags snumber level1
)
2684 (defun org-e-odt-end-outline ()
2685 (org-lparse-insert-tag "</div>"))
2687 (defun org-e-odt-suffix-from-snumber (snumber)
2688 (let* ((snu (replace-regexp-in-string "\\." "-" snumber
))
2689 (href (cdr (assoc (concat "sec-" snu
)
2690 org-export-preferred-target-alist
))))
2691 (org-solidify-link-text (or href snu
))))
2693 (defun org-e-odt-format-outline (contents level1 snumber title
2694 tags target extra-targets extra-class
)
2697 ;; (defun org-e-odt-format-line (line)
2698 ;; (case org-lparse-dyn-current-environment
2699 ;; ((quote fixedwidth) (concat (org-e-odt-encode-plain-text line) "\n"))
2700 ;; (t (concat line "\n"))))
2702 (defun org-e-odt-fix-class-name (kwd) ; audit callers of this function
2703 "Turn todo keyword into a valid class name.
2704 Replaces invalid characters with \"_\"."
2706 (while (string-match "[^a-zA-Z0-9_]" kwd
)
2707 (setq kwd
(replace-match "_" t t kwd
))))
2710 (defun org-e-odt-format-internal-link (text href
&optional extra
)
2711 (org-e-odt-format-link text
(concat "#" href
) extra
))
2713 (defun org-e-odt-format-extra-targets (extra-targets)
2714 (if (not extra-targets
) ""
2715 (mapconcat (lambda (x)
2717 (setq x
(org-solidify-link-text
2718 (if (org-uuidgen-p x
) (concat "ID-" x
) x
)))
2719 (org-e-odt-format-anchor "" x
))) extra-targets
"")))
2721 (defun org-e-odt-format-org-tags (tags)
2723 (org-e-odt-format-fontify
2726 (org-e-odt-format-fontify
2727 x
(concat "" ;; org-e-odt-tag-class-prefix
2728 (org-e-odt-fix-class-name x
))))
2730 (org-e-odt-format-spaces 1)) "tag")))
2732 (defun org-e-odt-format-section-number (&optional snumber level
)
2734 (and nil org-export-with-section-numbers
2735 ;; (not org-lparse-body-only)
2737 (org-e-odt-format-fontify snumber
(format "section-number-%d" level
))))
2739 ;; (defun org-e-odt-format-headline (title extra-targets tags
2740 ;; &optional snumber level)
2742 ;; (org-e-odt-format-extra-targets extra-targets)
2743 ;; (concat (org-e-odt-format-section-number snumber level) " ")
2745 ;; (and tags (concat (org-e-odt-format-spaces 3)
2746 ;; (org-e-odt-format-org-tags tags)))))
2748 ;; (defun org-e-odt-format-date (info)
2749 ;; (let ((date (plist-get info :date)))
2751 ;; ((and date (string-match "%" date))
2752 ;; (format-time-string date))
2754 ;; (t (format-time-string "%Y-%m-%d %T %Z")))))
2758 ;;; Internal Functions (Ngz)
2760 (defun org-e-odt--caption/label-string
(caption label info
)
2761 "Return caption and label HTML string for floats.
2763 CAPTION is a cons cell of secondary strings, the car being the
2764 standard caption and the cdr its short form. LABEL is a string
2765 representing the label. INFO is a plist holding contextual
2768 If there's no caption nor label, return the empty string.
2770 For non-floats, see `org-e-odt--wrap-label'."
2771 (setq label nil
) ;; FIXME
2773 (let ((label-str (if label
(format "\\label{%s}" label
) "")))
2775 ((and (not caption
) (not label
)) "")
2776 ((not caption
) (format "\\label{%s}\n" label
))
2777 ;; Option caption format with short name.
2779 (format "\\caption[%s]{%s%s}\n"
2780 (org-export-data (cdr caption
) info
)
2782 (org-export-data (car caption
) info
)))
2783 ;; Standard caption format.
2784 ;; (t (format "\\caption{%s%s}\n"
2786 ;; (org-export-data (car caption) info)))
2787 (t (org-export-data (car caption
) info
)))))
2789 (defun org-e-odt--find-verb-separator (s)
2790 "Return a character not used in string S.
2791 This is used to choose a separator for constructs like \\verb."
2792 (let ((ll "~,./?;':\"|!@#%^&-_=+abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ<>()[]{}"))
2793 (loop for c across ll
2794 when
(not (string-match (regexp-quote (char-to-string c
)) s
))
2795 return
(char-to-string c
))))
2797 (defun org-e-odt--quotation-marks (text info
)
2798 "Export quotation marks depending on language conventions.
2799 TEXT is a string containing quotation marks to be replaced. INFO
2800 is a plist used as a communication channel."
2803 (while (setq start
(string-match (car l
) text start
))
2804 (let ((new-quote (concat (match-string 1 text
) (cdr l
))))
2805 (setq text
(replace-match new-quote t t text
))))))
2806 (cdr (or (assoc (plist-get info
:language
) org-e-odt-quotes
)
2807 ;; Falls back on English.
2808 (assoc "en" org-e-odt-quotes
))))
2811 (defun org-e-odt--wrap-label (element output
)
2812 "Wrap label associated to ELEMENT around OUTPUT, if appropriate.
2813 This function shouldn't be used for floats. See
2814 `org-e-odt--caption/label-string'."
2815 ;; (let ((label (org-element-property :name element)))
2816 ;; (if (or (not output) (not label) (string= output "") (string= label ""))
2818 ;; (concat (format "\\label{%s}\n" label) output)))
2823 ;;; Transcode Helpers
2825 (defun* org-e-odt-format-headline
2826 (todo todo-type priority text tags
2827 &key level section-number headline-label
&allow-other-keys
)
2828 (concat (org-e-odt-todo todo
) (and todo
" ") text
2829 (and tags
(org-e-odt-format-spaces 3))
2830 (and tags
(org-e-odt-format-org-tags tags
))))
2834 (defun org-e-odt-htmlfontify-string (line)
2835 (let* ((hfy-html-quote-regex "\\([<\"&> ]\\)")
2836 (hfy-html-quote-map '(("\"" """)
2841 (" " "<text:tab/>")))
2842 (hfy-face-to-css 'org-e-odt-hfy-face-to-css
)
2843 (hfy-optimisations-1 (copy-seq hfy-optimisations
))
2844 (hfy-optimisations (add-to-list 'hfy-optimisations-1
2846 (hfy-begin-span-handler
2847 (lambda (style text-block text-id text-begins-block-p
)
2848 (insert (format "<text:span text:style-name=\"%s\">" style
))))
2849 (hfy-end-span-handler (lambda nil
(insert "</text:span>"))))
2850 (htmlfontify-string line
)))
2852 (defun org-e-odt-do-format-code
2853 (code &optional lang refs retain-labels num-start
)
2854 (let* ((lang (or (assoc-default lang org-src-lang-modes
) lang
))
2855 (lang-mode (and lang
(intern (format "%s-mode" lang
))))
2856 (code-lines (org-split-string code
"\n"))
2857 (code-length (length code-lines
))
2858 (use-htmlfontify-p (and (functionp lang-mode
)
2859 org-e-odt-fontify-srcblocks
2860 (require 'htmlfontify nil t
)
2861 (fboundp 'htmlfontify-string
)))
2862 (code (if (not use-htmlfontify-p
) code
2866 (font-lock-fontify-buffer)
2868 (fontifier (if use-htmlfontify-p
'org-e-odt-htmlfontify-string
2869 'org-e-odt-encode-plain-text
))
2870 (par-style (if use-htmlfontify-p
"OrgSrcBlock"
2871 "OrgFixedWidthBlock"))
2873 (assert (= code-length
(length (org-split-string code
"\n"))))
2875 (org-export-format-code
2877 (lambda (loc line-num ref
)
2879 (concat par-style
(and (= (incf i
) code-length
) "LastLine")))
2881 (setq loc
(concat loc
(and ref retain-labels
(format " (%s)" ref
))))
2882 (setq loc
(funcall fontifier loc
))
2884 (setq loc
(org-e-odt-format-target loc
(concat "coderef-" ref
))))
2885 (setq loc
(org-e-odt-format-stylized-paragraph par-style loc
))
2886 (if (not line-num
) loc
2887 (org-e-odt-format-tags
2888 '("<text:list-item>" .
"</text:list-item>") loc
)))
2891 ((not num-start
) code
)
2892 ((equal num-start
0)
2893 (org-e-odt-format-tags
2894 '("<text:list text:style-name=\"OrgSrcBlockNumberedLine\"%s>"
2895 .
"</text:list>") code
" text:continue-numbering=\"false\""))
2896 (t (org-e-odt-format-tags
2897 '("<text:list text:style-name=\"OrgSrcBlockNumberedLine\"%s>"
2898 .
"</text:list>") code
" text:continue-numbering=\"true\"")))))
2900 (defun org-e-odt-format-code (element info
)
2901 (let* ((lang (org-element-property :language element
))
2902 ;; Extract code and references.
2903 (code-info (org-export-unravel-code element
))
2904 (code (car code-info
))
2905 (refs (cdr code-info
))
2906 ;; Does the src block contain labels?
2907 (retain-labels (org-element-property :retain-labels element
))
2908 ;; Does it have line numbers?
2909 (num-start (case (org-element-property :number-lines element
)
2910 (continued (org-export-get-loc element info
))
2912 (org-e-odt-do-format-code code lang refs retain-labels num-start
)))
2918 (defun org-e-odt-template (contents info
)
2919 "Return complete document string after HTML conversion.
2920 CONTENTS is the transcoded contents string. RAW-DATA is the
2921 original parsed data. INFO is a plist holding export options."
2923 (org-e-odt-update-meta-file info
)
2925 (insert-file-contents
2926 (or org-e-odt-content-template-file
2927 (expand-file-name "OrgOdtContentTemplate.xml"
2928 org-e-odt-styles-dir
)))
2929 (goto-char (point-min))
2930 (re-search-forward "</office:text>" nil nil
)
2931 (goto-char (match-beginning 0))
2934 (insert (org-e-odt-format-preamble info
))
2935 ;; Table of Contents
2936 (let ((depth (plist-get info
:with-toc
)))
2937 (when (wholenump depth
) (insert (org-e-odt-toc depth info
))))
2939 ;; Copy styles.xml. Also dump htmlfontify styles, if there is any.
2940 (org-e-odt-update-styles-file info
)
2942 ;; Update styles.xml - take care of outline numbering
2943 (with-current-buffer
2944 (find-file-noselect (expand-file-name "styles.xml") t
)
2945 ;; Don't make automatic backup of styles.xml file. This setting
2946 ;; prevents the backed-up styles.xml file from being zipped in to
2947 ;; odt file. This is more of a hackish fix. Better alternative
2948 ;; would be to fix the zip command so that the output odt file
2949 ;; includes only the needed files and excludes any auto-generated
2950 ;; extra files like backups and auto-saves etc etc. Note that
2951 ;; currently the zip command zips up the entire temp directory so
2952 ;; that any auto-generated files created under the hood ends up in
2953 ;; the resulting odt file.
2954 (set (make-local-variable 'backup-inhibited
) t
)
2955 (org-e-odt-configure-outline-numbering))
2959 (buffer-substring-no-properties (point-min) (point-max))))
2963 ;;; Transcode Functions
2967 (defun org-e-odt-bold (bold contents info
)
2968 "Transcode BOLD from Org to HTML.
2969 CONTENTS is the text with bold markup. INFO is a plist holding
2970 contextual information."
2971 (org-e-odt-format-fontify contents
'bold
))
2976 (defun org-e-odt-center-block (center-block contents info
)
2977 "Transcode a CENTER-BLOCK element from Org to HTML.
2978 CONTENTS holds the contents of the center block. INFO is a plist
2979 holding contextual information."
2980 (org-e-odt--wrap-label center-block contents
))
2985 (defun org-e-odt-clock (clock contents info
)
2986 "Transcode a CLOCK element from Org to HTML.
2987 CONTENTS is nil. INFO is a plist used as a communication
2989 (org-e-odt-format-fontify
2990 (concat (org-e-odt-format-fontify org-clock-string
"timestamp-kwd")
2991 (org-e-odt-format-fontify
2992 (concat (org-translate-time (org-element-property :value clock
))
2993 (let ((time (org-element-property :time clock
)))
2994 (and time
(format " (%s)" time
))))
2996 "timestamp-wrapper"))
3001 (defun org-e-odt-code (code contents info
)
3002 "Transcode a CODE object from Org to HTML.
3003 CONTENTS is nil. INFO is a plist used as a communication
3005 (org-e-odt-format-fontify (org-element-property :value code
) 'code
))
3010 ;; Comments are ignored.
3015 ;; Comment Blocks are ignored.
3020 (defun org-e-odt-drawer (drawer contents info
)
3021 "Transcode a DRAWER element from Org to HTML.
3022 CONTENTS holds the contents of the block. INFO is a plist
3023 holding contextual information."
3024 (let* ((name (org-element-property :drawer-name drawer
))
3025 (output (if (functionp org-e-odt-format-drawer-function
)
3026 (funcall org-e-odt-format-drawer-function
3028 ;; If there's no user defined function: simply
3029 ;; display contents of the drawer.
3031 (org-e-odt--wrap-label drawer output
)))
3036 (defun org-e-odt-dynamic-block (dynamic-block contents info
)
3037 "Transcode a DYNAMIC-BLOCK element from Org to HTML.
3038 CONTENTS holds the contents of the block. INFO is a plist
3039 holding contextual information. See `org-export-data'."
3040 (org-e-odt--wrap-label dynamic-block contents
))
3045 (defun org-e-odt-entity (entity contents info
)
3046 "Transcode an ENTITY object from Org to HTML.
3047 CONTENTS are the definition itself. INFO is a plist holding
3048 contextual information."
3049 ;; (let ((ent (org-element-property :latex entity)))
3050 ;; (if (org-element-property :latex-math-p entity)
3051 ;; (format "$%s$" ent)
3053 (org-element-property :utf-8 entity
))
3058 (defun org-e-odt-example-block (example-block contents info
)
3059 "Transcode a EXAMPLE-BLOCK element from Org to HTML.
3060 CONTENTS is nil. INFO is a plist holding contextual information."
3061 (let* ((options (or (org-element-property :options example-block
) ""))
3062 (value (org-export-handle-code example-block info nil nil t
)))
3063 (org-e-odt--wrap-label
3064 example-block
(org-e-odt-format-source-code-or-example value nil
))))
3069 (defun org-e-odt-export-snippet (export-snippet contents info
)
3070 "Transcode a EXPORT-SNIPPET object from Org to HTML.
3071 CONTENTS is nil. INFO is a plist holding contextual information."
3072 (when (eq (org-export-snippet-backend export-snippet
) 'e-odt
)
3073 (org-element-property :value export-snippet
)))
3078 (defun org-e-odt-export-block (export-block contents info
)
3079 "Transcode a EXPORT-BLOCK element from Org to HTML.
3080 CONTENTS is nil. INFO is a plist holding contextual information."
3081 (when (string= (org-element-property :type export-block
) "ODT")
3082 (org-remove-indentation (org-element-property :value export-block
))))
3087 (defun org-e-odt-fixed-width (fixed-width contents info
)
3088 "Transcode a FIXED-WIDTH element from Org to HTML.
3089 CONTENTS is nil. INFO is a plist holding contextual information."
3090 (org-e-odt--wrap-label
3092 (org-e-odt-format-source-code-or-example
3093 (org-element-property :value fixed-width
) nil
)))
3096 ;;;; Footnote Definition
3098 ;; Footnote Definitions are ignored.
3101 ;;;; Footnote Reference
3103 (defun org-e-odt-footnote-def (raw info
) ; FIXME
3104 (if (equal (org-element-type raw
) 'org-data
)
3105 (org-trim (org-export-data raw info
)) ; fix paragraph style
3106 (org-e-odt-format-stylized-paragraph
3107 'footnote
(org-trim (org-export-data raw info
)))))
3109 (defvar org-e-odt-footnote-separator
3110 (org-e-odt-format-fontify "," 'superscript
))
3112 (defun org-e-odt-footnote-reference (footnote-reference contents info
)
3113 "Transcode a FOOTNOTE-REFERENCE element from Org to HTML.
3114 CONTENTS is nil. INFO is a plist holding contextual information."
3116 ;; Insert separator between two footnotes in a row.
3117 (let ((prev (org-export-get-previous-element footnote-reference info
)))
3118 (when (eq (org-element-type prev
) 'footnote-reference
)
3119 org-e-odt-footnote-separator
))
3121 ((not (org-export-footnote-first-reference-p footnote-reference info
))
3122 (let* ((n (org-export-get-footnote-number footnote-reference info
)))
3123 (org-e-odt-format-footnote-reference n
"IGNORED" 100)))
3124 ;; Inline definitions are secondary strings.
3125 ((eq (org-element-property :type footnote-reference
) 'inline
)
3126 (let* ((raw (org-export-get-footnote-definition footnote-reference info
))
3127 (n (org-export-get-footnote-number footnote-reference info
))
3128 (def (org-e-odt-footnote-def raw info
)))
3129 (org-e-odt-format-footnote-reference n def
1)))
3130 ;; Non-inline footnotes definitions are full Org data.
3132 (let* ((raw (org-export-get-footnote-definition footnote-reference info
))
3133 (n (org-export-get-footnote-number footnote-reference info
))
3134 (def (org-e-odt-footnote-def raw info
)))
3135 (org-e-odt-format-footnote-reference n def
1))))))
3140 (defun org-e-odt-todo (todo)
3142 (org-e-odt-format-fontify
3144 "" ; org-e-odt-todo-kwd-class-prefix
3145 (org-e-odt-fix-class-name todo
))
3146 (list (if (member todo org-done-keywords
) "done" "todo")
3149 (defun org-e-odt-format-headline--wrap (headline info
3150 &optional format-function
3152 "Transcode an HEADLINE element from Org to ODT.
3153 CONTENTS holds the contents of the headline. INFO is a plist
3154 holding contextual information."
3155 (let* ((level (+ (org-export-get-relative-level headline info
)))
3156 (headline-number (org-export-get-headline-number headline info
))
3157 (section-number (and (org-export-numbered-headline-p headline info
)
3158 (mapconcat 'number-to-string
3159 headline-number
".")))
3160 (todo (and (plist-get info
:with-todo-keywords
)
3161 (let ((todo (org-element-property :todo-keyword headline
)))
3162 (and todo
(org-export-data todo info
)))))
3163 (todo-type (and todo
(org-element-property :todo-type headline
)))
3164 (priority (and (plist-get info
:with-priority
)
3165 (org-element-property :priority headline
)))
3166 (text (org-export-data (org-element-property :title headline
) info
))
3167 (tags (and (plist-get info
:with-tags
)
3168 (org-element-property :tags headline
)))
3169 (headline-label (concat "sec-" (mapconcat 'number-to-string
3170 headline-number
"-")))
3171 (format-function (cond
3172 ((functionp format-function
) format-function
)
3173 ((functionp org-e-odt-format-headline-function
)
3175 (lambda (todo todo-type priority text tags
3177 (funcall org-e-odt-format-headline-function
3178 todo todo-type priority text tags
))))
3179 (t 'org-e-odt-format-headline
))))
3180 (apply format-function
3181 todo todo-type priority text tags
3182 :headline-label headline-label
:level level
3183 :section-number section-number extra-keys
)))
3185 (defun org-e-odt-headline (headline contents info
)
3186 "Transcode an HEADLINE element from Org to HTML.
3187 CONTENTS holds the contents of the headline. INFO is a plist
3188 holding contextual information."
3189 (let* ((numberedp (org-export-numbered-headline-p headline info
))
3190 ;; Get level relative to current parsed data.
3191 (level (org-export-get-relative-level headline info
))
3192 (text (org-export-data (org-element-property :title headline
) info
))
3193 ;; Create the headline text.
3194 (full-text (org-e-odt-format-headline--wrap headline info
)))
3196 ;; Case 1: This is a footnote section: ignore it.
3197 ((org-element-property :footnote-section-p headline
) nil
)
3198 ;; Case 2. This is a deep sub-tree: export it as a list item.
3199 ;; Also export as items headlines for which no section
3200 ;; format has been found.
3201 ((org-export-low-level-p headline info
) ; FIXME (or (not section-fmt))
3202 ;; Build the real contents of the sub-tree.
3203 (let* ((type (if numberedp
'unordered
'unordered
)) ; FIXME
3204 (itemized-body (org-e-odt-format-list-item
3205 contents type nil nil full-text
)))
3207 (and (org-export-first-sibling-p headline info
)
3208 (org-e-odt-begin-plain-list type
))
3210 (and (org-export-last-sibling-p headline info
)
3211 (org-e-odt-end-plain-list type
)))))
3212 ;; Case 3. Standard headline. Export it as a section.
3214 (let* ((extra-ids (list (org-element-property :custom-id headline
)
3215 (org-element-property :id headline
)))
3216 (extra-ids nil
) ; FIXME
3217 (id (concat "sec-" (mapconcat 'number-to-string
3218 (org-export-get-headline-number
3219 headline info
) "-"))))
3221 (org-e-odt-format-tags
3222 '("<text:h text:style-name=\"Heading_20_%s\" text:outline-level=\"%s\">" .
3224 (concat (org-e-odt-format-extra-targets extra-ids
)
3225 (if (not id
) full-text
(org-e-odt-format-target full-text id
) ))
3230 ;;;; Horizontal Rule
3232 (defun org-e-odt-horizontal-rule (horizontal-rule contents info
)
3233 "Transcode an HORIZONTAL-RULE object from Org to HTML.
3234 CONTENTS is nil. INFO is a plist holding contextual information."
3235 (let ((attr (mapconcat #'identity
3236 (org-element-property :attr_odt horizontal-rule
)
3238 (org-e-odt--wrap-label horizontal-rule
3239 (org-e-odt-format-horizontal-line))))
3242 ;;;; Inline Babel Call
3244 ;; Inline Babel Calls are ignored.
3247 ;;;; Inline Src Block
3249 (defun org-e-odt-inline-src-block (inline-src-block contents info
)
3250 "Transcode an INLINE-SRC-BLOCK element from Org to HTML.
3251 CONTENTS holds the contents of the item. INFO is a plist holding
3252 contextual information."
3253 (let* ((org-lang (org-element-property :language inline-src-block
))
3254 (code (org-element-property :value inline-src-block
))
3255 (separator (org-e-odt--find-verb-separator code
)))
3261 (defun org-e-odt-format-section (text class
&optional id
)
3262 (let ((extra (concat (when id
(format " id=\"%s\"" id
)))))
3263 (concat (format "<div class=\"%s\"%s>\n" class extra
) text
"</div>\n")))
3265 (defun org-e-odt-inlinetask (inlinetask contents info
)
3266 "Transcode an INLINETASK element from Org to ODT.
3267 CONTENTS holds the contents of the block. INFO is a plist
3268 holding contextual information."
3270 ;; If `org-e-odt-format-inlinetask-function' is provided, call it
3271 ;; with appropriate arguments.
3272 ((functionp org-e-odt-format-inlinetask-function
)
3273 (let ((format-function
3275 (lambda (todo todo-type priority text tags
3276 &key contents
&allow-other-keys
)
3277 (funcall org-e-odt-format-inlinetask-function
3278 todo todo-type priority text tags contents
)))))
3279 (org-e-odt-format-headline--wrap
3280 inlinetask info format-function
:contents contents
)))
3281 ;; Otherwise, use a default template.
3282 (t (org-e-odt--wrap-label
3284 (org-e-odt-format-stylized-paragraph
3285 nil
(org-e-odt-format-textbox
3286 (concat (org-e-odt-format-stylized-paragraph
3287 "OrgInlineTaskHeading" (org-e-odt-format-headline--wrap
3290 nil nil
"OrgInlineTaskFrame" " style:rel-width=\"100%\""))))))
3294 (defun org-e-odt-italic (italic contents info
)
3295 "Transcode ITALIC from Org to HTML.
3296 CONTENTS is the text with italic markup. INFO is a plist holding
3297 contextual information."
3298 (org-e-odt-format-fontify contents
'italic
))
3303 (defun org-e-odt-format-list-item (contents type checkbox
3304 &optional term-counter-id
3308 (org-e-odt-format-fontify (case checkbox
3311 (trans "[-]")) 'code
)))
3313 (org-e-odt-begin-list-item type term-counter-id headline
)
3314 ;; FIXME checkbox (and checkbox " ")
3316 (org-e-odt-end-list-item type
)))
3318 (defun org-e-odt-item (item contents info
)
3319 "Transcode an ITEM element from Org to HTML.
3320 CONTENTS holds the contents of the item. INFO is a plist holding
3321 contextual information."
3322 (let* ((plain-list (org-export-get-parent item info
))
3323 (type (org-element-property :type plain-list
))
3324 (counter (org-element-property :counter item
))
3325 (checkbox (org-element-property :checkbox item
))
3326 (tag (let ((tag (org-element-property :tag item
)))
3327 (and tag
(org-export-data tag info
)))))
3328 (org-e-odt-format-list-item
3329 contents type checkbox
(or tag counter
))))
3334 (defun org-e-odt-keyword (keyword contents info
)
3335 "Transcode a KEYWORD element from Org to HTML.
3336 CONTENTS is nil. INFO is a plist holding contextual information."
3337 (let ((key (org-element-property :key keyword
))
3338 (value (org-element-property :value keyword
)))
3340 ((string= key
"LATEX") value
)
3341 ((string= key
"INDEX") (format "\\index{%s}" value
))
3342 ((string= key
"TARGET") nil
; FIXME
3343 ;; (format "\\label{%s}" (org-export-solidify-link-text value))
3345 ((string= key
"toc")
3346 (let ((value (downcase value
)))
3348 ((string-match "\\<headlines\\>" value
)
3349 (let ((depth (or (and (string-match "[0-9]+" value
)
3350 (string-to-number (match-string 0 value
)))
3351 (plist-get info
:with-toc
))))
3352 (when (wholenump depth
) (org-e-odt-toc depth info
))))
3353 ((string= "tables" value
) "FIXME")
3354 ((string= "figures" value
) "FIXME")
3355 ((string= "listings" value
)
3357 ;; At the moment, src blocks with a caption are wrapped
3358 ;; into a figure environment.
3362 ;;;; Latex Environment
3364 (defun org-e-odt-format-latex (latex-frag processing-type
)
3365 (let* ((prefix (case processing-type
3367 (mathml "ltxmathml/")))
3369 (concat prefix
(file-name-sans-extension
3370 (file-name-nondirectory (buffer-file-name)))))
3371 (cache-dir (file-name-directory (buffer-file-name )))
3372 (display-msg (case processing-type
3373 (dvipng "Creating LaTeX Image...")
3374 (mathml "Creating MathML snippet..."))))
3377 (org-format-latex cache-relpath cache-dir nil display-msg
3378 nil nil processing-type
)
3381 (defun org-e-odt-latex-environment (latex-environment contents info
)
3382 "Transcode a LATEX-ENVIRONMENT element from Org to HTML.
3383 CONTENTS is nil. INFO is a plist holding contextual information."
3384 (org-e-odt--wrap-label
3387 (org-remove-indentation
3388 (org-element-property :value latex-environment
)))
3389 (processing-type (plist-get info
:LaTeX-fragments
))
3390 (caption (org-element-property :caption latex-environment
))
3391 (short-caption (and (cdr caption
)
3392 (org-export-data (cdr caption
) info
)))
3393 (caption (and (car caption
) (org-export-data (car caption
) info
)))
3394 (label (org-element-property :name latex-environment
))
3396 (label (org-element-property :name latex-environment
)))
3398 ((member processing-type
'(t mathjax
))
3399 (org-e-odt-format-formula latex-environment info
))
3400 ((equal processing-type
'dvipng
)
3401 (org-e-odt-format-stylized-paragraph
3402 nil
(org-e-odt-link--inline-image latex-environment info
)))
3409 ;; (when latex-frag ; FIXME
3410 ;; (setq href (org-propertize href :title "LaTeX Fragment"
3411 ;; :description latex-frag)))
3413 ;; provide descriptions
3415 (defun org-e-odt-latex-fragment (latex-fragment contents info
)
3416 "Transcode a LATEX-FRAGMENT object from Org to HTML.
3417 CONTENTS is nil. INFO is a plist holding contextual information."
3418 (let* ((latex-frag (org-element-property :value latex-fragment
))
3419 (processing-type (plist-get info
:LaTeX-fragments
)))
3421 ((member processing-type
'(t mathjax
))
3422 (org-e-odt-format-formula latex-fragment info
))
3423 ((equal processing-type
'dvipng
)
3424 (org-e-odt-link--inline-image latex-fragment info
))
3430 (defun org-e-odt-line-break (line-break contents info
)
3431 "Transcode a LINE-BREAK object from Org to HTML.
3432 CONTENTS is nil. INFO is a plist holding contextual information."
3433 "<text:line-break/>\n")
3438 (defun org-e-odt-link--inline-image (element info
)
3439 "Return HTML code for an inline image.
3440 LINK is the link pointing to the inline image. INFO is a plist
3441 used as a communication channel."
3443 ((eq (org-element-type element
) 'link
)
3444 (let* ((type (org-element-property :type element
))
3445 (raw-path (org-element-property :path element
)))
3446 (cond ((member type
'("http" "https"))
3447 (concat type
":" raw-path
))
3448 ((file-name-absolute-p raw-path
)
3449 (expand-file-name raw-path
))
3451 ((member (org-element-type element
)
3452 '(latex-fragment latex-environment
))
3453 (let* ((latex-frag (org-remove-indentation
3454 (org-element-property
3456 (formula-link (org-e-odt-format-latex
3457 latex-frag
'dvipng
)))
3459 (string-match "file:\\([^]]*\\)" formula-link
)
3460 (match-string 1 formula-link
))))
3461 (t (error "what is this?"))))
3462 (href (org-e-odt-format-tags
3463 "<draw:image xlink:href=\"%s\" xlink:type=\"simple\" xlink:show=\"embed\" xlink:actuate=\"onLoad\"/>" ""
3464 (org-e-odt-copy-image-file src
)))
3465 ;; extract attributes from #+ATTR_ODT line.
3466 (attr-from (case (org-element-type element
)
3467 (link (org-export-get-parent-paragraph element info
))
3469 ;; convert attributes to a plist.
3470 (attr-plist (org-e-odt-element-attributes attr-from info
))
3471 ;; handle `:anchor', `:style' and `:attributes' properties.
3473 (car (assoc-string (plist-get attr-plist
:anchor
)
3474 '(("as-char") ("paragraph") ("page")) t
)))
3476 (and user-frame-anchor
(plist-get attr-plist
:style
)))
3478 (and user-frame-anchor
(plist-get attr-plist
:attributes
)))
3480 (list user-frame-style user-frame-attrs user-frame-anchor
))
3481 ;; (embed-as (or embed-as user-frame-anchor "paragraph"))
3483 ;; handle `:width', `:height' and `:scale' properties.
3484 (size (org-e-odt-image-size-from-file
3485 src
(plist-get attr-plist
:width
)
3486 (plist-get attr-plist
:height
)
3487 (plist-get attr-plist
:scale
) nil
;; embed-as
3490 (width (car size
)) (height (cdr size
))
3492 (case (org-element-type element
)
3493 ((org-e-odt-standalone-image-p element info
) "paragraph")
3494 (latex-fragment "as-char")
3495 (latex-environment "paragraph")
3497 (captions (org-e-odt-format-label element info
'definition
))
3498 (caption (car captions
)) (short-caption (cdr captions
))
3499 (entity (concat (and caption
"Captioned") embed-as
"Image")))
3500 (org-e-odt-format-entity entity href width height
3501 captions user-frame-params
)))
3503 (defun org-e-odt-format-entity (entity href width height
&optional
3504 captions user-frame-params
)
3505 (let* ((caption (car captions
)) (short-caption (cdr captions
))
3506 (entity-style (assoc-string entity org-e-odt-entity-frame-styles t
))
3507 default-frame-params frame-params
)
3510 (setq default-frame-params
(nth 2 entity-style
))
3511 (setq frame-params
(org-e-odt-merge-frame-params
3512 default-frame-params user-frame-params
))
3513 (apply 'org-e-odt-format-frame href width height frame-params
))
3515 (setq default-frame-params
(nth 3 entity-style
))
3516 (setq frame-params
(org-e-odt-merge-frame-params
3517 default-frame-params user-frame-params
))
3518 (apply 'org-e-odt-format-textbox
3519 (org-e-odt-format-stylized-paragraph
3522 (apply 'org-e-odt-format-frame href width height
3523 (let ((entity-style-1 (copy-sequence
3524 (nth 2 entity-style
))))
3525 (setcar (cdr entity-style-1
)
3527 (cadr entity-style-1
)
3529 (format " draw:name=\"%s\" "
3533 width height frame-params
)))))
3535 (defvar org-e-odt-standalone-image-predicate
3536 (function (lambda (paragraph)
3537 (or (org-element-property :caption paragraph
)
3538 (org-element-property :name paragraph
)))))
3540 (defun org-e-odt-standalone-image-p (element info
&optional predicate
)
3541 "Test if ELEMENT is a standalone image for the purpose ODT export.
3542 INFO is a plist holding contextual information.
3544 Return non-nil, if ELEMENT is of type paragraph and it's sole
3545 content, save for whitespaces, is a link that qualifies as an
3548 Return non-nil, if ELEMENT is of type link and it's containing
3549 paragraph has no other content save for leading and trailing
3552 Return nil, otherwise.
3554 Bind `org-e-odt-standalone-image-predicate' to constrain
3555 paragraph further. For example, to check for only captioned
3556 standalone images, do the following.
3558 \(setq org-e-odt-standalone-image-predicate
3559 \(lambda \(paragraph\)
3560 \(org-element-property :caption paragraph\)\)\)
3562 (let ((paragraph (case (org-element-type element
)
3564 (link (and (org-export-inline-image-p
3565 element org-e-odt-inline-image-rules
)
3566 (org-export-get-parent element info
)))
3569 (assert (eq (org-element-type paragraph
) 'paragraph
))
3570 (when (or (not (and (boundp 'org-e-odt-standalone-image-predicate
)
3571 (functionp org-e-odt-standalone-image-predicate
)))
3572 (funcall org-e-odt-standalone-image-predicate paragraph
))
3573 (let ((contents (org-element-contents paragraph
)))
3574 (loop for x in contents
3575 with inline-image-count
= 0
3577 ((eq (org-element-type x
) 'plain-text
)
3578 (not (org-string-nw-p x
)))
3579 ((eq (org-element-type x
) 'link
)
3580 (when (org-export-inline-image-p
3581 x org-e-odt-inline-image-rules
)
3582 (= (incf inline-image-count
) 1)))
3585 (defun org-e-odt-link (link desc info
)
3586 "Transcode a LINK object from Org to HTML.
3588 DESC is the description part of the link, or the empty string.
3589 INFO is a plist holding contextual information. See
3591 (let* ((type (org-element-property :type link
))
3592 (raw-path (org-element-property :path link
))
3593 ;; Ensure DESC really exists, or set it to nil.
3594 (desc (and (not (string= desc
"")) desc
))
3595 (imagep (org-export-inline-image-p
3596 link org-e-odt-inline-image-rules
))
3598 ((member type
'("http" "https" "ftp" "mailto"))
3599 (concat type
":" raw-path
))
3600 ((string= type
"file")
3601 (when (string-match "\\(.+\\)::.+" raw-path
)
3602 (setq raw-path
(match-string 1 raw-path
)))
3603 (if (file-name-absolute-p raw-path
)
3604 (concat "file://" (expand-file-name raw-path
))
3605 (concat "file://" raw-path
)))
3610 ((and (not desc
) (org-export-inline-image-p
3611 link org-e-odt-inline-image-rules
))
3612 (org-e-odt-link--inline-image link info
))
3613 ;; Radio target: Transcode target's contents and use them as
3614 ;; link's description.
3615 ((string= type
"radio")
3616 (let ((destination (org-export-resolve-radio-link link info
)))
3618 (org-e-odt-format-internal-link
3619 (org-export-data (org-element-contents destination
) info
)
3620 (org-export-solidify-link-text path
)))))
3621 ;; Links pointing to an headline: Find destination and build
3622 ;; appropriate referencing command.
3623 ((member type
'("custom-id" "fuzzy" "id"))
3624 (let ((destination (if (string= type
"fuzzy")
3625 (org-export-resolve-fuzzy-link link info
)
3626 (org-export-resolve-id-link link info
))))
3627 (case (org-element-type destination
)
3628 ;; Fuzzy link points nowhere.
3630 (org-e-odt-format-fontify
3631 (or desc
(org-export-data
3632 (org-element-property :raw-link link
) info
))
3634 ;; Fuzzy link points to an invisible target.
3636 ;; LINK points to an headline. If headlines are numbered
3637 ;; and the link has no description, display headline's
3638 ;; number. Otherwise, display description or headline's
3641 (let* ((headline-no (org-export-get-headline-number destination info
))
3642 (label (format "sec-%s" (mapconcat 'number-to-string
3644 (section-no (mapconcat 'number-to-string headline-no
".")))
3648 ((plist-get info
:section-numbers
) section-no
)
3650 (org-element-property :title destination
) info
))))
3651 (org-e-odt-format-internal-link desc label
)))
3652 ;; Fuzzy link points to a target. Do as above.
3655 ;; (setq number (cond
3656 ;; ((org-e-odt-standalone-image-p destination info)
3657 ;; (org-export-get-ordinal
3658 ;; (assoc 'link (org-element-contents destination))
3659 ;; info 'link 'org-e-odt-standalone-image-p))
3660 ;; (t (org-export-get-ordinal destination info))))
3661 ;; (setq desc (when number
3662 ;; (if (atom number) (number-to-string number)
3663 ;; (mapconcat 'number-to-string number ".")))))
3665 (let ((label-reference
3666 (org-e-odt-format-label destination info
'reference
)))
3667 (assert label-reference
)
3668 label-reference
)))))
3669 ;; Coderef: replace link with the reference name or the
3670 ;; equivalent line number.
3671 ((string= type
"coderef")
3672 (let* ((fmt (org-export-get-coderef-format path desc
))
3673 (res (org-export-resolve-coderef path info
))
3674 (org-e-odt-suppress-xref nil
)
3675 (href (org-xml-format-href (concat "#coderef-" path
))))
3676 (format fmt
(org-e-odt-format-link res href
))))
3677 ;; Link type is handled by a special function.
3678 ((functionp (setq protocol
(nth 2 (assoc type org-link-protocols
))))
3679 (funcall protocol
(org-link-unescape path
) desc
'html
))
3680 ;; External link with a description part.
3681 ((and path desc
) (org-e-odt-format-link desc path
))
3682 ;; External link without a description part.
3683 (path (org-e-odt-format-link path path
))
3684 ;; No path, only description. Try to do something useful.
3685 (t (org-e-odt-format-fontify desc
'italic
)))))
3690 ;; Babel Calls are ignored.
3695 (defun org-e-odt-macro (macro contents info
)
3696 "Transcode a MACRO element from Org to HTML.
3697 CONTENTS is nil. INFO is a plist holding contextual information."
3698 ;; Use available tools.
3699 (org-export-expand-macro macro info
))
3704 (defun org-e-odt-paragraph (paragraph contents info
)
3705 "Transcode a PARAGRAPH element from Org to HTML.
3706 CONTENTS is the contents of the paragraph, as a string. INFO is
3707 the plist used as a communication channel."
3708 (let* ((style nil
) ; FIXME
3709 (class (cdr (assoc style
'((footnote .
"footnote")
3711 (extra (if class
(format " class=\"%s\"" class
) ""))
3712 (parent (org-export-get-parent paragraph info
))
3713 (parent-type (org-element-type parent
))
3714 (style (case parent-type
3715 (quote-block 'quote
)
3716 (center-block 'center
)
3717 (footnote-definition 'footnote
)
3719 (org-e-odt-format-stylized-paragraph style contents
)))
3724 (defun org-e-odt-plain-list (plain-list contents info
)
3725 "Transcode a PLAIN-LIST element from Org to HTML.
3726 CONTENTS is the contents of the list. INFO is a plist holding
3727 contextual information."
3728 (let* (arg1 ;; FIXME
3729 (type (org-element-property :type plain-list
))
3730 (attr (mapconcat #'identity
3731 (org-element-property :attr_odt plain-list
)
3733 (org-e-odt--wrap-label
3734 plain-list
(format "%s\n%s%s"
3735 (org-e-odt-begin-plain-list type
)
3736 contents
(org-e-odt-end-plain-list type
)))))
3740 (defun org-e-odt-convert-special-strings (string)
3741 "Convert special characters in STRING to ODT."
3742 (let ((all org-e-odt-special-string-regexps
)
3744 (while (setq a
(pop all
))
3745 (setq re
(car a
) rpl
(cdr a
) start
0)
3746 (while (string-match re string start
)
3747 (setq string
(replace-match rpl t nil string
))))
3750 ;; (defun org-e-odt-encode-plain-text (s)
3751 ;; "Convert plain text characters to HTML equivalent.
3752 ;; Possible conversions are set in `org-export-html-protect-char-alist'."
3753 ;; (let ((cl org-e-odt-protect-char-alist) c)
3754 ;; (while (setq c (pop cl))
3756 ;; (while (string-match (car c) s start)
3757 ;; (setq s (replace-match (cdr c) t t s)
3758 ;; start (1+ (match-beginning 0))))))
3761 (defun org-e-odt-plain-text (text info
)
3762 "Transcode a TEXT string from Org to HTML.
3763 TEXT is the string to transcode. INFO is a plist holding
3764 contextual information."
3765 (setq text
(org-e-odt-encode-plain-text text t
))
3766 ;; Protect %, #, &, $, ~, ^, _, { and }.
3767 ;; (while (string-match "\\([^\\]\\|^\\)\\([%$#&{}~^_]\\)" text)
3769 ;; (replace-match (format "\\%s" (match-string 2 text)) nil t text 2)))
3771 ;; (setq text (replace-regexp-in-string
3772 ;; "\\(?:[^\\]\\|^\\)\\(\\\\\\)\\(?:[^%$#&{}~^_\\]\\|$\\)"
3773 ;; "$\\backslash$" text nil t 1))
3774 ;; HTML into \HTML{} and TeX into \TeX{}.
3775 ;; (let ((case-fold-search nil)
3777 ;; (while (string-match "\\<\\(\\(?:La\\)?TeX\\)\\>" text start)
3778 ;; (setq text (replace-match
3779 ;; (format "\\%s{}" (match-string 1 text)) nil t text)
3780 ;; start (match-end 0))))
3781 ;; Handle quotation marks
3782 ;; (setq text (org-e-odt--quotation-marks text info))
3783 ;; Convert special strings.
3784 ;; (when (plist-get info :with-special-strings)
3785 ;; (while (string-match (regexp-quote "...") text)
3786 ;; (setq text (replace-match "\\ldots{}" nil t text))))
3787 (when (plist-get info
:with-special-strings
)
3788 (setq text
(org-e-odt-convert-special-strings text
)))
3789 ;; Handle break preservation if required.
3790 (when (plist-get info
:preserve-breaks
)
3791 (setq text
(replace-regexp-in-string "\\(\\\\\\\\\\)?[ \t]*\n" " \\\\\\\\\n"
3799 (defun org-e-odt-planning (planning contents info
)
3800 "Transcode a PLANNING element from Org to HTML.
3801 CONTENTS is nil. INFO is a plist used as a communication
3803 (org-e-odt-format-fontify
3805 (let ((closed (org-element-property :closed planning
)))
3807 (concat (org-e-odt-format-fontify org-closed-string
"timestamp-kwd")
3808 (org-e-odt-format-fontify (org-translate-time closed
)
3810 (let ((deadline (org-element-property :deadline planning
)))
3812 (concat (org-e-odt-format-fontify org-deadline-string
"timestamp-kwd")
3813 (org-e-odt-format-fontify (org-translate-time deadline
)
3815 (let ((scheduled (org-element-property :scheduled planning
)))
3817 (concat (org-e-odt-format-fontify org-scheduled-string
"timestamp-kwd")
3818 (org-e-odt-format-fontify (org-translate-time scheduled
)
3820 "timestamp-wrapper"))
3823 ;;;; Property Drawer
3825 (defun org-e-odt-property-drawer (property-drawer contents info
)
3826 "Transcode a PROPERTY-DRAWER element from Org to HTML.
3827 CONTENTS is nil. INFO is a plist holding contextual
3829 ;; The property drawer isn't exported but we want separating blank
3830 ;; lines nonetheless.
3836 (defun org-e-odt-quote-block (quote-block contents info
)
3837 "Transcode a QUOTE-BLOCK element from Org to HTML.
3838 CONTENTS holds the contents of the block. INFO is a plist
3839 holding contextual information."
3840 (org-e-odt--wrap-label quote-block contents
))
3845 (defun org-e-odt-quote-section (quote-section contents info
)
3846 "Transcode a QUOTE-SECTION element from Org to HTML.
3847 CONTENTS is nil. INFO is a plist holding contextual information."
3848 (let ((value (org-remove-indentation
3849 (org-element-property :value quote-section
))))
3850 (when value
(org-e-odt-format-source-code-or-example value nil
))))
3855 (defun org-e-odt-section (section contents info
) ; FIXME
3856 "Transcode a SECTION element from Org to HTML.
3857 CONTENTS holds the contents of the section. INFO is a plist
3858 holding contextual information."
3863 (defun org-e-odt-radio-target (radio-target text info
)
3864 "Transcode a RADIO-TARGET object from Org to HTML.
3865 TEXT is the text of the target. INFO is a plist holding
3866 contextual information."
3867 (org-e-odt-format-anchor
3868 text
(org-export-solidify-link-text
3869 (org-element-property :value radio-target
))))
3874 (defun org-e-odt-special-block (special-block contents info
)
3875 "Transcode a SPECIAL-BLOCK element from Org to HTML.
3876 CONTENTS holds the contents of the block. INFO is a plist
3877 holding contextual information."
3878 (let ((type (downcase (org-element-property :type special-block
))))
3879 (org-e-odt--wrap-label
3881 (format "\\begin{%s}\n%s\\end{%s}" type contents type
))))
3886 (defun org-e-odt-src-block (src-block contents info
)
3887 "Transcode a SRC-BLOCK element from Org to HTML.
3888 CONTENTS holds the contents of the item. INFO is a plist holding
3889 contextual information."
3890 (let* ((lang (org-element-property :language src-block
))
3891 (caption (org-element-property :caption src-block
))
3892 (short-caption (and (cdr caption
)
3893 (org-export-data (cdr caption
) info
)))
3894 (caption (and (car caption
) (org-export-data (car caption
) info
)))
3895 (label (org-element-property :name src-block
)))
3896 ;; FIXME: Handle caption
3897 ;; caption-str (when caption)
3898 ;; (main (org-export-data (car caption) info))
3899 ;; (secondary (org-export-data (cdr caption) info))
3900 ;; (caption-str (org-e-odt--caption/label-string caption label info))
3901 (let* ((captions (org-e-odt-format-label src-block info
'definition
))
3902 (caption (car captions
)) (short-caption (cdr captions
)))
3904 (and caption
(org-e-odt-format-stylized-paragraph 'listing caption
))
3905 (org-e-odt-format-code src-block info
)))))
3908 ;;;; Statistics Cookie
3910 (defun org-e-odt-statistics-cookie (statistics-cookie contents info
)
3911 "Transcode a STATISTICS-COOKIE object from Org to HTML.
3912 CONTENTS is nil. INFO is a plist holding contextual information."
3913 (let ((cookie-value (org-element-property :value statistics-cookie
)))
3914 (org-e-odt-format-fontify cookie-value
'code
)))
3919 (defun org-e-odt-strike-through (strike-through contents info
)
3920 "Transcode STRIKE-THROUGH from Org to HTML.
3921 CONTENTS is the text with strike-through markup. INFO is a plist
3922 holding contextual information."
3923 (org-e-odt-format-fontify contents
'strike
))
3928 (defun org-e-odt-subscript (subscript contents info
)
3929 "Transcode a SUBSCRIPT object from Org to HTML.
3930 CONTENTS is the contents of the object. INFO is a plist holding
3931 contextual information."
3932 ;; (format (if (= (length contents) 1) "$_%s$" "$_{\\mathrm{%s}}$") contents)
3933 (org-e-odt-format-fontify contents
'subscript
))
3938 (defun org-e-odt-superscript (superscript contents info
)
3939 "Transcode a SUPERSCRIPT object from Org to HTML.
3940 CONTENTS is the contents of the object. INFO is a plist holding
3941 contextual information."
3942 ;; (format (if (= (length contents) 1) "$^%s$" "$^{\\mathrm{%s}}$") contents)
3943 (org-e-odt-format-fontify contents
'superscript
))
3948 (defun org-e-odt-table-style-spec (element info
)
3949 (let* ((table (org-export-get-parent-table element info
))
3950 (table-attributes (org-e-odt-element-attributes table info
))
3951 (table-style (plist-get table-attributes
:style
)))
3952 (assoc table-style org-e-odt-table-styles
)))
3954 (defun org-e-odt-get-table-cell-styles (table-cell info
)
3955 "Retrieve styles applicable to a table cell.
3956 R and C are (zero-based) row and column numbers of the table
3957 cell. STYLE-SPEC is an entry in `org-e-odt-table-styles'
3958 applicable to the current table. It is `nil' if the table is not
3959 associated with any style attributes.
3961 Return a cons of (TABLE-CELL-STYLE-NAME . PARAGRAPH-STYLE-NAME).
3963 When STYLE-SPEC is nil, style the table cell the conventional way
3964 - choose cell borders based on row and column groupings and
3965 choose paragraph alignment based on `org-col-cookies' text
3967 `org-e-odt-get-paragraph-style-cookie-for-table-cell'.
3969 When STYLE-SPEC is non-nil, ignore the above cookie and return
3970 styles congruent with the ODF-1.2 specification."
3971 (let* ((table-cell-address (org-export-table-cell-address table-cell info
))
3972 (r (car table-cell-address
)) (c (cdr table-cell-address
))
3973 (style-spec (org-e-odt-table-style-spec table-cell info
))
3974 (table-dimensions (org-export-table-dimensions
3975 (org-export-get-parent-table table-cell info
)
3978 ;; LibreOffice - particularly the Writer - honors neither table
3979 ;; templates nor custom table-cell styles. Inorder to retain
3980 ;; inter-operability with LibreOffice, only automatic styles are
3981 ;; used for styling of table-cells. The current implementation is
3982 ;; congruent with ODF-1.2 specification and hence is
3983 ;; future-compatible.
3985 ;; Additional Note: LibreOffice's AutoFormat facility for tables -
3986 ;; which recognizes as many as 16 different cell types - is much
3987 ;; richer. Unfortunately it is NOT amenable to easy configuration
3989 (let* ((template-name (nth 1 style-spec
))
3990 (cell-style-selectors (nth 2 style-spec
))
3993 ((and (cdr (assoc 'use-first-column-styles cell-style-selectors
))
3994 (= c
0)) "FirstColumn")
3995 ((and (cdr (assoc 'use-last-column-styles cell-style-selectors
))
3996 (= (1+ c
) (cdr table-dimensions
)))
3998 ((and (cdr (assoc 'use-first-row-styles cell-style-selectors
))
3999 (= r
0)) "FirstRow")
4000 ((and (cdr (assoc 'use-last-row-styles cell-style-selectors
))
4001 (= (1+ r
) (car table-dimensions
)))
4003 ((and (cdr (assoc 'use-banding-rows-styles cell-style-selectors
))
4004 (= (% r
2) 1)) "EvenRow")
4005 ((and (cdr (assoc 'use-banding-rows-styles cell-style-selectors
))
4006 (= (% r
2) 0)) "OddRow")
4007 ((and (cdr (assoc 'use-banding-columns-styles cell-style-selectors
))
4008 (= (% c
2) 1)) "EvenColumn")
4009 ((and (cdr (assoc 'use-banding-columns-styles cell-style-selectors
))
4010 (= (% c
2) 0)) "OddColumn")
4012 (concat template-name cell-type
)))))
4014 (defun org-e-odt-table-cell (table-cell contents info
)
4015 "Transcode a TABLE-CELL element from Org to ODT.
4016 CONTENTS is nil. INFO is a plist used as a communication
4018 (let* ((table-cell-address (org-export-table-cell-address table-cell info
))
4019 (r (car table-cell-address
))
4020 (c (cdr table-cell-address
))
4021 (horiz-span (or (org-export-table-cell-width table-cell info
) 0))
4022 (table-row (org-export-get-parent table-cell info
))
4023 (custom-style-prefix (org-e-odt-get-table-cell-styles
4027 (and custom-style-prefix
4028 (format "%sTableParagraph" custom-style-prefix
))
4031 ((and (= 1 (org-export-table-row-group table-row info
))
4032 (org-export-table-has-header-p
4033 (org-export-get-parent-table table-row info
) info
))
4035 ((and (zerop c
) t
;; (org-lparse-get 'TABLE-FIRST-COLUMN-AS-LABELS)
4038 (t "OrgTableContents"))
4039 (capitalize (symbol-name (org-export-table-cell-alignment
4040 table-cell info
))))))
4043 (and custom-style-prefix
(format "%sTableCell"
4044 custom-style-prefix
))
4047 (when (or (org-export-table-row-starts-rowgroup-p table-row info
)
4049 (when (org-export-table-row-ends-rowgroup-p table-row info
) "B")
4050 (when (and (org-export-table-cell-starts-colgroup-p table-cell info
)
4051 (not (zerop c
)) ) "L"))))
4054 (format " table:style-name=\"%s\"" cell-style-name
)
4055 (and (> horiz-span
0)
4056 (format " table:number-columns-spanned=\"%d\""
4057 (1+ horiz-span
))))))
4058 (unless contents
(setq contents
""))
4060 (org-e-odt-format-tags
4061 '("<table:table-cell%s>" .
"</table:table-cell>")
4062 (org-e-odt-format-stylized-paragraph paragraph-style contents
)
4065 (dotimes (i horiz-span s
)
4066 (setq s
(concat s
"\n<table:covered-table-cell/>"))))
4072 (defun org-e-odt-table-row (table-row contents info
)
4073 "Transcode a TABLE-ROW element from Org to ODT.
4074 CONTENTS is the contents of the row. INFO is a plist used as a
4075 communication channel."
4076 ;; Rules are ignored since table separators are deduced from
4077 ;; borders of the current row.
4078 (when (eq (org-element-property :type table-row
) 'standard
)
4079 (let* ((rowgroup-tags
4080 (if (and (= 1 (org-export-table-row-group table-row info
))
4081 (org-export-table-has-header-p
4082 (org-export-get-parent-table table-row info
) info
))
4083 ;; If the row belongs to the first rowgroup and the
4084 ;; table has more than one row groups, then this row
4085 ;; belongs to the header row group.
4086 '("\n<table:table-header-rows>" .
"\n</table:table-header-rows>")
4087 ;; Otherwise, it belongs to non-header row group.
4088 '("\n<table:table-rows>" .
"\n</table:table-rows>"))))
4090 ;; Does this row begin a rowgroup?
4091 (when (org-export-table-row-starts-rowgroup-p table-row info
)
4092 (car rowgroup-tags
))
4094 (org-e-odt-format-tags
4095 '("<table:table-row>" .
"</table:table-row>") contents
)
4096 ;; Does this row end a rowgroup?
4097 (when (org-export-table-row-ends-rowgroup-p table-row info
)
4098 (cdr rowgroup-tags
))))))
4103 (defun org-e-odt-table-first-row-data-cells (table info
)
4108 (unless (eq (org-element-property :type row
) 'rule
) row
))
4110 (special-column-p (org-export-table-has-special-column-p table
)))
4111 (if (not special-column-p
) (org-element-contents table-row
)
4112 (cdr (org-element-contents table-row
)))))
4114 (defun org-e-odt-table (table contents info
)
4115 "Transcode a TABLE element from Org to HTML.
4116 CONTENTS is the contents of the table. INFO is a plist holding
4117 contextual information."
4118 (case (org-element-property :type table
)
4121 (let* ((captions (org-e-odt-format-label table info
'definition
))
4122 (caption (car captions
)) (short-caption (cdr captions
))
4123 (attributes (org-e-odt-element-attributes table info
))
4124 (custom-table-style (nth 1 (org-e-odt-table-style-spec table info
)))
4127 (lambda (table info
)
4128 (let* ((table-style (or custom-table-style
"OrgTable"))
4129 (column-style (format "%sColumn" table-style
)))
4131 (lambda (table-cell)
4132 (let ((width (1+ (or (org-export-table-cell-width
4133 table-cell info
) 0))))
4134 (org-e-odt-make-string
4136 (org-e-odt-format-tags
4137 "<table:table-column table:style-name=\"%s\"/>"
4139 (org-e-odt-table-first-row-data-cells table info
) "\n"))))))
4142 (when caption
(org-e-odt-format-stylized-paragraph 'table caption
))
4144 (let* ((automatic-name
4145 (org-e-odt-add-automatic-style "Table" attributes
)))
4147 "\n<table:table table:name=\"%s\" table:style-name=\"%s\">\n"
4148 (or short-caption
(car automatic-name
))
4149 (or custom-table-style
(cdr automatic-name
) "OrgTable")))
4150 ;; column specification.
4151 (funcall table-column-specs table info
)
4155 "</table:table>")))))
4160 (defun org-e-odt-target (target contents info
)
4161 "Transcode a TARGET object from Org to HTML.
4162 CONTENTS is nil. INFO is a plist holding contextual
4164 (org-e-odt-format-anchor
4165 "" (org-export-solidify-link-text (org-element-property :value target
))))
4170 (defun org-e-odt-timestamp (timestamp contents info
)
4171 "Transcode a TIMESTAMP object from Org to HTML.
4172 CONTENTS is nil. INFO is a plist used as a communication
4174 (org-e-odt-format-fontify
4175 (org-e-odt-format-fontify
4176 (org-translate-time (org-element-property :value timestamp
))
4178 "timestamp-wrapper"))
4183 (defun org-e-odt-underline (underline contents info
)
4184 "Transcode UNDERLINE from Org to HTML.
4185 CONTENTS is the text with underline markup. INFO is a plist
4186 holding contextual information."
4187 (org-e-odt-format-fontify contents
'underline
))
4192 (defun org-e-odt-verbatim (verbatim contents info
)
4193 "Transcode a VERBATIM object from Org to HTML.
4194 CONTENTS is nil. INFO is a plist used as a communication
4196 (org-e-odt-format-fontify (org-element-property :value verbatim
) 'verbatim
))
4201 (defun org-e-odt-verse-block (verse-block contents info
)
4202 "Transcode a VERSE-BLOCK element from Org to HTML.
4203 CONTENTS is verse block contents. INFO is a plist holding
4204 contextual information."
4205 ;; Replace each newline character with line break. Also replace
4206 ;; each blank line with a line break.
4207 (setq contents
(replace-regexp-in-string
4208 "^ *\\\\\\\\$" "<br/>\n"
4209 (replace-regexp-in-string
4210 "\\(\\\\\\\\\\)?[ \t]*\n" " <br/>\n" contents
)))
4212 ;; Replace each white space at beginning of a line with a
4213 ;; non-breaking space.
4214 (while (string-match "^[ \t]+" contents
)
4215 (let ((new-str (org-e-odt-format-spaces
4216 (length (match-string 0 contents
)))))
4217 (setq contents
(replace-match new-str nil t contents
))))
4219 (org-e-odt--wrap-label
4220 verse-block
(format "<p class=\"verse\">\n%s</p>" contents
)))
4225 ;;; Filter Functions
4227 ;;;; Filter Settings
4230 ;;; Interactive functions
4232 (defun org-e-odt-export-to-odt
4233 (&optional subtreep visible-only body-only ext-plist pub-dir
)
4234 "Export current buffer to a HTML file.
4236 If narrowing is active in the current buffer, only export its
4239 If a region is active, export that region.
4241 When optional argument SUBTREEP is non-nil, export the sub-tree
4242 at point, extracting information from the headline properties
4245 When optional argument VISIBLE-ONLY is non-nil, don't export
4246 contents of hidden elements.
4248 When optional argument BODY-ONLY is non-nil, only write code
4249 between \"\\begin{document}\" and \"\\end{document}\".
4251 EXT-PLIST, when provided, is a property list with external
4252 parameters overriding Org default settings, but still inferior to
4253 file-local settings.
4255 When optional argument PUB-DIR is set, use it as the publishing
4258 Return output file's name."
4260 (setq debug-on-error t
)
4262 ;; (let* ((outfile (org-export-output-file-name ".html" subtreep pub-dir))
4263 ;; (outfile "content.xml"))
4264 ;; (org-export-to-file
4265 ;; 'e-odt outfile subtreep visible-only body-only ext-plist))
4267 (let* ((outbuf (org-e-odt-init-outfile))
4268 (target (org-export-output-file-name ".odt" subtreep pub-dir
))
4269 (outdir (file-name-directory (buffer-file-name outbuf
)))
4270 (default-directory outdir
))
4272 ;; FIXME: for copying embedded images
4273 (setq org-current-export-file
4274 (file-name-directory
4275 (org-export-output-file-name ".odt" subtreep nil
)))
4277 (org-export-to-buffer
4279 (memq 'subtree optns
) (memq 'visible optns
) (memq 'body optns
))
4281 (setq org-lparse-opt-plist nil
) ; FIXME
4282 (org-e-odt-save-as-outfile target
;; info
4287 (if (not org-e-odt-preferred-output-format
) target
4288 (or (org-e-odt-convert target org-e-odt-preferred-output-format
)
4295 (defun org-e-odt-reachable-p (in-fmt out-fmt
)
4296 "Return non-nil if IN-FMT can be converted to OUT-FMT."
4298 (let ((reachable-formats (org-e-odt-do-reachable-formats in-fmt
)))
4299 (dolist (e reachable-formats
)
4300 (let ((out-fmt-spec (assoc out-fmt
(cdr e
))))
4302 (throw 'done
(cons (car e
) out-fmt-spec
))))))))
4304 (defun org-e-odt-do-convert (in-file out-fmt
&optional prefix-arg
)
4305 "Workhorse routine for `org-e-odt-convert'."
4306 (require 'browse-url
)
4307 (let* ((in-file (expand-file-name (or in-file buffer-file-name
)))
4308 (dummy (or (file-readable-p in-file
)
4309 (error "Cannot read %s" in-file
)))
4310 (in-fmt (file-name-extension in-file
))
4311 (out-fmt (or out-fmt
(error "Output format unspecified")))
4312 (how (or (org-e-odt-reachable-p in-fmt out-fmt
)
4313 (error "Cannot convert from %s format to %s format?"
4315 (convert-process (car how
))
4316 (out-file (concat (file-name-sans-extension in-file
) "."
4317 (nth 1 (or (cdr how
) out-fmt
))))
4318 (extra-options (or (nth 2 (cdr how
)) ""))
4319 (out-dir (file-name-directory in-file
))
4320 (cmd (format-spec convert-process
4321 `((?i .
,(shell-quote-argument in-file
))
4322 (?I .
,(browse-url-file-url in-file
))
4325 (?O .
,(browse-url-file-url out-file
))
4326 (?d .
, (shell-quote-argument out-dir
))
4327 (?D .
,(browse-url-file-url out-dir
))
4328 (?x .
,extra-options
)))))
4329 (when (file-exists-p out-file
)
4330 (delete-file out-file
))
4332 (message "Executing %s" cmd
)
4333 (let ((cmd-output (shell-command-to-string cmd
)))
4334 (message "%s" cmd-output
))
4337 ((file-exists-p out-file
)
4338 (message "Exported to %s" out-file
)
4340 (message "Opening %s..." out-file
)
4341 (org-open-file out-file
))
4344 (message "Export to %s failed" out-file
)
4347 (defun org-e-odt-do-reachable-formats (in-fmt)
4348 "Return verbose info about formats to which IN-FMT can be converted.
4349 Return a list where each element is of the
4350 form (CONVERTER-PROCESS . OUTPUT-FMT-ALIST). See
4351 `org-e-odt-convert-processes' for CONVERTER-PROCESS and see
4352 `org-e-odt-convert-capabilities' for OUTPUT-FMT-ALIST."
4354 (and org-e-odt-convert-process
4355 (cadr (assoc-string org-e-odt-convert-process
4356 org-e-odt-convert-processes t
))))
4358 (and org-e-odt-convert-process
4359 (cadr (assoc-string org-e-odt-convert-process
4360 org-e-odt-convert-processes t
))
4361 org-e-odt-convert-capabilities
))
4364 (dolist (c capabilities
)
4365 (when (member in-fmt
(nth 1 c
))
4366 (push (cons converter
(nth 2 c
)) reachable-formats
))))
4369 (defun org-e-odt-reachable-formats (in-fmt)
4370 "Return list of formats to which IN-FMT can be converted.
4371 The list of the form (OUTPUT-FMT-1 OUTPUT-FMT-2 ...)."
4373 (mapc (lambda (e) (add-to-list 'l e
))
4374 (apply 'append
(mapcar
4375 (lambda (e) (mapcar 'car
(cdr e
)))
4376 (org-e-odt-do-reachable-formats in-fmt
))))
4379 (defun org-e-odt-convert-read-params ()
4380 "Return IN-FILE and OUT-FMT params for `org-e-odt-do-convert'.
4381 This is a helper routine for interactive use."
4382 (let* ((input (if (featurep 'ido
) 'ido-completing-read
'completing-read
))
4383 (in-file (read-file-name "File to be converted: "
4384 nil buffer-file-name t
))
4385 (in-fmt (file-name-extension in-file
))
4386 (out-fmt-choices (org-e-odt-reachable-formats in-fmt
))
4388 (or (and out-fmt-choices
4389 (funcall input
"Output format: "
4390 out-fmt-choices nil nil nil
))
4392 "No known converter or no known output formats for %s files"
4394 (list in-file out-fmt
)))
4397 (defun org-e-odt-convert (&optional in-file out-fmt prefix-arg
)
4398 "Convert IN-FILE to format OUT-FMT using a command line converter.
4399 IN-FILE is the file to be converted. If unspecified, it defaults
4400 to variable `buffer-file-name'. OUT-FMT is the desired output
4401 format. Use `org-e-odt-convert-process' as the converter.
4402 If PREFIX-ARG is non-nil then the newly converted file is opened
4403 using `org-open-file'."
4405 (append (org-e-odt-convert-read-params) current-prefix-arg
))
4406 (org-e-odt-do-convert in-file out-fmt prefix-arg
))
4408 ;;; FIXMES, TODOS, FOR REVIEW etc
4410 ;; (defun org-e-odt-discontinue-list ()
4411 ;; (let ((stashed-stack org-lparse-list-stack))
4412 ;; (loop for list-type in stashed-stack
4413 ;; do (org-lparse-end-list-item-1 list-type)
4414 ;; (org-lparse-end-list list-type))
4415 ;; (setq org-e-odt-list-stack-stashed stashed-stack)))
4417 ;; (defun org-e-odt-continue-list ()
4418 ;; (setq org-e-odt-list-stack-stashed (nreverse org-e-odt-list-stack-stashed))
4419 ;; (loop for list-type in org-e-odt-list-stack-stashed
4420 ;; do (org-lparse-begin-list list-type)
4421 ;; (org-lparse-begin-list-item list-type)))
4423 ;; FIXME: Begin indented table
4424 ;; (setq org-e-odt-table-indentedp (not (null org-lparse-list-stack)))
4425 ;; (setq org-e-odt-table-indentedp nil) ; FIXME
4426 ;; (when org-e-odt-table-indentedp
4427 ;; ;; Within the Org file, the table is appearing within a list item.
4428 ;; ;; OpenDocument doesn't allow table to appear within list items.
4429 ;; ;; Temporarily terminate the list, emit the table and then
4430 ;; ;; re-continue the list.
4431 ;; (org-e-odt-discontinue-list)
4432 ;; ;; Put the Table in an indented section.
4433 ;; (let ((level (length org-e-odt-list-stack-stashed)))
4434 ;; (org-e-odt-begin-section (format "OrgIndentedSection-Level-%d" level))))
4436 ;; FIXME: End indented table
4437 ;; (when org-e-odt-table-indentedp
4438 ;; (org-e-odt-end-section)
4439 ;; (org-e-odt-continue-list))
4442 ;;;; org-format-table-html
4443 ;;;; org-format-org-table-html
4444 ;;;; org-format-table-table-html
4445 ;;;; org-table-number-fraction
4446 ;;;; org-table-number-regexp
4447 ;;;; org-e-odt-table-caption-above
4450 ;;;; "<span style=\"visibility:hidden;\">%s</span>"
4451 ;;;; Remove display properties
4453 ;;;; org-e-odt-with-timestamp
4454 ;;;; org-e-odt-html-helper-timestamp
4456 ;;;; org-export-as-html-and-open
4457 ;;;; org-export-as-html-batch
4458 ;;;; org-export-as-html-to-buffer
4459 ;;;; org-replace-region-by-html
4460 ;;;; org-export-region-as-html
4461 ;;;; org-export-as-html
4463 ;;;; (org-export-directory :html opt-plist)
4464 ;;;; (plist-get opt-plist :html-extension)
4465 ;;;; org-e-odt-toplevel-hlevel
4466 ;;;; org-e-odt-inline-image-extensions
4467 ;;;; org-e-odt-protect-char-alist
4468 ;;;; org-e-odt-table-use-header-tags-for-first-column
4469 ;;;; org-e-odt-todo-kwd-class-prefix
4470 ;;;; org-e-odt-tag-class-prefix
4471 ;;;; org-e-odt-footnote-separator
4474 ;;; Library Initializations
4478 ;; Let Org open all OpenDocument files using system-registered app
4479 (add-to-list 'org-file-apps
4480 (cons (concat "\\." (car desc
) "\\'") 'system
))
4481 ;; Let Emacs open all OpenDocument files in archive mode
4482 (add-to-list 'auto-mode-alist
4483 (cons (concat "\\." (car desc
) "\\'") 'archive-mode
)))
4484 org-e-odt-file-extensions
)
4486 (defvar org-e-odt-display-outline-level
2)
4487 (defun org-e-odt-enumerate-element (element info
&optional predicate n
)
4488 (let* ((numbered-parent-headline-at-<=-n
4490 (lambda (element n info
)
4491 (loop for x in
(org-export-get-genealogy element info
)
4492 thereis
(and (eq (org-element-type x
) 'headline
)
4493 (<= (org-export-get-relative-level x info
) n
)
4494 (org-export-numbered-headline-p x info
)
4498 (lambda (element scope info
&optional predicate
)
4501 (or scope
(plist-get info
:parse-tree
))
4502 (org-element-type element
)
4504 (and (or (not predicate
) (funcall predicate el info
))
4508 info
'first-match
)))))
4509 (scope (funcall numbered-parent-headline-at-
<=-n
4510 element
(or n org-e-odt-display-outline-level
) info
))
4511 (ordinal (funcall enumerate element scope info predicate
))
4516 (mapconcat 'number-to-string
4517 (org-export-get-headline-number scope info
) "."))
4521 (number-to-string ordinal
))))
4522 ;; (message "%s:\t%s" (org-element-property :name element) tag)
4525 (provide 'org-e-odt
)
4527 ;;; org-e-odt.el ends here