1 ;;; org-e-odt.el --- OpenDocument Text exporter for Org-mode
3 ;; Copyright (C) 2010-2012 Free Software Foundation, Inc.
5 ;; Author: Jambunathan K <kjambunathan at gmail dot com>
6 ;; Keywords: outlines, hypermedia, calendar, wp
7 ;; Homepage: http://orgmode.org
9 ;; This file is part of GNU Emacs.
11 ;; GNU Emacs is free software: you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation, either version 3 of the License, or
14 ;; (at your option) any later version.
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
31 ;; org-e-odt-preprocess-latex-fragments
32 ;; org-export-as-e-odt-and-open
33 ;; org-export-as-e-odt-batch
34 ;; org-export-as-e-odt
36 (defun org-e-odt-get-style-name-for-entity (category &optional entity
)
37 (let ((entity (or entity
'default
)))
39 (cdr (assoc entity
(cdr (assoc category
40 org-e-odt-org-styles-alist
))))
41 (cdr (assoc entity
(cdr (assoc category
42 org-e-odt-default-org-styles-alist
))))
43 (error "Cannot determine style name for entity %s of type %s"
46 ;; Following variable is let bound when `org-do-lparse' is in
47 ;; progress. See org-html.el.
49 (defun org-e-odt-format-preamble (info)
50 (let* ((title (org-export-secondary-string
51 (plist-get info
:title
) 'e-odt info
))
52 (author (and (plist-get info
:with-author
)
53 (let ((auth (plist-get info
:author
)))
54 (and auth
(org-export-secondary-string
56 (date (plist-get info
:date
))
57 (iso-date (org-e-odt-format-date date
))
58 (date (org-e-odt-format-date date
"%d %b %Y"))
59 (email (plist-get info
:email
))
60 ;; switch on or off above vars based on user settings
61 (author (and (plist-get info
:with-author
) (or author email
)))
62 ;; (date (and (plist-get info :time-stamp-file) date))
63 (email (and (plist-get info
:with-email
) email
)))
68 (org-e-odt-format-stylized-paragraph
69 'title
(format "\n<text:title>%s</text:title>" title
))
71 "\n<text:p text:style-name=\"OrgTitle\"/>"))
73 ((and author
(not email
))
76 (org-e-odt-format-stylized-paragraph
78 (format "<text:initial-creator>%s</text:initial-creator>" author
))
80 "\n<text:p text:style-name=\"OrgSubtitle\"/>"))
84 (org-e-odt-format-stylized-paragraph
86 (org-e-odt-format-link
87 (format "<text:initial-creator>%s</text:initial-creator>" author
)
88 (concat "mailto:" email
)))
90 "\n<text:p text:style-name=\"OrgSubtitle\"/>")))
94 (org-e-odt-format-stylized-paragraph
96 (org-e-odt-format-tags
97 '("<text:date style:data-style-name=\"%s\" text:date-value=\"%s\">"
101 "<text:p text:style-name=\"OrgSubtitle\"/>")))))
103 (defun org-e-odt-begin-section (style &optional name
)
104 (let ((default-name (car (org-e-odt-add-automatic-style "Section"))))
105 (format "<text:section text:style-name=\"%s\" text:name=\"%s\">"
106 style
(or name default-name
))))
108 (defun org-e-odt-end-section ()
111 (defun org-e-odt-begin-paragraph (&optional style
)
112 (format "<text:p%s>" (org-e-odt-get-extra-attrs-for-paragraph-style style
)))
114 (defun org-e-odt-end-paragraph ()
117 (defun org-e-odt-get-extra-attrs-for-paragraph-style (style)
121 ((stringp style
) style
)
122 ((symbolp style
) (org-e-odt-get-style-name-for-entity
125 (error "Don't know how to handle paragraph style %s" style
))
126 (format " text:style-name=\"%s\"" style-name
)))
128 (defun org-e-odt-format-stylized-paragraph (style text
)
129 (format "\n<text:p%s>%s</text:p>"
130 (org-e-odt-get-extra-attrs-for-paragraph-style style
)
133 (defun org-e-odt-format-author (&optional author
)
134 (when (setq author
(or author
(plist-get org-lparse-opt-plist
:author
)))
135 (format "<dc:creator>%s</dc:creator>" author
)))
137 (defun org-e-odt-format-date (&optional org-ts fmt
)
140 (and (stringp org-ts
)
141 (string-match org-ts-regexp0 org-ts
)
143 (org-fix-decoded-time
144 (org-parse-time-string (match-string 0 org-ts
) t
)))))
147 (fmt (format-time-string fmt time
))
148 (t (setq date
(format-time-string "%Y-%m-%dT%H:%M:%S%z" time
))
149 (format "%s:%s" (substring date
0 -
2) (substring date -
2)))))))
151 (defun org-e-odt-begin-annotation (&optional author date
)
153 "<office:annotation>\n"
154 (and author
(org-e-odt-format-author author
))
155 (org-e-odt-format-tags
156 '("<dc:date>" .
"</dc:date>")
157 (org-e-odt-format-date
158 (or date
(plist-get org-lparse-opt-plist
:date
))))
159 (org-e-odt-begin-paragraph)))
161 (defun org-e-odt-end-annotation ()
162 "</office:annotation>")
164 (defun org-e-odt-begin-plain-list (ltype)
165 (let* ((style-name (org-e-odt-get-style-name-for-entity 'list ltype
))
167 ;; (if (or org-lparse-list-table-p
168 ;; (and (= 1 (length org-lparse-list-stack))
169 ;; (null org-e-odt-list-stack-stashed)))
170 ;; " text:continue-numbering=\"false\""
171 ;; " text:continue-numbering=\"true\"")
173 " text:continue-numbering=\"true\""
176 (format " text:style-name=\"%s\"" style-name
)))))
178 ((ordered unordered descriptive
)
180 ;; (org-e-odt-end-paragraph)
181 (format "<text:list%s>" extra
)))
182 (t (error "Unknown list type: %s" ltype
)))))
184 (defun org-e-odt-end-plain-list (ltype)
185 (if ltype
"</text:list>"
186 (error "Unknown list type: %s" ltype
)))
188 (defun org-e-odt-begin-list-item (ltype &optional arg headline
)
191 (assert (not headline
) t
)
192 (let* ((counter arg
) (extra ""))
193 (concat "<text:list-item>" ;; (org-e-odt-begin-paragraph)
195 ;; (if (= (length org-lparse-list-stack)
196 ;; (length org-e-odt-list-stack-stashed))
197 ;; "<text:list-header>" "<text:list-item>")
200 (let* ((id arg
) (extra ""))
203 ;; (org-e-odt-begin-paragraph)
204 (if headline
(org-e-odt-format-target headline id
)
205 (org-e-odt-format-bookmark "" id
)))
206 ;; (if (= (length org-lparse-list-stack)
207 ;; (length org-e-odt-list-stack-stashed))
208 ;; "<text:list-header>" "<text:list-item>")
211 (assert (not headline
) t
)
212 (let ((term (or arg
"(no term)")))
214 (org-e-odt-format-tags
215 '("<text:list-item>" .
"</text:list-item>")
216 (org-e-odt-format-stylized-paragraph 'definition-term term
))
217 (org-e-odt-begin-list-item 'unordered
)
218 (org-e-odt-begin-plain-list 'descriptive
)
219 (org-e-odt-begin-list-item 'unordered
))))
220 (t (error "Unknown list type"))))
222 (defun org-e-odt-end-list-item (ltype)
225 ;; (org-lparse-insert-tag
226 ;; (if (= (length org-lparse-list-stack)
227 ;; (length org-e-odt-list-stack-stashed))
228 ;; (prog1 "</text:list-header>"
229 ;; (setq org-e-odt-list-stack-stashed nil))
230 ;; "</text:list-item>")
236 (org-e-odt-end-list-item 'unordered
)
237 (org-e-odt-end-plain-list 'descriptive
)
238 (org-e-odt-end-list-item 'unordered
)
240 (t (error "Unknown list type"))))
242 (defun org-e-odt-write-automatic-styles ()
243 "Write automatic styles to \"content.xml\"."
245 (find-file-noselect (expand-file-name "content.xml") t
)
246 ;; position the cursor
247 (goto-char (point-min))
248 (re-search-forward " </office:automatic-styles>" nil t
)
249 (goto-char (match-beginning 0))
250 ;; write automatic table styles
251 (loop for
(style-name props
) in
252 (plist-get org-e-odt-automatic-styles
'Table
) do
253 (when (setq props
(or (plist-get props
:rel-width
) 96))
254 (insert (format org-e-odt-table-style-format style-name props
))))))
256 (defun org-e-odt-update-display-level (&optional level
)
258 (find-file-noselect (expand-file-name "content.xml") t
)
259 ;; position the cursor.
260 (goto-char (point-min))
261 ;; remove existing sequence decls.
262 (when (re-search-forward "<text:sequence-decls" nil t
)
263 (delete-region (match-beginning 0)
264 (re-search-forward "</text:sequence-decls>" nil nil
)))
267 <text:sequence-decls>")
268 (loop for x in org-e-odt-category-map-alist
270 <text:sequence-decl text:display-outline-level=\"%d\" text:name=\"%s\"/>"
273 </text:sequence-decls>")))
275 (defun org-e-odt-add-automatic-style (object-type &optional object-props
)
276 "Create an automatic style of type OBJECT-TYPE with param OBJECT-PROPS.
277 OBJECT-PROPS is (typically) a plist created by passing
278 \"#+ATTR_ODT: \" option of the object in question to
279 `org-e-odt-parse-block-attributes'.
281 Use `org-e-odt-object-counters' to generate an automatic
282 OBJECT-NAME and STYLE-NAME. If OBJECT-PROPS is non-nil, add a
283 new entry in `org-e-odt-automatic-styles'. Return (OBJECT-NAME
285 (assert (stringp object-type
))
286 (let* ((object (intern object-type
))
288 (seqno (1+ (or (plist-get org-e-odt-object-counters seqvar
) 0)))
289 (object-name (format "%s%d" object-type seqno
)) style-name
)
290 (setq org-e-odt-object-counters
291 (plist-put org-e-odt-object-counters seqvar seqno
))
293 (setq style-name
(format "Org%s" object-name
))
294 (setq org-e-odt-automatic-styles
295 (plist-put org-e-odt-automatic-styles object
296 (append (list (list style-name object-props
))
297 (plist-get org-e-odt-automatic-styles object
)))))
298 (cons object-name style-name
)))
300 (defun org-e-odt-begin-toc (lang-specific-heading max-level
)
303 <text:table-of-content text:style-name=\"Sect2\" text:protected=\"true\" text:name=\"Table of Contents1\">
304 <text:table-of-content-source text:outline-level=\"%d\">
305 <text:index-title-template text:style-name=\"Contents_20_Heading\">%s</text:index-title-template>
306 " max-level lang-specific-heading
)
308 (let ((entry-templates ""))
309 (loop for level from
1 upto
10
310 do
(setq entry-templates
311 (concat entry-templates
314 <text:table-of-content-entry-template text:outline-level=\"%d\" text:style-name=\"Contents_20_%d\">
315 <text:index-entry-link-start text:style-name=\"Internet_20_link\"/>
316 <text:index-entry-chapter/>
317 <text:index-entry-text/>
318 <text:index-entry-link-end/>
319 </text:table-of-content-entry-template>
324 </text:table-of-content-source>
327 <text:index-title text:style-name=\"Sect1\" text:name=\"Table of Contents1_Head\">
328 <text:p text:style-name=\"Contents_20_Heading\">%s</text:p>
330 " lang-specific-heading
)))
332 (defun org-e-odt-end-toc ()
335 </text:table-of-content>
338 (defun org-e-odt-format-toc-entry (snumber todo headline tags href
)
341 (setq headline
(concat
342 (and org-export-with-section-numbers
343 (concat snumber
". "))
347 (org-e-odt-format-spaces 3)
348 (org-e-odt-format-fontify tags
"tag")))))
350 (setq headline
(org-e-odt-format-fontify headline
"todo")))
352 (let ((org-e-odt-suppress-xref t
))
353 (org-e-odt-format-link headline
(concat "#" href
))))
355 (defun org-e-odt-format-toc-item (toc-entry level org-last-level
)
356 (let ((style (format "Contents_20_%d" level
)))
357 (concat "\n" (org-e-odt-format-stylized-paragraph style toc-entry
) "\n")))
359 ;; Following variable is let bound during 'ORG-LINK callback. See
362 (defun org-e-odt-format-link (desc href
&optional attr
)
364 ((and (= (string-to-char href
) ?
#) (not org-e-odt-suppress-xref
))
365 (setq href
(substring href
1))
366 (let ((xref-format "text"))
368 (setq desc
(format "%d" desc
) xref-format
"number"))
370 (setq desc
(mapconcat 'identity desc
".") xref-format
"chapter"))
371 (setq href
(concat org-e-odt-bookmark-prefix href
))
372 (org-e-odt-format-tags-simple
373 '("<text:bookmark-ref text:reference-format=\"%s\" text:ref-name=\"%s\">" .
374 "</text:bookmark-ref>")
375 desc xref-format href
)))
376 (org-lparse-link-description-is-image
377 (org-e-odt-format-tags
378 '("<draw:a xlink:type=\"simple\" xlink:href=\"%s\" %s>" .
"</draw:a>")
379 desc href
(or attr
"")))
381 (org-e-odt-format-tags-simple
382 '("<text:a xlink:type=\"simple\" xlink:href=\"%s\" %s>" .
"</text:a>")
383 desc href
(or attr
"")))))
385 (defun org-e-odt-format-spaces (n)
389 " " (org-e-odt-format-tags "<text:s text:c=\"%d\"/>" "" (1- n
))))
392 (defun org-e-odt-format-tabs (&optional n
)
393 (let ((tab "<text:tab/>")
397 (defun org-e-odt-format-line-break ()
398 (org-e-odt-format-tags "<text:line-break/>" ""))
400 (defun org-e-odt-format-horizontal-line ()
401 (org-e-odt-format-stylized-paragraph 'horizontal-line
""))
403 (defun org-e-odt-encode-plain-text (line &optional no-whitespace-filling
)
404 (setq line
(org-e-html-encode-plain-text line
))
405 (if no-whitespace-filling line
406 (org-e-odt-fill-tabs-and-spaces line
)))
408 (defun org-e-odt-format-line (line)
409 (case org-lparse-dyn-current-environment
411 (org-e-odt-format-stylized-paragraph
412 'fixedwidth
(org-e-odt-encode-plain-text line
)) "\n"))
413 (t (concat line
"\n"))))
415 (defun org-e-odt-format-comment (fmt &rest args
)
416 (let ((comment (apply 'format fmt args
)))
417 (format "\n<!-- %s -->\n" comment
)))
419 (defun org-e-odt-format-org-entity (wd)
420 (org-entity-get-representation wd
'utf8
))
422 (defun org-e-odt-fill-tabs-and-spaces (line)
423 (replace-regexp-in-string
424 "\\([\t]\\|\\([ ]+\\)\\)" (lambda (s)
426 ((string= s
"\t") (org-e-odt-format-tabs))
427 (t (org-e-odt-format-spaces (length s
))))) line
))
429 (defun org-e-odt-hfy-face-to-css (fn)
430 "Create custom style for face FN.
431 When FN is the default face, use it's foreground and background
432 properties to create \"OrgSrcBlock\" paragraph style. Otherwise
433 use it's color attribute to create a character style whose name
434 is obtained from FN. Currently all attributes of FN other than
437 The style name for a face FN is derived using the following
438 operations on the face name in that order - de-dash, CamelCase
439 and prefix with \"OrgSrc\". For example,
440 `font-lock-function-name-face' is associated with
441 \"OrgSrcFontLockFunctionNameFace\"."
442 (let* ((css-list (hfy-face-to-style fn
))
443 (style-name ((lambda (fn)
446 'capitalize
(split-string
447 (hfy-face-or-def-to-name fn
) "-")
449 (color-val (cdr (assoc "color" css-list
)))
450 (background-color-val (cdr (assoc "background" css-list
)))
451 (style (and org-e-odt-create-custom-styles-for-srcblocks
454 (format org-src-block-paragraph-format
455 background-color-val color-val
))
459 <style:style style:name=\"%s\" style:family=\"text\">
460 <style:text-properties fo:color=\"%s\"/>
461 </style:style>" style-name color-val
))))))
462 (cons style-name style
)))
464 (defun org-e-odt-insert-custom-styles-for-srcblocks (styles)
465 "Save STYLES used for colorizing of source blocks.
466 Update styles.xml with styles that were collected as part of
467 `org-e-odt-hfy-face-to-css' callbacks."
470 (find-file-noselect (expand-file-name "styles.xml") t
)
471 (goto-char (point-min))
472 (when (re-search-forward "</office:styles>" nil t
)
473 (goto-char (match-beginning 0))
474 (insert "\n<!-- Org Htmlfontify Styles -->\n" styles
"\n")))))
476 (defun org-e-odt-remap-stylenames (style-name)
478 (cdr (assoc style-name
'(("timestamp-wrapper" .
"OrgTimestampWrapper")
479 ("timestamp" .
"OrgTimestamp")
480 ("timestamp-kwd" .
"OrgTimestampKeyword")
484 ("target" .
"OrgTarget"))))
487 (defun org-e-odt-format-fontify (text style
&optional id
)
491 (org-e-odt-remap-stylenames style
))
493 (org-e-odt-get-style-name-for-entity 'character style
))
495 (assert (< 1 (length style
)))
496 (let ((parent-style (pop style
)))
497 (mapconcat (lambda (s)
498 ;; (assert (stringp s) t)
499 (org-e-odt-remap-stylenames s
)) style
"")
500 (org-e-odt-remap-stylenames parent-style
)))
501 (t (error "Don't how to handle style %s" style
)))))
502 (org-e-odt-format-tags-simple
503 '("<text:span text:style-name=\"%s\">" .
"</text:span>")
506 (defun org-e-odt-relocate-relative-path (path dir
)
507 (if (file-name-absolute-p path
) path
508 (file-relative-name (expand-file-name path dir
)
509 (expand-file-name "eyecandy" dir
))))
511 (defun org-e-odt-format-formula (element info
)
513 ((eq (org-element-type element
) 'link
) ; FIXME
514 (let* ((type (org-element-property :type element
))
515 (raw-path (org-element-property :path element
)))
517 ((file-name-absolute-p raw-path
)
518 (expand-file-name raw-path
))
520 ((member (org-element-type element
)
521 '(latex-fragment latex-environment
))
522 (let* ((latex-frag (org-remove-indentation
523 (org-element-property
525 (formula-link (org-e-odt-format-latex
526 latex-frag
'mathml
)))
528 (string-match "file:\\([^]]*\\)" formula-link
)
529 (match-string 1 formula-link
))))
530 (t (error "what is this?"))))
532 (case (org-element-type element
)
533 (link (org-export-get-parent-paragraph element info
))
535 (captions (org-e-odt-format-label caption-from info
'definition
))
536 (caption (car captions
))
538 (org-e-odt-format-tags
539 "<draw:object xlink:href=\"%s\" xlink:type=\"simple\" xlink:show=\"embed\" xlink:actuate=\"onLoad\"/>" ""
540 (file-name-directory (org-e-odt-copy-formula-file src
))))
541 (embed-as (if caption
'paragraph
'character
))
544 ((eq embed-as
'character
)
545 (org-e-odt-format-entity "InlineFormula" href width height
))
547 (let ((table-info nil
)
549 '(:alignment
["c" "c"]
550 :column-groups
[nil nil
]
552 :special-column-p nil
:width
[8 1]))
553 (org-lparse-table-ncols 2)) ; FIXME
554 (org-e-odt-list-table ; FIXME
557 (org-e-odt-format-entity
558 "CaptionedDisplayFormula" href width height captions
)
559 (let* ((org-e-odt-category-map-alist
560 '(("__Table__" "Table" "value")
561 ("__Figure__" "Illustration" "value")
562 ("__MathFormula__" "Text" "math-label")
563 ("__DvipngImage__" "Equation" "value")
564 ("__Listing__" "Listing" "value"))))
565 (car (org-e-odt-format-label caption-from info
'definition
)))))
566 '(table (:attr_odt
(":style \"OrgEquation\""))) info
))))))
568 (defun org-e-odt-copy-formula-file (path)
569 "Returns the internal name of the file"
570 (let* ((src-file (expand-file-name
571 path
(file-name-directory org-current-export-file
)))
572 (target-dir (format "Formula-%04d/"
573 (incf org-e-odt-embedded-formulas-count
)))
574 (target-file (concat target-dir
"content.xml")))
575 (message "Embedding %s as %s ..."
576 (substring-no-properties path
) target-file
)
578 (make-directory target-dir
)
579 (org-e-odt-create-manifest-file-entry
580 "application/vnd.oasis.opendocument.formula" target-dir
"1.2")
582 (case (org-e-odt-is-formula-link-p src-file
)
584 (copy-file src-file target-file
'overwrite
))
586 (org-e-odt-zip-extract-one src-file
"content.xml" target-dir
))
588 (error "%s is not a formula file" src-file
)))
590 (org-e-odt-create-manifest-file-entry "text/xml" target-file
)
593 (defun org-e-odt-is-formula-link-p (file)
594 (let ((case-fold-search nil
))
596 ((string-match "\\.\\(mathml\\|mml\\)\\'" file
)
598 ((string-match "\\.odf\\'" file
)
601 (defun org-e-odt-format-org-link (opt-plist type-1 path fragment desc attr
603 "Make a OpenDocument link.
604 OPT-PLIST is an options list.
605 TYPE-1 is the device-type of the link (THIS://foo.html).
606 PATH is the path of the link (http://THIS#location).
607 FRAGMENT is the fragment part of the link, if any (foo.html#THIS).
608 DESC is the link description, if any.
609 ATTR is a string of other attributes of the a element."
610 (declare (special org-lparse-par-open
))
613 (and (member type-1
'("http" "https" "file"))
614 (org-lparse-should-inline-p path descp
)
616 (type (if (equal type-1
"id") "file" type-1
))
620 ;; check for inlined images
621 ((and (member type
'("file"))
624 filename org-e-odt-inline-image-extensions
)
626 (org-e-odt-format-inline-image thefile
))
627 ;; check for embedded formulas
628 ((and (member type
'("file"))
630 (org-e-odt-is-formula-link-p filename
)
632 (org-e-odt-format-formula thefile
))
633 ((string= type
"coderef")
634 (let* ((ref fragment
)
635 (lineno-or-ref (cdr (assoc ref org-export-code-refs
)))
636 (desc (and descp desc
))
637 (org-e-odt-suppress-xref nil
)
638 (href (org-xml-format-href (concat "#coderef-" ref
))))
640 ((and (numberp lineno-or-ref
) (not desc
))
641 (org-e-odt-format-link lineno-or-ref href
))
642 ((and (numberp lineno-or-ref
) desc
643 (string-match (regexp-quote (concat "(" ref
")")) desc
))
644 (format (replace-match "%s" t t desc
)
645 (org-e-odt-format-link lineno-or-ref href
)))
648 (if (and desc
(string-match
649 (regexp-quote (concat "(" ref
")"))
651 (replace-match "%s" t t desc
)
654 (org-e-odt-format-link (org-xml-format-desc desc
) href
)))))
656 (when (string= type
"file")
659 ((file-name-absolute-p path
)
660 (concat "file://" (expand-file-name path
)))
661 (t (org-e-odt-relocate-relative-path
662 thefile org-current-export-file
)))))
664 (when (and (member type
'("" "http" "https" "file")) fragment
)
665 (setq thefile
(concat thefile
"#" fragment
)))
667 (setq thefile
(org-xml-format-href thefile
))
669 (when (not (member type
'("" "file")))
670 (setq thefile
(concat type
":" thefile
)))
672 (let ((org-e-odt-suppress-xref nil
))
673 (org-e-odt-format-link
674 (org-xml-format-desc desc
) thefile attr
)))))))
676 (defun org-e-odt-format-anchor (text name
&optional class
)
677 (org-e-odt-format-target text name
))
679 (defun org-e-odt-format-bookmark (text id
)
681 (org-e-odt-format-tags "<text:bookmark text:name=\"%s\"/>" text id
)
684 (defun org-e-odt-format-target (text id
)
685 (let ((name (concat org-e-odt-bookmark-prefix id
)))
687 (and id
(org-e-odt-format-tags
688 "<text:bookmark-start text:name=\"%s\"/>" "" name
))
689 (org-e-odt-format-bookmark text id
)
690 (and id
(org-e-odt-format-tags
691 "<text:bookmark-end text:name=\"%s\"/>" "" name
)))))
693 (defun org-e-odt-format-footnote (n def
)
694 (setq n
(format "%d" n
))
695 (let ((id (concat "fn" n
))
696 (note-class "footnote")
697 (par-style "Footnote"))
698 (org-e-odt-format-tags-simple
699 '("<text:note text:id=\"%s\" text:note-class=\"%s\">" .
"</text:note>")
701 (org-e-odt-format-tags-simple
702 '("<text:note-citation>" .
"</text:note-citation>") n
)
703 (org-e-odt-format-tags-simple
704 '("<text:note-body>" .
"</text:note-body>") def
))
707 (defun org-e-odt-format-footnote-reference (n def refcnt
)
709 (org-e-odt-format-footnote n def
)
710 (org-e-odt-format-footnote-ref n
)))
712 (defun org-e-odt-format-footnote-ref (n)
713 (setq n
(format "%d" n
))
714 (let ((note-class "footnote")
716 (ref-name (concat "fn" n
)))
717 (org-e-odt-format-tags-simple
718 '("<text:span text:style-name=\"%s\">" .
"</text:span>")
719 (org-e-odt-format-tags-simple
720 '("<text:note-ref text:note-class=\"%s\" text:reference-format=\"%s\" text:ref-name=\"%s\">" .
"</text:note-ref>")
721 n note-class ref-format ref-name
)
724 (defun org-e-odt-element-attributes (element info
)
725 (let* ((raw-attr (org-element-property :attr_odt element
))
726 (raw-attr (and raw-attr
727 (org-trim (mapconcat #'identity raw-attr
" ")))))
728 (unless (and raw-attr
(string-match "\\`(.*)\\'" raw-attr
))
729 (setq raw-attr
(format "(%s)" raw-attr
)))
730 (ignore-errors (read raw-attr
))))
732 (defun org-e-odt-format-object-description (title description
)
733 (concat (and title
(org-e-odt-format-tags
734 '("<svg:title>" .
"</svg:title>")
735 (org-e-odt-encode-plain-text title t
)))
736 (and description
(org-e-odt-format-tags
737 '("<svg:desc>" .
"</svg:desc>")
738 (org-e-odt-encode-plain-text description t
)))))
740 (defun org-e-odt-format-frame (text width height style
&optional
744 (if width
(format " svg:width=\"%0.2fcm\"" width
) "")
745 (if height
(format " svg:height=\"%0.2fcm\"" height
) "")
747 (format " text:anchor-type=\"%s\"" (or anchor-type
"paragraph")))))
748 (org-e-odt-format-tags
749 '("<draw:frame draw:style-name=\"%s\"%s>" .
"</draw:frame>")
750 (concat text
(org-e-odt-format-object-description
751 (get-text-property 0 :title text
)
752 (get-text-property 0 :description text
)))
755 (defun org-e-odt-format-textbox (text width height style
&optional
757 (org-e-odt-format-frame
758 (org-e-odt-format-tags
759 '("<draw:text-box %s>" .
"</draw:text-box>")
760 text
(concat (format " fo:min-height=\"%0.2fcm\"" (or height
.2))
762 (format " fo:min-width=\"%0.2fcm\"" (or width
.2)))))
763 width nil style extra anchor-type
))
765 (defun org-e-odt-merge-frame-params(default-frame-params user-frame-params
)
766 (if (not user-frame-params
) default-frame-params
767 (assert (= (length default-frame-params
) 3))
768 (assert (= (length user-frame-params
) 3))
769 (loop for user-frame-param in user-frame-params
770 for default-frame-param in default-frame-params
771 collect
(or user-frame-param default-frame-param
))))
773 (defun org-e-odt-copy-image-file (path)
774 "Returns the internal name of the file"
775 (let* ((image-type (file-name-extension path
))
776 (media-type (format "image/%s" image-type
))
777 (src-file (expand-file-name
778 path
(file-name-directory org-current-export-file
)))
779 (target-dir "Images/")
781 (format "%s%04d.%s" target-dir
782 (incf org-e-odt-embedded-images-count
) image-type
)))
783 (message "Embedding %s as %s ..."
784 (substring-no-properties path
) target-file
)
786 (when (= 1 org-e-odt-embedded-images-count
)
787 (make-directory target-dir
)
788 (org-e-odt-create-manifest-file-entry "" target-dir
))
790 (copy-file src-file target-file
'overwrite
)
791 (org-e-odt-create-manifest-file-entry media-type target-file
)
794 (defun org-e-odt-do-image-size (probe-method file
&optional dpi anchor-type
)
795 (setq dpi
(or dpi org-e-odt-pixels-per-inch
))
796 (setq anchor-type
(or anchor-type
"paragraph"))
797 (flet ((size-in-cms (size-in-pixels)
798 (flet ((pixels-to-cms (pixels)
799 (let* ((cms-per-inch 2.54)
800 (inches (/ pixels dpi
)))
801 (* cms-per-inch inches
))))
803 (cons (pixels-to-cms (car size-in-pixels
))
804 (pixels-to-cms (cdr size-in-pixels
)))))))
807 (size-in-cms (ignore-errors ; Emacs could be in batch mode
809 (image-size (create-image file
) 'pixels
))))
812 (let ((dim (shell-command-to-string
813 (format "identify -format \"%%w:%%h\" \"%s\"" file
))))
814 (when (string-match "\\([0-9]+\\):\\([0-9]+\\)" dim
)
815 (cons (string-to-number (match-string 1 dim
))
816 (string-to-number (match-string 2 dim
)))))))
818 (cdr (assoc-string anchor-type
819 org-e-odt-default-image-sizes-alist
))))))
821 (defun org-e-odt-image-size-from-file (file &optional user-width
822 user-height scale dpi embed-as
)
823 (unless (file-name-absolute-p file
)
824 (setq file
(expand-file-name
825 file
(file-name-directory org-current-export-file
))))
826 (let* (size width height
)
827 (unless (and user-height user-width
)
828 (loop for probe-method in org-e-odt-image-size-probe-method
830 do
(setq size
(org-e-odt-do-image-size
831 probe-method file dpi embed-as
)))
832 (or size
(error "Cannot determine Image size. Aborting ..."))
833 (setq width
(car size
) height
(cdr size
)))
836 (setq width
(* width scale
) height
(* height scale
)))
837 ((and user-height user-width
)
838 (setq width user-width height user-height
))
840 (setq width
(* user-height
(/ width height
)) height user-height
))
842 (setq height
(* user-width
(/ height width
)) width user-width
))
844 ;; ensure that an embedded image fits comfortably within a page
845 (let ((max-width (car org-e-odt-max-image-size
))
846 (max-height (cdr org-e-odt-max-image-size
)))
847 (when (or (> width max-width
) (> height max-height
))
848 (let* ((scale1 (/ max-width width
))
849 (scale2 (/ max-height height
))
850 (scale (min scale1 scale2
)))
851 (setq width
(* scale width
) height
(* scale height
)))))
852 (cons width height
)))
854 (defun org-e-odt-format-label (element info op
)
856 (case (org-element-type element
)
857 (link (org-export-get-parent-paragraph element info
))
859 ;; get label and caption.
860 (label (org-element-property :name caption-from
))
861 (caption (org-element-property :caption caption-from
))
862 (short-caption (cdr caption
))
863 ;; transcode captions.
864 (caption (and (car caption
) (org-export-secondary-string
865 (car caption
) 'e-odt info
)))
866 (short-caption (and short-caption
(org-export-secondary-string
867 short-caption
'e-odt info
))))
868 (when (or label caption
)
869 (let* ((default-category
871 ((eq (org-element-type element
) 'table
)
873 ((org-e-odt-standalone-image-p element info
)
875 ((member (org-element-type element
)
876 '(latex-environment latex-fragment
))
877 (let ((processing-type (plist-get info
:LaTeX-fragments
)))
879 ((eq processing-type
'dvipng
) "__DvipngImage__")
880 ((eq processing-type
'mathjax
) "__MathFormula__")
881 ((eq processing-type
't
) "__MathFormula__")
882 (t (error "Handle LaTeX:verbatim")))))
883 ((eq (org-element-type element
) 'src-block
)
885 (t (error "Handle enumeration of %S" element
))))
888 ((member (org-element-type element
)
889 '(table latex-environment src-block
))
891 ((org-e-odt-standalone-image-p element info
)
892 'org-e-odt-standalone-image-p
)
893 (t (error "Handle enumeration of %S" element
))))
894 (seqno (org-e-odt-enumerate-element
895 element info predicate
)) ; FIXME
896 ;; handle label props.
897 (label-props (assoc default-category org-e-odt-category-map-alist
))
898 ;; identify opendocument counter
899 (counter (nth 1 label-props
))
900 ;; identify label style
901 (label-style (nth 2 label-props
))
902 ;; grok language setting
903 (en-strings (assoc-default "en" org-e-odt-category-strings
))
904 (lang (plist-get info
:language
)) ; FIXME
905 (lang-strings (assoc-default lang org-e-odt-category-strings
))
906 ;; retrieve localized category sting
907 (pos (- (length org-e-odt-category-map-alist
)
908 (length (memq label-props org-e-odt-category-map-alist
))))
909 (category (or (nth pos lang-strings
) (nth pos en-strings
))))
912 ;; assign an internal label, if user has not provided one
913 (setq label
(or label
(format "%s-%s" default-category seqno
)))
914 (setq label
(org-solidify-link-text label
))
918 (cadr (assoc-string label-style org-e-odt-label-styles t
))
920 (?n .
,(org-e-odt-format-tags-simple
921 '("<text:sequence text:ref-name=\"%s\" text:name=\"%s\" text:formula=\"ooow:%s+1\" style:num-format=\"1\">" .
"</text:sequence>")
922 seqno label counter counter
))
923 (?c .
,(or caption
""))))
927 (setq label
(org-solidify-link-text label
))
928 (let* ((fmt (cddr (assoc-string label-style org-e-odt-label-styles t
)))
931 (org-e-odt-format-tags-simple
932 '("<text:sequence-ref text:reference-format=\"%s\" text:ref-name=\"%s\">"
933 .
"</text:sequence-ref>")
934 (format-spec fmt2
`((?e .
,category
)
935 (?n .
,seqno
))) fmt1 label
)))
936 (t (error "Unknow %S on label" op
)))))))
938 (defun org-e-odt-format-tags-1 (tag text prefix suffix
&rest args
)
941 (concat prefix
(apply 'format
(car tag
) args
) text suffix
943 ((stringp tag
) ; singleton tag
944 (concat prefix
(apply 'format tag args
) text
))))
946 (defun org-e-odt-format-tags (tag text
&rest args
)
947 (apply 'org-e-odt-format-tags-1 tag text
"\n" "\n" args
))
949 (defun org-e-odt-format-tags-simple (tag text
&rest args
)
950 (apply 'org-e-odt-format-tags-1 tag text nil nil args
))
952 (defun org-e-odt-init-outfile ()
953 (unless (executable-find "zip")
954 ;; Not at all OSes ship with zip by default
955 (error "Executable \"zip\" needed for creating OpenDocument files"))
957 (let* ((outdir (make-temp-file
958 (format org-e-odt-tmpdir-prefix
'odt
) t
)) ; FIXME
959 (content-file (expand-file-name "content.xml" outdir
)))
962 (setq org-e-odt-manifest-file-entries nil
963 org-e-odt-embedded-images-count
0
964 org-e-odt-embedded-formulas-count
0
965 org-e-odt-section-count
0
966 org-e-odt-entity-labels-alist nil
967 org-e-odt-list-stack-stashed nil
968 org-e-odt-automatic-styles nil
969 org-e-odt-object-counters nil
970 org-e-odt-entity-counts-plist nil
)
972 ;; let `htmlfontify' know that we are interested in collecting
975 (setq hfy-user-sheet-assoc nil
)
979 (find-file-noselect content-file t
)
982 (defun org-e-odt-save-as-outfile (target opt-plist
)
983 ;; write automatic styles
984 (org-e-odt-write-automatic-styles)
986 ;; update display levels
987 (org-e-odt-update-display-level org-e-odt-display-outline-level
)
990 ;; (when (equal org-lparse-backend 'odt) FIXME
993 ;; (org-e-odt-update-styles-file opt-plist)
995 ;; create mimetype file
996 (let ((mimetype (org-e-odt-write-mimetype-file ;; org-lparse-backend FIXME
998 (org-e-odt-create-manifest-file-entry mimetype
"/" "1.2"))
1000 ;; create a manifest entry for content.xml
1001 (org-e-odt-create-manifest-file-entry "text/xml" "content.xml")
1003 ;; write out the manifest entries before zipping
1004 (org-e-odt-write-manifest-file)
1006 (let ((xml-files '("mimetype" "META-INF/manifest.xml" "content.xml"
1008 (zipdir default-directory
))
1009 (when (or t
(equal org-lparse-backend
'odt
)) ; FIXME
1010 (push "styles.xml" xml-files
))
1011 (message "Switching to directory %s" (expand-file-name zipdir
))
1013 ;; save all xml files
1014 (mapc (lambda (file)
1015 (with-current-buffer
1016 (find-file-noselect (expand-file-name file
) t
)
1017 ;; prettify output if needed
1018 (when org-e-odt-prettify-xml
1019 (indent-region (point-min) (point-max)))
1023 (let* ((target-name (file-name-nondirectory target
))
1024 (target-dir (file-name-directory target
))
1025 (cmds `(("zip" "-mX0" ,target-name
"mimetype")
1026 ("zip" "-rmTq" ,target-name
"."))))
1027 (when (file-exists-p target
)
1028 ;; FIXME: If the file is locked this throws a cryptic error
1029 (delete-file target
))
1031 (let ((coding-system-for-write 'no-conversion
) exitcode err-string
)
1032 (message "Creating odt file...")
1035 (message "Running %s" (mapconcat 'identity cmd
" "))
1037 (with-output-to-string
1039 (apply 'call-process
(car cmd
)
1040 nil standard-output nil
(cdr cmd
)))))
1041 (or (zerop exitcode
)
1042 (ignore (message "%s" err-string
))
1043 (error "Unable to create odt file (%S)" exitcode
)))
1046 ;; move the file from outdir to target-dir
1047 (rename-file target-name target-dir
)
1049 ;; kill all xml buffers
1050 (mapc (lambda (file)
1052 (find-file-noselect (expand-file-name file zipdir
) t
)))
1055 (delete-directory zipdir
)))
1056 (message "Created %s" target
)
1057 (set-buffer (find-file-noselect target t
)))
1060 (defun org-e-odt-create-manifest-file-entry (&rest args
)
1061 (push args org-e-odt-manifest-file-entries
))
1063 (defun org-e-odt-write-manifest-file ()
1064 (make-directory "META-INF")
1065 (let ((manifest-file (expand-file-name "META-INF/manifest.xml")))
1066 (with-current-buffer
1067 (find-file-noselect manifest-file t
)
1069 "<?xml version=\"1.0\" encoding=\"UTF-8\"?>
1070 <manifest:manifest xmlns:manifest=\"urn:oasis:names:tc:opendocument:xmlns:manifest:1.0\" manifest:version=\"1.2\">\n")
1072 (lambda (file-entry)
1073 (let* ((version (nth 2 file-entry
))
1075 (format " manifest:version=\"%s\"" version
)
1078 (format org-e-odt-manifest-file-entry-tag
1079 (nth 0 file-entry
) (nth 1 file-entry
) extra
))))
1080 org-e-odt-manifest-file-entries
)
1081 (insert "\n</manifest:manifest>"))))
1083 (defun org-e-odt-update-meta-file (info) ; FIXME opt-plist
1084 (let ((title (org-export-secondary-string
1085 (plist-get info
:title
) 'e-odt info
))
1086 (author (or (let ((auth (plist-get info
:author
)))
1087 (and auth
(org-export-secondary-string
1088 auth
'e-odt info
))) ""))
1089 (date (org-e-odt-format-date (plist-get info
:date
)))
1090 (email (plist-get info
:email
))
1091 (keywords (plist-get info
:keywords
))
1092 (description (plist-get info
:description
)))
1095 "<?xml version=\"1.0\" encoding=\"UTF-8\"?>
1096 <office:document-meta
1097 xmlns:office=\"urn:oasis:names:tc:opendocument:xmlns:office:1.0\"
1098 xmlns:xlink=\"http://www.w3.org/1999/xlink\"
1099 xmlns:dc=\"http://purl.org/dc/elements/1.1/\"
1100 xmlns:meta=\"urn:oasis:names:tc:opendocument:xmlns:meta:1.0\"
1101 xmlns:ooo=\"http://openoffice.org/2004/office\"
1102 office:version=\"1.2\">
1104 (org-e-odt-format-author author
) "\n"
1105 (format "<meta:initial-creator>%s</meta:initial-creator>\n" author
)
1106 (format "<dc:date>%s</dc:date>\n" date
)
1107 (format "<meta:creation-date>%s</meta:creation-date>\n" date
)
1108 (format "<meta:generator>%s</meta:generator>\n"
1109 (when org-export-creator-info
1110 (format "Org-%s/Emacs-%s"
1111 org-version emacs-version
)))
1112 (format "<meta:keyword>%s</meta:keyword>\n" keywords
)
1113 (format "<dc:subject>%s</dc:subject>\n" description
)
1114 (format "<dc:title>%s</dc:title>\n" title
)
1116 " </office:meta>\n" "</office:document-meta>")
1117 nil
(expand-file-name "meta.xml")))
1119 ;; create a manifest entry for meta.xml
1120 (org-e-odt-create-manifest-file-entry "text/xml" "meta.xml"))
1122 (defun org-e-odt-update-styles-file (info)
1123 ;; write styles file
1124 (let ((styles-file (plist-get info
:odt-styles-file
)))
1125 (org-e-odt-copy-styles-file (and styles-file
1126 (read (org-trim styles-file
))))
1128 ;; FIXME: Who is opening an empty styles.xml before this point?
1129 (with-current-buffer
1130 (find-file-noselect (expand-file-name "styles.xml") t
)
1131 (revert-buffer t t
)))
1133 ;; Write custom styles for source blocks
1134 (org-e-odt-insert-custom-styles-for-srcblocks
1137 (format " %s\n" (cddr style
)))
1138 hfy-user-sheet-assoc
"")))
1140 (defun org-e-odt-write-mimetype-file (format)
1141 ;; create mimetype file
1144 (odt "application/vnd.oasis.opendocument.text")
1145 (odf "application/vnd.oasis.opendocument.formula")
1146 (t (error "Unknown OpenDocument backend %S" org-lparse-backend
)))))
1147 (write-region mimetype nil
(expand-file-name "mimetype"))
1150 (declare-function org-create-math-formula
"org"
1151 (latex-frag &optional mathml-file
))
1153 (defun org-e-odt-get (what &optional opt-plist
)
1155 (EXPORT-DIR (org-export-directory :html opt-plist
))
1156 (TABLE-FIRST-COLUMN-AS-LABELS nil
)
1157 (CODING-SYSTEM-FOR-WRITE 'utf-8
)
1158 (CODING-SYSTEM-FOR-SAVE 'utf-8
)
1159 (t (error "Unknown property: %s" what
))))
1161 (defun org-e-odt-do-preprocess-latex-fragments ()
1162 "Convert LaTeX fragments to images."
1163 (let* ((latex-frag-opt (plist-get org-lparse-opt-plist
:LaTeX-fragments
))
1164 (latex-frag-opt ; massage the options
1165 (or (and (member latex-frag-opt
'(mathjax t
))
1166 (not (and (fboundp 'org-format-latex-mathml-available-p
)
1167 (org-format-latex-mathml-available-p)))
1168 (prog1 org-lparse-latex-fragment-fallback
1171 "LaTeX to MathML converter not available. "
1172 (format "Using %S instead."
1173 org-lparse-latex-fragment-fallback
)))))
1175 cache-dir display-msg
)
1177 ((eq latex-frag-opt
'dvipng
)
1178 (setq cache-dir
"ltxpng/")
1179 (setq display-msg
"Creating LaTeX image %s"))
1180 ((member latex-frag-opt
'(mathjax t
))
1181 (setq latex-frag-opt
'mathml
)
1182 (setq cache-dir
"ltxmathml/")
1183 (setq display-msg
"Creating MathML formula %s")))
1184 (when (and org-current-export-file
)
1186 (concat cache-dir
(file-name-sans-extension
1187 (file-name-nondirectory org-current-export-file
)))
1188 org-current-export-dir nil display-msg
1189 nil nil latex-frag-opt
))))
1191 (eval-after-load 'org-odt
1192 '(ad-deactivate 'org-format-latex-as-mathml
))
1196 ;; (defadvice org-format-latex-as-mathml ; FIXME
1197 ;; (after org-e-odt-protect-latex-fragment activate)
1198 ;; "Encode LaTeX fragment as XML.
1199 ;; Do this when translation to MathML fails."
1200 ;; (when (or (not (> (length ad-return-value) 0))
1201 ;; (get-text-property 0 'org-protected ad-return-value))
1202 ;; (setq ad-return-value
1203 ;; (org-propertize (org-e-odt-encode-plain-text (ad-get-arg 0))
1204 ;; 'org-protected t))))
1206 (defun org-e-odt-zip-extract-one (archive member
&optional target
)
1208 (let* ((target (or target default-directory
))
1209 (archive (expand-file-name archive
))
1210 (archive-zip-extract
1211 (list "unzip" "-qq" "-o" "-d" target
))
1212 exit-code command-output
)
1213 (setq command-output
1215 (setq exit-code
(archive-zip-extract archive member
))
1217 (unless (zerop exit-code
)
1218 (message command-output
)
1219 (error "Extraction failed"))))
1221 (defun org-e-odt-zip-extract (archive members
&optional target
)
1222 (when (atom members
) (setq members
(list members
)))
1223 (mapc (lambda (member)
1224 (org-e-odt-zip-extract-one archive member target
))
1227 (defun org-e-odt-copy-styles-file (&optional styles-file
)
1228 ;; Non-availability of styles.xml is not a critical error. For now
1229 ;; throw an error purely for aesthetic reasons.
1230 (setq styles-file
(or styles-file
1231 org-e-odt-styles-file
1232 (expand-file-name "OrgOdtStyles.xml"
1233 org-e-odt-styles-dir
)
1234 (error "org-e-odt: Missing styles file?")))
1236 ((listp styles-file
)
1237 (let ((archive (nth 0 styles-file
))
1238 (members (nth 1 styles-file
)))
1239 (org-e-odt-zip-extract archive members
)
1242 (when (org-file-image-p member
)
1243 (let* ((image-type (file-name-extension member
))
1244 (media-type (format "image/%s" image-type
)))
1245 (org-e-odt-create-manifest-file-entry media-type member
))))
1247 ((and (stringp styles-file
) (file-exists-p styles-file
))
1248 (let ((styles-file-type (file-name-extension styles-file
)))
1250 ((string= styles-file-type
"xml")
1251 (copy-file styles-file
(expand-file-name "styles.xml") t
))
1252 ((member styles-file-type
'("odt" "ott"))
1253 (org-e-odt-zip-extract styles-file
"styles.xml")))))
1255 (error (format "Invalid specification of styles.xml file: %S"
1256 org-e-odt-styles-file
))))
1258 ;; create a manifest entry for styles.xml
1259 (org-e-odt-create-manifest-file-entry "text/xml" "styles.xml"))
1261 (defun org-e-odt-configure-outline-numbering ()
1262 "Outline numbering is retained only upto LEVEL.
1263 To disable outline numbering pass a LEVEL of 0."
1264 (goto-char (point-min))
1266 "<text:outline-level-style\\([^>]*\\)text:level=\"\\([^\"]*\\)\"\\([^>]*\\)>")
1268 "<text:outline-level-style\\1text:level=\"\\2\" style:num-format=\"\">"))
1269 (while (re-search-forward regex nil t
)
1270 (unless (let ((sec-num (plist-get info
:section-numbers
))
1271 (level (string-to-number (match-string 2))))
1272 (if (wholenump sec-num
) (<= level sec-num
) sec-num
))
1273 (replace-match replacement t nil
))))
1277 (defun org-export-as-odf (latex-frag &optional odf-file
)
1278 "Export LATEX-FRAG as OpenDocument formula file ODF-FILE.
1279 Use `org-create-math-formula' to convert LATEX-FRAG first to
1280 MathML. When invoked as an interactive command, use
1281 `org-latex-regexps' to infer LATEX-FRAG from currently active
1282 region. If no LaTeX fragments are found, prompt for it. Push
1283 MathML source to kill ring, if `org-export-copy-to-kill-ring' is
1287 (setq frag
(and (setq frag
(and (region-active-p)
1288 (buffer-substring (region-beginning)
1290 (loop for e in org-latex-regexps
1291 thereis
(when (string-match (nth 1 e
) frag
)
1292 (match-string (nth 2 e
) frag
)))))
1293 (read-string "LaTeX Fragment: " frag nil frag
))
1294 ,(let ((odf-filename (expand-file-name
1296 (file-name-sans-extension
1297 (or (file-name-nondirectory buffer-file-name
)))
1299 (file-name-directory buffer-file-name
))))
1300 (read-file-name "ODF filename: " nil odf-filename nil
1301 (file-name-nondirectory odf-filename
)))))
1302 (let* ((org-lparse-backend 'odf
)
1303 org-lparse-opt-plist
1304 (filename (or odf-file
1307 (file-name-sans-extension
1308 (or (file-name-nondirectory buffer-file-name
)))
1310 (file-name-directory buffer-file-name
))))
1311 (buffer (find-file-noselect (org-e-odt-init-outfile filename
)))
1312 (coding-system-for-write 'utf-8
)
1313 (save-buffer-coding-system 'utf-8
))
1315 (set-buffer-file-coding-system coding-system-for-write
)
1316 (let ((mathml (org-create-math-formula latex-frag
)))
1317 (unless mathml
(error "No Math formula created"))
1319 (or (org-export-push-to-kill-ring
1320 (upcase (symbol-name org-lparse-backend
)))
1321 (message "Exporting... done")))
1322 (org-e-odt-save-as-outfile filename nil
; FIXME
1326 (defun org-export-as-odf-and-open ()
1327 "Export LaTeX fragment as OpenDocument formula and immediately open it.
1328 Use `org-export-as-odf' to read LaTeX fragment and OpenDocument
1331 (org-lparse-and-open
1332 nil nil nil
(call-interactively 'org-export-as-odf
)))
1337 ;;; Driver Starts here
1340 (require 'format-spec
)
1341 (eval-when-compile (require 'cl
) (require 'table
))
1347 ;; FIXME: it already exists in org-e-odt.el
1348 ;;; Function Declarations
1350 (declare-function org-element-property
"org-element" (property element
))
1351 (declare-function org-element-normalize-string
"org-element" (s))
1352 (declare-function org-element-parse-secondary-string
1353 "org-element" (string restriction
&optional buffer
))
1354 (defvar org-element-string-restrictions
)
1355 (defvar org-element-object-restrictions
)
1357 (declare-function org-export-clean-table
"org-export" (table specialp
))
1358 (declare-function org-export-data
"org-export" (data backend info
))
1359 (declare-function org-export-directory
"org-export" (type plist
))
1360 (declare-function org-export-expand-macro
"org-export" (macro info
))
1361 (declare-function org-export-first-sibling-p
"org-export" (headline info
))
1362 (declare-function org-export-footnote-first-reference-p
"org-export"
1363 (footnote-reference info
))
1364 (declare-function org-export-get-coderef-format
"org-export" (path desc
))
1365 (declare-function org-export-get-footnote-definition
"org-export"
1366 (footnote-reference info
))
1367 (declare-function org-export-get-footnote-number
"org-export" (footnote info
))
1368 (declare-function org-export-get-previous-element
"org-export" (blob info
))
1369 (declare-function org-export-get-relative-level
"org-export" (headline info
))
1370 (declare-function org-export-handle-code
1371 "org-export" (element info
&optional num-fmt ref-fmt delayed
))
1372 (declare-function org-export-included-file
"org-export" (keyword backend info
))
1373 (declare-function org-export-inline-image-p
"org-export"
1374 (link &optional extensions
))
1375 (declare-function org-export-last-sibling-p
"org-export" (headline info
))
1376 (declare-function org-export-low-level-p
"org-export" (headline info
))
1377 (declare-function org-export-output-file-name
1378 "org-export" (extension &optional subtreep pub-dir
))
1379 (declare-function org-export-resolve-coderef
"org-export" (ref info
))
1380 (declare-function org-export-resolve-fuzzy-link
"org-export" (link info
))
1381 (declare-function org-export-secondary-string
"org-export"
1382 (secondary backend info
))
1383 (declare-function org-export-solidify-link-text
"org-export" (s))
1384 (declare-function org-export-table-format-info
"org-export" (table))
1386 org-export-to-buffer
"org-export"
1387 (backend buffer
&optional subtreep visible-only body-only ext-plist
))
1389 org-export-to-file
"org-export"
1390 (backend file
&optional subtreep visible-only body-only ext-plist
))
1392 (declare-function org-id-find-id-file
"org-id" (id))
1393 (declare-function htmlize-region
"ext:htmlize" (beg end
))
1394 (declare-function org-pop-to-buffer-same-window
1395 "org-compat" (&optional buffer-or-name norecord label
))
1401 (declare-function hfy-face-to-style
"htmlfontify" (fn))
1402 (declare-function hfy-face-or-def-to-name
"htmlfontify" (fn))
1403 (declare-function archive-zip-extract
"arc-mode.el" (archive name
))
1405 ;;; Internal Variables
1407 ;;;; ODT Internal Variables
1409 (defconst org-e-odt-lib-dir
1410 (file-name-directory load-file-name
)
1411 "Location of ODT exporter.
1412 Use this to infer values of `org-e-odt-styles-dir' and
1413 `org-e-odt-schema-dir'.")
1415 (defvar org-e-odt-data-dir
1416 (expand-file-name "../etc/" org-e-odt-lib-dir
)
1417 "Data directory for ODT exporter.
1418 Use this to infer values of `org-e-odt-styles-dir' and
1419 `org-e-odt-schema-dir'.")
1421 (defconst org-e-odt-special-string-regexps
1422 '(("\\\\-" .
"­\\1") ; shy
1423 ("---\\([^-]\\)" .
"—\\1") ; mdash
1424 ("--\\([^-]\\)" .
"–\\1") ; ndash
1425 ("\\.\\.\\." .
"…")) ; hellip
1426 "Regular expressions for special string conversion.")
1428 (defconst org-e-odt-schema-dir-list
1430 (and org-e-odt-data-dir
1431 (expand-file-name "./schema/" org-e-odt-data-dir
)) ; bail out
1433 (and (boundp 'org-e-odt-data-dir
) org-e-odt-data-dir
; see make install
1434 (expand-file-name "./schema/" org-e-odt-data-dir
)))
1435 (expand-file-name "../contrib/odt/etc/schema/" org-e-odt-lib-dir
) ; git
1437 "List of directories to search for OpenDocument schema files.
1438 Use this list to set the default value of
1439 `org-e-odt-schema-dir'. The entries in this list are
1440 populated heuristically based on the values of `org-e-odt-lib-dir'
1441 and `org-e-odt-data-dir'.")
1444 (defconst org-e-odt-styles-dir-list
1446 (and org-e-odt-data-dir
1447 (expand-file-name "./styles/" org-e-odt-data-dir
)) ; bail out
1449 (and (boundp 'org-e-odt-data-dir
) org-e-odt-data-dir
; see make install
1450 (expand-file-name "./styles/" org-e-odt-data-dir
)))
1451 (expand-file-name "../etc/styles/" org-e-odt-lib-dir
) ; git
1452 (expand-file-name "./etc/styles/" org-e-odt-lib-dir
) ; elpa
1453 (expand-file-name "./org/" data-directory
) ; system
1455 "List of directories to search for OpenDocument styles files.
1456 See `org-e-odt-styles-dir'. The entries in this list are populated
1457 heuristically based on the values of `org-e-odt-lib-dir' and
1458 `org-e-odt-data-dir'.")
1460 (defconst org-e-odt-styles-dir
1463 (message "Debug (org-e-odt): Searching for OpenDocument styles files...")
1464 (mapc (lambda (styles-dir)
1466 (message "Debug (org-e-odt): Trying %s..." styles-dir
)
1467 (when (and (file-readable-p
1469 "OrgOdtContentTemplate.xml" styles-dir
))
1472 "OrgOdtStyles.xml" styles-dir
)))
1473 (message "Debug (org-e-odt): Using styles under %s"
1475 (throw 'styles-dir styles-dir
))))
1476 org-e-odt-styles-dir-list
)
1479 (error "Error (org-e-odt): Cannot find factory styles files. Aborting."))
1481 "Directory that holds auxiliary XML files used by the ODT exporter.
1483 This directory contains the following XML files -
1484 \"OrgOdtStyles.xml\" and \"OrgOdtContentTemplate.xml\". These
1485 XML files are used as the default values of
1486 `org-e-odt-styles-file' and
1487 `org-e-odt-content-template-file'.
1489 The default value of this variable varies depending on the
1490 version of org in use and is initialized from
1491 `org-e-odt-styles-dir-list'. Note that the user could be using org
1492 from one of: org's own private git repository, GNU ELPA tar or
1495 (defconst org-e-odt-tmpdir-prefix
"%s-")
1496 (defconst org-e-odt-bookmark-prefix
"OrgXref.")
1498 (defconst org-e-odt-manifest-file-entry-tag
1500 <manifest:file-entry manifest:media-type=\"%s\" manifest:full-path=\"%s\"%s/>")
1504 (defvar org-lparse-dyn-first-heading-pos
) ; let bound during org-do-lparse
1506 (defvar org-e-odt-suppress-xref nil
)
1507 (defvar org-e-odt-file-extensions
1508 '(("odt" .
"OpenDocument Text")
1509 ("ott" .
"OpenDocument Text Template")
1510 ("odm" .
"OpenDocument Master Document")
1511 ("ods" .
"OpenDocument Spreadsheet")
1512 ("ots" .
"OpenDocument Spreadsheet Template")
1513 ("odg" .
"OpenDocument Drawing (Graphics)")
1514 ("otg" .
"OpenDocument Drawing Template")
1515 ("odp" .
"OpenDocument Presentation")
1516 ("otp" .
"OpenDocument Presentation Template")
1517 ("odi" .
"OpenDocument Image")
1518 ("odf" .
"OpenDocument Formula")
1519 ("odc" .
"OpenDocument Chart")))
1521 (defvar org-e-odt-default-org-styles-alist
1522 '((paragraph .
((default .
"Text_20_body")
1523 (fixedwidth .
"OrgFixedWidthBlock")
1524 (verse .
"OrgVerse")
1525 (quote .
"Quotations")
1526 (blockquote .
"Quotations")
1527 (center .
"OrgCenter")
1529 (right .
"OrgRight")
1530 (title .
"OrgTitle")
1531 (subtitle .
"OrgSubtitle")
1532 (footnote .
"Footnote")
1533 (src .
"OrgSrcBlock")
1534 (illustration .
"Illustration")
1536 (listing .
"Listing")
1537 (definition-term .
"Text_20_body_20_bold")
1538 (horizontal-line .
"Horizontal_20_Line")))
1539 (character .
((bold .
"Bold")
1540 (emphasis .
"Emphasis")
1542 (verbatim .
"OrgCode")
1543 (strike .
"Strikethrough")
1544 (underline .
"Underline")
1545 (subscript .
"OrgSubscript")
1546 (superscript .
"OrgSuperscript")))
1547 (list .
((ordered .
"OrgNumberedList")
1548 (unordered .
"OrgBulletedList")
1549 (descriptive .
"OrgDescriptionList"))))
1550 "Default styles for various entities.")
1552 (defvar org-e-odt-org-styles-alist org-e-odt-default-org-styles-alist
)
1555 ;;;_. control callbacks
1556 ;;;_ , document body
1558 (defvar org-lparse-body-only
) ; let bound during org-do-lparse
1559 (defvar org-lparse-opt-plist
) ; bound during org-do-lparse
1560 (defvar org-lparse-list-stack
) ; dynamically bound in org-do-lparse
1561 (defvar org-e-odt-list-stack-stashed
)
1562 (defvar org-lparse-table-ncols
)
1563 (defvar org-e-odt-table-rowgrp-open
)
1564 (defvar org-e-odt-table-rownum
)
1565 (defvar org-e-odt-table-cur-rowgrp-is-hdr
)
1566 (defvar org-lparse-table-is-styled
)
1567 (defvar org-lparse-table-rowgrp-info
)
1568 (defvar org-lparse-table-colalign-vector
)
1570 (defvar org-e-odt-table-style nil
1571 "Table style specified by \"#+ATTR_ODT: <style-name>\" line.
1572 This is set during `org-e-odt-begin-table'.")
1574 (defvar org-e-odt-table-style-spec nil
1575 "Entry for `org-e-odt-table-style' in `org-e-odt-table-styles'.")
1578 (defvar org-e-odt-table-style-format
1580 <style:style style:name=\"%s\" style:family=\"table\">
1581 <style:table-properties style:rel-width=\"%d%%\" fo:margin-top=\"0cm\" fo:margin-bottom=\"0.20cm\" table:align=\"center\"/>
1584 "Template for auto-generated Table styles.")
1586 (defvar org-e-odt-automatic-styles
'()
1587 "Registry of automatic styles for various OBJECT-TYPEs.
1588 The variable has the following form:
1590 \(\(OBJECT-NAME-A.1 OBJECT-PROPS-A.1\)
1591 \(OBJECT-NAME-A.2 OBJECT-PROPS-A.2\) ...\)\)
1593 \(\(OBJECT-NAME-B.1 OBJECT-PROPS-B.1\)
1594 \(OBJECT-NAME-B.2 OBJECT-PROPS-B.2\) ...\)\)
1597 OBJECT-TYPEs could be \"Section\", \"Table\", \"Figure\" etc.
1598 OBJECT-PROPS is (typically) a plist created by passing
1599 \"#+ATTR_ODT: \" option to `org-e-odt-parse-block-attributes'.
1601 Use `org-e-odt-add-automatic-style' to add update this variable.'")
1603 (defvar org-e-odt-object-counters nil
1604 "Running counters for various OBJECT-TYPEs.
1605 Use this to generate automatic names and style-names. See
1606 `org-e-odt-add-automatic-style'.")
1608 (defvar org-e-odt-table-indentedp nil
)
1609 (defvar org-lparse-table-colalign-info
)
1610 (defvar org-lparse-link-description-is-image nil
)
1613 (defvar org-src-block-paragraph-format
1614 "<style:style style:name=\"OrgSrcBlock\" style:family=\"paragraph\" style:parent-style-name=\"Preformatted_20_Text\">
1615 <style:paragraph-properties fo:background-color=\"%s\" fo:padding=\"0.049cm\" fo:border=\"0.51pt solid #000000\" style:shadow=\"none\">
1616 <style:background-image/>
1617 </style:paragraph-properties>
1618 <style:text-properties fo:color=\"%s\"/>
1620 "Custom paragraph style for colorized source and example blocks.
1621 This style is much the same as that of \"OrgFixedWidthBlock\"
1622 except that the foreground and background colors are set
1623 according to the default face identified by the `htmlfontify'.")
1625 (defvar hfy-optimisations
)
1626 (defvar org-e-odt-embedded-formulas-count
0)
1627 (defvar org-e-odt-entity-frame-styles
1628 '(("As-CharImage" "__Figure__" ("OrgInlineImage" nil
"as-char"))
1629 ("ParagraphImage" "__Figure__" ("OrgDisplayImage" nil
"paragraph"))
1630 ("PageImage" "__Figure__" ("OrgPageImage" nil
"page"))
1631 ("CaptionedAs-CharImage" "__Figure__"
1632 ("OrgCaptionedImage"
1633 " style:rel-width=\"100%\" style:rel-height=\"scale\"" "paragraph")
1634 ("OrgInlineImage" nil
"as-char"))
1635 ("CaptionedParagraphImage" "__Figure__"
1636 ("OrgCaptionedImage"
1637 " style:rel-width=\"100%\" style:rel-height=\"scale\"" "paragraph")
1638 ("OrgImageCaptionFrame" nil
"paragraph"))
1639 ("CaptionedPageImage" "__Figure__"
1640 ("OrgCaptionedImage"
1641 " style:rel-width=\"100%\" style:rel-height=\"scale\"" "paragraph")
1642 ("OrgPageImageCaptionFrame" nil
"page"))
1643 ("InlineFormula" "__MathFormula__" ("OrgInlineFormula" nil
"as-char"))
1644 ("DisplayFormula" "__MathFormula__" ("OrgDisplayFormula" nil
"as-char"))
1645 ("CaptionedDisplayFormula" "__MathFormula__"
1646 ("OrgCaptionedFormula" nil
"paragraph")
1647 ("OrgFormulaCaptionFrame" nil
"as-char"))))
1649 (defvar org-e-odt-embedded-images-count
0)
1651 (defvar org-e-odt-image-size-probe-method
1652 (append (and (executable-find "identify") '(imagemagick)) ; See Bug#10675
1654 "Ordered list of methods for determining image sizes.")
1656 (defvar org-e-odt-default-image-sizes-alist
1657 '(("as-char" .
(5 .
0.4))
1658 ("paragraph" .
(5 .
5)))
1659 "Hardcoded image dimensions one for each of the anchor
1662 ;; A4 page size is 21.0 by 29.7 cms
1663 ;; The default page settings has 2cm margin on each of the sides. So
1664 ;; the effective text area is 17.0 by 25.7 cm
1665 (defvar org-e-odt-max-image-size
'(17.0 .
20.0)
1666 "Limiting dimensions for an embedded image.")
1668 (defvar org-e-odt-entity-labels-alist nil
1669 "Associate Labels with the Labeled entities.
1670 Each element of the alist is of the form (LABEL-NAME
1671 CATEGORY-NAME SEQNO LABEL-STYLE-NAME). LABEL-NAME is same as
1672 that specified by \"#+LABEL: ...\" line. CATEGORY-NAME is the
1673 type of the entity that LABEL-NAME is attached to. CATEGORY-NAME
1674 can be one of \"Table\", \"Figure\" or \"Equation\". SEQNO is
1675 the unique number assigned to the referenced entity on a
1676 per-CATEGORY basis. It is generated sequentially and is 1-based.
1677 LABEL-STYLE-NAME is a key `org-e-odt-label-styles'.
1679 See `org-e-odt-add-label-definition' and
1680 `org-e-odt-fixup-label-references'.")
1682 (defvar org-e-odt-entity-counts-plist nil
1683 "Plist of running counters of SEQNOs for each of the CATEGORY-NAMEs.
1684 See `org-e-odt-entity-labels-alist' for known CATEGORY-NAMEs.")
1686 (defvar org-e-odt-label-styles
1687 '(("math-formula" "%c" "text" "(%n)")
1688 ("math-label" "(%n)" "text" "(%n)")
1689 ("category-and-value" "%e %n: %c" "category-and-value" "%e %n")
1690 ("value" "%e %n: %c" "value" "%n"))
1691 "Specify how labels are applied and referenced.
1692 This is an alist where each element is of the
1693 form (LABEL-STYLE-NAME LABEL-ATTACH-FMT LABEL-REF-MODE
1696 LABEL-ATTACH-FMT controls how labels and captions are attached to
1697 an entity. It may contain following specifiers - %e, %n and %c.
1698 %e is replaced with the CATEGORY-NAME. %n is replaced with
1699 \"<text:sequence ...> SEQNO </text:sequence>\". %c is replaced
1700 with CAPTION. See `org-e-odt-format-label-definition'.
1702 LABEL-REF-MODE and LABEL-REF-FMT controls how label references
1703 are generated. The following XML is generated for a label
1704 reference - \"<text:sequence-ref
1705 text:reference-format=\"LABEL-REF-MODE\" ...> LABEL-REF-FMT
1706 </text:sequence-ref>\". LABEL-REF-FMT may contain following
1707 specifiers - %e and %n. %e is replaced with the CATEGORY-NAME.
1708 %n is replaced with SEQNO. See
1709 `org-e-odt-format-label-reference'.")
1711 (defcustom org-e-odt-category-strings
1712 '(("en" "Table" "Figure" "Equation" "Equation" "Listing"))
1713 "Specify category strings for various captionable entities.
1714 Captionable entity can be one of a Table, an Embedded Image, a
1715 LaTeX fragment (generated with dvipng) or a Math Formula.
1717 For example, when `org-export-default-language' is \"en\", an
1718 embedded image will be captioned as \"Figure 1: Orgmode Logo\".
1719 If you want the images to be captioned instead as \"Illustration
1720 1: Orgmode Logo\", then modify the entry for \"en\" as shown
1723 \(setq org-e-odt-category-strings
1724 '\(\(\"en\" \"Table\" \"Illustration\"
1725 \"Equation\" \"Equation\"\)\)\)"
1726 :group
'org-export-e-odt
1728 :type
'(repeat (list (string :tag
"Language tag")
1729 (choice :tag
"Table"
1730 (const :tag
"Use Default" nil
)
1731 (string :tag
"Category string"))
1732 (choice :tag
"Figure"
1733 (const :tag
"Use Default" nil
)
1734 (string :tag
"Category string"))
1735 (choice :tag
"Math Formula"
1736 (const :tag
"Use Default" nil
)
1737 (string :tag
"Category string"))
1738 (choice :tag
"Dvipng Image"
1739 (const :tag
"Use Default" nil
)
1740 (string :tag
"Category string"))
1741 (choice :tag
"Listing"
1742 (const :tag
"Use Default" nil
)
1743 (string :tag
"Category string")))))
1745 (defvar org-e-odt-category-map-alist
1746 '(("__Table__" "Table" "value")
1747 ("__Figure__" "Illustration" "value")
1748 ("__MathFormula__" "Text" "math-formula")
1749 ("__DvipngImage__" "Equation" "value")
1750 ("__Listing__" "Listing" "value")
1751 ;; ("__Table__" "Table" "category-and-value")
1752 ;; ("__Figure__" "Figure" "category-and-value")
1753 ;; ("__DvipngImage__" "Equation" "category-and-value")
1755 "Map a CATEGORY-HANDLE to OD-VARIABLE and LABEL-STYLE.
1756 This is a list where each entry is of the form \\(CATEGORY-HANDLE
1757 OD-VARIABLE LABEL-STYLE\\). CATEGORY_HANDLE identifies the
1758 captionable entity in question. OD-VARIABLE is the OpenDocument
1759 sequence counter associated with the entity. These counters are
1761 \"<text:sequence-decls>...</text:sequence-decls>\" block of
1762 `org-e-odt-content-template-file'. LABEL-STYLE is a key
1763 into `org-e-odt-label-styles' and specifies how a given entity
1764 should be captioned and referenced.
1766 The position of a CATEGORY-HANDLE in this list is used as an
1767 index in to per-language entry for
1768 `org-e-odt-category-strings' to retrieve a CATEGORY-NAME.
1769 This CATEGORY-NAME is then used for qualifying the user-specified
1770 captions on export.")
1772 (defvar org-e-odt-manifest-file-entries nil
)
1773 (defvar hfy-user-sheet-assoc
) ; bound during org-do-lparse
1774 (defvar org-lparse-latex-fragment-fallback
) ; set by org-do-lparse
1777 ;;;; HTML Internal Variables
1779 (defvar org-e-odt-option-alist
1781 ;; (:agenda-style nil nil org-agenda-export-html-style)
1782 ;; (:convert-org-links nil nil org-e-odt-link-org-files-as-html)
1783 ;; ;; FIXME Use (org-xml-encode-org-text-skip-links s) ??
1784 ;; ;; (:expand-quoted-html nil "@" org-e-odt-expand)
1785 ;; (:inline-images nil nil org-e-odt-inline-images)
1786 ;; ;; (:link-home nil nil org-e-odt-link-home) FIXME
1787 ;; ;; (:link-up nil nil org-e-odt-link-up) FIXME
1788 ;; (:style nil nil org-e-odt-style)
1789 ;; (:style-extra nil nil org-e-odt-style-extra)
1790 ;; (:style-include-default nil nil org-e-odt-style-include-default)
1791 ;; (:style-include-scripts nil nil org-e-odt-style-include-scripts)
1792 ;; ;; (:timestamp nil nil org-e-odt-with-timestamp)
1793 ;; (:html-extension nil nil org-e-odt-extension)
1794 ;; (:html-postamble nil nil org-e-odt-postamble)
1795 ;; (:html-preamble nil nil org-e-odt-preamble)
1796 ;; (:html-table-tag nil nil org-e-odt-table-tag)
1797 ;; (:xml-declaration nil nil org-e-odt-xml-declaration)
1798 (:odt-styles-file
"ODT_STYLES_FILE" nil nil t
)
1799 (:LaTeX-fragments nil
"LaTeX" org-export-with-LaTeX-fragments
))
1800 "Alist between export properties and ways to set them.
1802 The car of the alist is the property name, and the cdr is a list
1803 like \(KEYWORD OPTION DEFAULT BEHAVIOUR\) where:
1805 KEYWORD is a string representing a buffer keyword, or nil.
1806 OPTION is a string that could be found in an #+OPTIONS: line.
1807 DEFAULT is the default value for the property.
1808 BEHAVIOUR determine how Org should handle multiple keywords for
1809 the same property. It is a symbol among:
1810 nil Keep old value and discard the new one.
1811 t Replace old value with the new one.
1812 `space' Concatenate the values, separating them with a space.
1813 `newline' Concatenate the values, separating them with
1815 `split' Split values at white spaces, and cons them to the
1818 KEYWORD and OPTION have precedence over DEFAULT.
1820 All these properties should be back-end agnostic. For back-end
1821 specific properties, define a similar variable named
1822 `org-BACKEND-option-alist', replacing BACKEND with the name of
1823 the appropriate back-end. You can also redefine properties
1824 there, as they have precedence over these.")
1826 (defvar html-table-tag nil
) ; dynamically scoped into this.
1828 ;; FIXME: it already exists in org-e-odt.el
1829 (defconst org-e-odt-cvt-link-fn
1831 "Function to convert link URLs to exportable URLs.
1832 Takes two arguments, TYPE and PATH.
1833 Returns exportable url as (TYPE PATH), or nil to signal that it
1834 didn't handle this case.
1835 Intended to be locally bound around a call to `org-export-as-html'." )
1840 (defvar org-e-odt-format-table-no-css
)
1841 (defvar htmlize-buffer-places
) ; from htmlize.el
1842 (defvar body-only
) ; dynamically scoped into this.
1844 (defvar org-e-odt-table-rowgrp-open
)
1845 (defvar org-e-odt-table-rownum
)
1846 (defvar org-e-odt-table-cur-rowgrp-is-hdr
)
1847 (defvar org-lparse-table-is-styled
)
1850 (defvar org-e-odt-headline-formatter
1851 (lambda (level snumber todo todo-type priority
1852 title tags target extra-targets extra-class
)
1853 (concat snumber
" " title
)))
1857 ;;; User Configuration Variables
1859 (defgroup org-export-e-odt nil
1860 "Options for exporting Org mode files to ODT."
1861 :tag
"Org Export ODT"
1864 (defcustom org-e-odt-protect-char-alist
1868 "Alist of characters to be converted by `org-e-html-protect'."
1869 :group
'org-export-e-html
1870 :type
'(repeat (cons (string :tag
"Character")
1871 (string :tag
"ODT equivalent"))))
1872 (defcustom org-e-odt-schema-dir
1875 (message "Debug (org-e-odt): Searching for OpenDocument schema files...")
1877 (lambda (schema-dir)
1879 (message "Debug (org-e-odt): Trying %s..." schema-dir
)
1880 (when (and (file-readable-p
1881 (expand-file-name "od-manifest-schema-v1.2-cs01.rnc"
1884 (expand-file-name "od-schema-v1.2-cs01.rnc"
1887 (expand-file-name "schemas.xml" schema-dir
)))
1888 (message "Debug (org-e-odt): Using schema files under %s"
1890 (throw 'schema-dir schema-dir
))))
1891 org-e-odt-schema-dir-list
)
1892 (message "Debug (org-e-odt): No OpenDocument schema files installed")
1895 "Directory that contains OpenDocument schema files.
1897 This directory contains:
1898 1. rnc files for OpenDocument schema
1899 2. a \"schemas.xml\" file that specifies locating rules needed
1900 for auto validation of OpenDocument XML files.
1902 Use the customize interface to set this variable. This ensures
1903 that `rng-schema-locating-files' is updated and auto-validation
1904 of OpenDocument XML takes place based on the value
1905 `rng-nxml-auto-validate-flag'.
1907 The default value of this variable varies depending on the
1908 version of org in use and is initialized from
1909 `org-e-odt-schema-dir-list'. The OASIS schema files are available
1910 only in the org's private git repository. It is *not* bundled
1911 with GNU ELPA tar or standard Emacs distribution."
1913 (const :tag
"Not set" nil
)
1914 (directory :tag
"Schema directory"))
1915 :group
'org-export-e-odt
1919 "Set `org-e-odt-schema-dir'.
1920 Also add it to `rng-schema-locating-files'."
1921 (let ((schema-dir value
))
1925 (expand-file-name "od-manifest-schema-v1.2-cs01.rnc" schema-dir
))
1927 (expand-file-name "od-schema-v1.2-cs01.rnc" schema-dir
))
1929 (expand-file-name "schemas.xml" schema-dir
)))
1932 (message "Error (org-e-odt): %s has no OpenDocument schema files"
1935 (when org-e-odt-schema-dir
1936 (eval-after-load 'rng-loc
1937 '(add-to-list 'rng-schema-locating-files
1938 (expand-file-name "schemas.xml"
1939 org-e-odt-schema-dir
))))))
1941 (defcustom org-e-odt-content-template-file nil
1942 "Template file for \"content.xml\".
1943 The exporter embeds the exported content just before
1944 \"</office:text>\" element.
1946 If unspecified, the file named \"OrgOdtContentTemplate.xml\"
1947 under `org-e-odt-styles-dir' is used."
1949 :group
'org-export-e-odt
1952 (defcustom org-e-odt-styles-file nil
1953 "Default styles file for use with ODT export.
1954 Valid values are one of:
1956 2. path to a styles.xml file
1957 3. path to a *.odt or a *.ott file
1958 4. list of the form (ODT-OR-OTT-FILE (FILE-MEMBER-1 FILE-MEMBER-2
1961 In case of option 1, an in-built styles.xml is used. See
1962 `org-e-odt-styles-dir' for more information.
1964 In case of option 3, the specified file is unzipped and the
1965 styles.xml embedded therein is used.
1967 In case of option 4, the specified ODT-OR-OTT-FILE is unzipped
1968 and FILE-MEMBER-1, FILE-MEMBER-2 etc are copied in to the
1969 generated odt file. Use relative path for specifying the
1970 FILE-MEMBERS. styles.xml must be specified as one of the
1973 Use options 1, 2 or 3 only if styles.xml alone suffices for
1974 achieving the desired formatting. Use option 4, if the styles.xml
1975 references additional files like header and footer images for
1976 achieving the desired formatting.
1978 Use \"#+ODT_STYLES_FILE: ...\" directive to set this variable on
1979 a per-file basis. For example,
1981 #+ODT_STYLES_FILE: \"/path/to/styles.xml\" or
1982 #+ODT_STYLES_FILE: (\"/path/to/file.ott\" (\"styles.xml\" \"image/hdr.png\"))."
1983 :group
'org-export-e-odt
1987 (const :tag
"Factory settings" nil
)
1988 (file :must-match t
:tag
"styles.xml")
1989 (file :must-match t
:tag
"ODT or OTT file")
1990 (list :tag
"ODT or OTT file + Members"
1991 (file :must-match t
:tag
"ODF Text or Text Template file")
1992 (cons :tag
"Members"
1993 (file :tag
" Member" "styles.xml")
1994 (repeat (file :tag
"Member"))))))
1997 (defcustom org-e-odt-inline-image-extensions
1998 '("png" "jpeg" "jpg" "gif")
1999 "Extensions of image files that can be inlined into HTML."
2000 :type
'(repeat (string :tag
"Extension"))
2001 :group
'org-export-e-odt
2004 (defcustom org-e-odt-pixels-per-inch display-pixels-per-inch
2005 "Scaling factor for converting images pixels to inches.
2006 Use this for sizing of embedded images. See Info node `(org)
2007 Images in ODT export' for more information."
2009 :group
'org-export-e-odt
2012 (defcustom org-e-odt-create-custom-styles-for-srcblocks t
2013 "Whether custom styles for colorized source blocks be automatically created.
2014 When this option is turned on, the exporter creates custom styles
2015 for source blocks based on the advice of `htmlfontify'. Creation
2016 of custom styles happen as part of `org-e-odt-hfy-face-to-css'.
2018 When this option is turned off exporter does not create such
2021 Use the latter option if you do not want the custom styles to be
2022 based on your current display settings. It is necessary that the
2023 styles.xml already contains needed styles for colorizing to work.
2025 This variable is effective only if
2026 `org-e-odt-fontify-srcblocks' is turned on."
2027 :group
'org-export-e-odt
2031 (defcustom org-e-odt-preferred-output-format nil
2032 "Automatically post-process to this format after exporting to \"odt\".
2033 Interactive commands `org-export-as-e-odt' and
2034 `org-export-as-e-odt-and-open' export first to \"odt\" format and
2035 then use `org-e-odt-convert-process' to convert the
2036 resulting document to this format. During customization of this
2037 variable, the list of valid values are populated based on
2038 `org-e-odt-convert-capabilities'."
2039 :group
'org-export-e-odt
2041 :type
'(choice :convert-widget
2043 (apply 'widget-convert
(widget-type w
)
2044 (eval (car (widget-get w
:args
)))))
2045 `((const :tag
"None" nil
)
2046 ,@(mapcar (lambda (c)
2047 `(const :tag
,c
,c
))
2048 (org-e-odt-reachable-formats "odt")))))
2050 (defcustom org-e-odt-table-styles
2051 '(("OrgEquation" "OrgEquation"
2052 ((use-first-column-styles . t
)
2053 (use-last-column-styles . t
))))
2054 "Specify how Table Styles should be derived from a Table Template.
2055 This is a list where each element is of the
2056 form (TABLE-STYLE-NAME TABLE-TEMPLATE-NAME TABLE-CELL-OPTIONS).
2058 TABLE-STYLE-NAME is the style associated with the table through
2059 `org-e-odt-table-style'.
2061 TABLE-TEMPLATE-NAME is a set of - upto 9 - automatic
2062 TABLE-CELL-STYLE-NAMEs and PARAGRAPH-STYLE-NAMEs (as defined
2063 below) that is included in
2064 `org-e-odt-content-template-file'.
2066 TABLE-CELL-STYLE-NAME := TABLE-TEMPLATE-NAME + TABLE-CELL-TYPE +
2068 PARAGRAPH-STYLE-NAME := TABLE-TEMPLATE-NAME + TABLE-CELL-TYPE +
2070 TABLE-CELL-TYPE := \"FirstRow\" | \"LastColumn\" |
2071 \"FirstRow\" | \"LastRow\" |
2072 \"EvenRow\" | \"OddRow\" |
2073 \"EvenColumn\" | \"OddColumn\" | \"\"
2074 where \"+\" above denotes string concatenation.
2076 TABLE-CELL-OPTIONS is an alist where each element is of the
2077 form (TABLE-CELL-STYLE-SELECTOR . ON-OR-OFF).
2078 TABLE-CELL-STYLE-SELECTOR := `use-first-row-styles' |
2079 `use-last-row-styles' |
2080 `use-first-column-styles' |
2081 `use-last-column-styles' |
2082 `use-banding-rows-styles' |
2083 `use-banding-columns-styles' |
2084 `use-first-row-styles'
2085 ON-OR-OFF := `t' | `nil'
2087 For example, with the following configuration
2089 \(setq org-e-odt-table-styles
2090 '\(\(\"TableWithHeaderRowsAndColumns\" \"Custom\"
2091 \(\(use-first-row-styles . t\)
2092 \(use-first-column-styles . t\)\)\)
2093 \(\"TableWithHeaderColumns\" \"Custom\"
2094 \(\(use-first-column-styles . t\)\)\)\)\)
2096 1. A table associated with \"TableWithHeaderRowsAndColumns\"
2097 style will use the following table-cell styles -
2098 \"CustomFirstRowTableCell\", \"CustomFirstColumnTableCell\",
2099 \"CustomTableCell\" and the following paragraph styles
2100 \"CustomFirstRowTableParagraph\",
2101 \"CustomFirstColumnTableParagraph\", \"CustomTableParagraph\"
2104 2. A table associated with \"TableWithHeaderColumns\" style will
2105 use the following table-cell styles -
2106 \"CustomFirstColumnTableCell\", \"CustomTableCell\" and the
2107 following paragraph styles
2108 \"CustomFirstColumnTableParagraph\", \"CustomTableParagraph\"
2111 Note that TABLE-TEMPLATE-NAME corresponds to the
2112 \"<table:table-template>\" elements contained within
2113 \"<office:styles>\". The entries (TABLE-STYLE-NAME
2114 TABLE-TEMPLATE-NAME TABLE-CELL-OPTIONS) correspond to
2115 \"table:template-name\" and \"table:use-first-row-styles\" etc
2116 attributes of \"<table:table>\" element. Refer ODF-1.2
2117 specification for more information. Also consult the
2118 implementation filed under `org-e-odt-get-table-cell-styles'.
2120 The TABLE-STYLE-NAME \"OrgEquation\" is used internally for
2121 formatting of numbered display equations. Do not delete this
2122 style from the list."
2123 :group
'org-export-e-odt
2126 (const :tag
"None" nil
)
2127 (repeat :tag
"Table Styles"
2128 (list :tag
"Table Style Specification"
2129 (string :tag
"Table Style Name")
2130 (string :tag
"Table Template Name")
2131 (alist :options
(use-first-row-styles
2133 use-first-column-styles
2134 use-last-column-styles
2135 use-banding-rows-styles
2136 use-banding-columns-styles
)
2138 :value-type
(const :tag
"True" t
))))))
2139 (defcustom org-e-odt-fontify-srcblocks t
2140 "Specify whether or not source blocks need to be fontified.
2141 Turn this option on if you want to colorize the source code
2142 blocks in the exported file. For colorization to work, you need
2143 to make available an enhanced version of `htmlfontify' library."
2145 :group
'org-export-e-odt
2148 (defcustom org-e-odt-prettify-xml t
; FIXME
2149 "Specify whether or not the xml output should be prettified.
2150 When this option is turned on, `indent-region' is run on all
2151 component xml buffers before they are saved. Turn this off for
2152 regular use. Turn this on if you need to examine the xml
2154 :group
'org-export-e-odt
2158 (defcustom org-e-odt-convert-processes
2160 "soffice --headless --convert-to %f%x --outdir %d %i")
2162 "unoconv -f %f -o %d %i"))
2163 "Specify a list of document converters and their usage.
2164 The converters in this list are offered as choices while
2165 customizing `org-e-odt-convert-process'.
2167 This variable is a list where each element is of the
2168 form (CONVERTER-NAME CONVERTER-CMD). CONVERTER-NAME is the name
2169 of the converter. CONVERTER-CMD is the shell command for the
2170 converter and can contain format specifiers. These format
2171 specifiers are interpreted as below:
2173 %i input file name in full
2174 %I input file name as a URL
2175 %f format of the output file
2176 %o output file name in full
2177 %O output file name as a URL
2178 %d output dir in full
2179 %D output dir as a URL.
2180 %x extra options as set in `org-e-odt-convert-capabilities'."
2181 :group
'org-export-e-odt
2185 (const :tag
"None" nil
)
2186 (alist :tag
"Converters"
2187 :key-type
(string :tag
"Converter Name")
2188 :value-type
(group (string :tag
"Command line")))))
2190 (defcustom org-e-odt-convert-process
"LibreOffice"
2191 "Use this converter to convert from \"odt\" format to other formats.
2192 During customization, the list of converter names are populated
2193 from `org-e-odt-convert-processes'."
2194 :group
'org-export-e-odt
2196 :type
'(choice :convert-widget
2198 (apply 'widget-convert
(widget-type w
)
2199 (eval (car (widget-get w
:args
)))))
2200 `((const :tag
"None" nil
)
2201 ,@(mapcar (lambda (c)
2202 `(const :tag
,(car c
) ,(car c
)))
2203 org-e-odt-convert-processes
))))
2205 (defcustom org-e-odt-convert-capabilities
2207 ("odt" "ott" "doc" "rtf" "docx")
2208 (("pdf" "pdf") ("odt" "odt") ("rtf" "rtf") ("ott" "ott")
2209 ("doc" "doc" ":\"MS Word 97\"") ("docx" "docx") ("html" "html")))
2212 (("pdf" "pdf") ("odt" "odt") ("html" "html")))
2214 ("ods" "ots" "xls" "csv" "xlsx")
2215 (("pdf" "pdf") ("ots" "ots") ("html" "html") ("csv" "csv") ("ods" "ods")
2216 ("xls" "xls") ("xlsx" "xlsx")))
2218 ("odp" "otp" "ppt" "pptx")
2219 (("pdf" "pdf") ("swf" "swf") ("odp" "odp") ("otp" "otp") ("ppt" "ppt")
2220 ("pptx" "pptx") ("odg" "odg"))))
2221 "Specify input and output formats of `org-e-odt-convert-process'.
2222 More correctly, specify the set of input and output formats that
2223 the user is actually interested in.
2225 This variable is an alist where each element is of the
2226 form (DOCUMENT-CLASS INPUT-FMT-LIST OUTPUT-FMT-ALIST).
2227 INPUT-FMT-LIST is a list of INPUT-FMTs. OUTPUT-FMT-ALIST is an
2228 alist where each element is of the form (OUTPUT-FMT
2229 OUTPUT-FILE-EXTENSION EXTRA-OPTIONS).
2231 The variable is interpreted as follows:
2232 `org-e-odt-convert-process' can take any document that is in
2233 INPUT-FMT-LIST and produce any document that is in the
2234 OUTPUT-FMT-LIST. A document converted to OUTPUT-FMT will have
2235 OUTPUT-FILE-EXTENSION as the file name extension. OUTPUT-FMT
2236 serves dual purposes:
2237 - It is used for populating completion candidates during
2238 `org-e-odt-convert' commands.
2239 - It is used as the value of \"%f\" specifier in
2240 `org-e-odt-convert-process'.
2242 EXTRA-OPTIONS is used as the value of \"%x\" specifier in
2243 `org-e-odt-convert-process'.
2245 DOCUMENT-CLASS is used to group a set of file formats in
2246 INPUT-FMT-LIST in to a single class.
2248 Note that this variable inherently captures how LibreOffice based
2249 converters work. LibreOffice maps documents of various formats
2250 to classes like Text, Web, Spreadsheet, Presentation etc and
2251 allow document of a given class (irrespective of it's source
2252 format) to be converted to any of the export formats associated
2255 See default setting of this variable for an typical
2257 :group
'org-export-e-odt
2261 (const :tag
"None" nil
)
2262 (alist :tag
"Capabilities"
2263 :key-type
(string :tag
"Document Class")
2265 (group (repeat :tag
"Input formats" (string :tag
"Input format"))
2266 (alist :tag
"Output formats"
2267 :key-type
(string :tag
"Output format")
2269 (group (string :tag
"Output file extension")
2271 (const :tag
"None" nil
)
2272 (string :tag
"Extra options"))))))))
2279 ;;;; Document Header (Styles)
2281 ;;;; Document Header (Scripts)
2283 ;;;; Document Header (Mathjax)
2296 ;;;; Statistics Cookie
2316 ;;;; Horizontal Rule
2317 ;;;; Inline Babel Call
2318 ;;;; Inline Src Block
2322 ;;;; Latex Environment
2331 ;;;; Property Drawer
2357 ;;; User Configurable Variables (MAYBE)
2365 (defcustom org-e-odt-format-headline-function nil
2366 "Function to format headline text.
2368 This function will be called with 5 arguments:
2369 TODO the todo keyword \(string or nil\).
2370 TODO-TYPE the type of todo \(symbol: `todo', `done', nil\)
2371 PRIORITY the priority of the headline \(integer or nil\)
2372 TEXT the main headline text \(string\).
2373 TAGS the tags string, separated with colons \(string or nil\).
2375 The function result will be used in the section format string.
2377 As an example, one could set the variable to the following, in
2378 order to reproduce the default set-up:
2380 \(defun org-e-odt-format-headline \(todo todo-type priority text tags\)
2381 \"Default format function for an headline.\"
2382 \(concat \(when todo
2383 \(format \"\\\\textbf{\\\\textsc{\\\\textsf{%s}}} \" todo\)\)
2385 \(format \"\\\\framebox{\\\\#%c} \" priority\)\)
2387 \(when tags \(format \"\\\\hfill{}\\\\textsc{%s}\" tags\)\)\)\)"
2388 :group
'org-export-e-odt
2395 (defcustom org-e-odt-active-timestamp-format
"\\textit{%s}"
2396 "A printf format string to be applied to active time-stamps."
2397 :group
'org-export-e-odt
2400 (defcustom org-e-odt-inactive-timestamp-format
"\\textit{%s}"
2401 "A printf format string to be applied to inactive time-stamps."
2402 :group
'org-export-e-odt
2405 (defcustom org-e-odt-diary-timestamp-format
"\\textit{%s}"
2406 "A printf format string to be applied to diary time-stamps."
2407 :group
'org-export-e-odt
2413 (defcustom org-e-odt-inline-image-rules
2414 '(("file" .
"\\.\\(jpeg\\|jpg\\|png\\|gif\\)\\'"))
2415 "Rules characterizing image files that can be inlined into HTML.
2417 A rule consists in an association whose key is the type of link
2418 to consider, and value is a regexp that will be matched against
2421 Note that, by default, the image extension *actually* allowed
2422 depend on the way the HTML file is processed. When used with
2423 pdflatex, pdf, jpg and png images are OK. When processing
2424 through dvi to Postscript, only ps and eps are allowed. The
2425 default we use here encompasses both."
2426 :group
'org-export-e-odt
2427 :type
'(alist :key-type
(string :tag
"Type")
2428 :value-type
(regexp :tag
"Path")))
2432 (defcustom org-e-odt-table-caption-above t
2433 "When non-nil, place caption string at the beginning of the table.
2434 Otherwise, place it near the end."
2435 :group
'org-export-e-odt
2440 (defcustom org-e-odt-format-drawer-function nil
2441 "Function called to format a drawer in HTML code.
2443 The function must accept two parameters:
2444 NAME the drawer name, like \"LOGBOOK\"
2445 CONTENTS the contents of the drawer.
2447 The function should return the string to be exported.
2449 For example, the variable could be set to the following function
2450 in order to mimic default behaviour:
2452 \(defun org-e-odt-format-drawer-default \(name contents\)
2453 \"Format a drawer element for HTML export.\"
2455 :group
'org-export-e-odt
2461 (defcustom org-e-odt-format-inlinetask-function nil
2462 "Function called to format an inlinetask in HTML code.
2464 The function must accept six parameters:
2465 TODO the todo keyword, as a string
2466 TODO-TYPE the todo type, a symbol among `todo', `done' and nil.
2467 PRIORITY the inlinetask priority, as a string
2468 NAME the inlinetask name, as a string.
2469 TAGS the inlinetask tags, as a string.
2470 CONTENTS the contents of the inlinetask, as a string.
2472 The function should return the string to be exported.
2474 For example, the variable could be set to the following function
2475 in order to mimic default behaviour:
2477 \(defun org-e-odt-format-inlinetask \(todo type priority name tags contents\)
2478 \"Format an inline task element for HTML export.\"
2479 \(let \(\(full-title
2482 \(format \"\\\\textbf{\\\\textsf{\\\\textsc{%s}}} \" todo\)\)
2483 \(when priority \(format \"\\\\framebox{\\\\#%c} \" priority\)\)
2485 \(when tags \(format \"\\\\hfill{}\\\\textsc{%s}\" tags\)\)\)\)\)
2486 \(format \(concat \"\\\\begin{center}\\n\"
2488 \"\\\\begin{minipage}[c]{.6\\\\textwidth}\\n\"
2490 \"\\\\rule[.8em]{\\\\textwidth}{2pt}\\n\\n\"
2492 \"\\\\end{minipage}}\"
2493 \"\\\\end{center}\"\)
2494 full-title contents\)\)"
2495 :group
'org-export-e-odt
2503 (defcustom org-e-odt-quotes
2504 '(("fr" ("\\(\\s-\\|[[(]\\)\"" .
"«~") ("\\(\\S-\\)\"" .
"~»") ("\\(\\s-\\|(\\)'" .
"'"))
2505 ("en" ("\\(\\s-\\|[[(]\\)\"" .
"``") ("\\(\\S-\\)\"" .
"''") ("\\(\\s-\\|(\\)'" .
"`")))
2506 "Alist for quotes to use when converting english double-quotes.
2508 The CAR of each item in this alist is the language code.
2509 The CDR of each item in this alist is a list of three CONS:
2510 - the first CONS defines the opening quote;
2511 - the second CONS defines the closing quote;
2512 - the last CONS defines single quotes.
2514 For each item in a CONS, the first string is a regexp
2515 for allowed characters before/after the quote, the second
2516 string defines the replacement string for this quote."
2517 :group
'org-export-e-odt
2519 (cons :tag
"Opening quote"
2520 (string :tag
"Regexp for char before")
2521 (string :tag
"Replacement quote "))
2522 (cons :tag
"Closing quote"
2523 (string :tag
"Regexp for char after ")
2524 (string :tag
"Replacement quote "))
2525 (cons :tag
"Single quote"
2526 (string :tag
"Regexp for char before")
2527 (string :tag
"Replacement quote "))))
2534 ;;; Internal Functions (HTML)
2536 ;; (defun org-e-odt-format-inline-image (path &optional caption label attr)
2537 ;; ;; FIXME: alt text missing here?
2538 ;; (let ((inline-image (format "<img src=\"%s\" alt=\"%s\"/>"
2539 ;; path (file-name-nondirectory path))))
2540 ;; (if (not label) inline-image
2541 ;; (org-e-odt-format-section inline-image "figure" label))))
2545 (defun org-e-odt-bibliography ()
2546 "Find bibliography, cut it out and return it."
2548 (let (beg end
(cnt 1) bib
)
2550 (goto-char (point-min))
2551 (when (re-search-forward
2552 "^[ \t]*<div \\(id\\|class\\)=\"bibliography\"" nil t
)
2553 (setq beg
(match-beginning 0))
2554 (while (re-search-forward "</?div\\>" nil t
)
2555 (setq cnt
(+ cnt
(if (string= (match-string 0) "<div") +1 -
1)))
2557 (and (looking-at ">") (forward-char 1))
2558 (setq bib
(buffer-substring beg
(point)))
2559 (delete-region beg
(point))
2560 (throw 'exit bib
))))
2565 (defun org-e-odt-format-table (lines olines
)
2566 (let ((org-e-odt-format-table-no-css nil
))
2567 (org-lparse-format-table lines olines
)))
2569 (defun org-e-odt-splice-attributes (tag attributes
)
2570 "Read attributes in string ATTRIBUTES, add and replace in HTML tag TAG."
2571 (if (not attributes
)
2573 (let (oldatt newatt
)
2574 (setq oldatt
(org-extract-attributes-from-string tag
)
2576 newatt
(cdr (org-extract-attributes-from-string attributes
)))
2578 (setq oldatt
(plist-put oldatt
(pop newatt
) (pop newatt
))))
2579 (if (string-match ">" tag
)
2581 (replace-match (concat (org-attributes-to-string oldatt
) ">")
2585 (defun org-export-splice-style (style extra
)
2586 "Splice EXTRA into STYLE, just before \"</style>\"."
2587 (if (and (stringp extra
)
2588 (string-match "\\S-" extra
)
2589 (string-match "</style>" style
))
2590 (concat (substring style
0 (match-beginning 0))
2592 (substring style
(match-beginning 0)))
2595 (defun org-e-odt-toc-entry-formatter
2596 (level snumber todo todo-type priority
2597 headline tags target extra-targets extra-class
)
2598 (org-e-odt-format-toc-entry snumber todo headline tags target
))
2600 (defun org-e-odt-make-string (n string
)
2601 (let (out) (dotimes (i n out
) (setq out
(concat string out
)))))
2603 (defun org-e-odt-toc-text (toc-entries)
2604 (let* ((prev-level (1- (nth 1 (car toc-entries
))))
2605 (start-level prev-level
))
2608 (let ((headline (nth 0 entry
))
2609 (level (nth 1 entry
)))
2610 (prog1 (org-e-odt-format-toc-item headline level prev-level
)
2611 (setq prev-level level
))))
2614 (defun* org-e-odt-format-toc-headline
2615 (todo todo-type priority text tags
2616 &key level section-number headline-label
&allow-other-keys
)
2619 (and org-export-with-section-numbers
2620 (concat section-number
". "))
2624 (org-e-odt-format-spaces 3)
2625 (org-e-odt-format-fontify tags
"tag")))))
2627 (setq text
(org-e-odt-format-fontify text
"todo")))
2629 (let ((org-e-odt-suppress-xref t
))
2630 (org-e-odt-format-link text
(concat "#" headline-label
))))
2632 (defun org-e-odt-toc (depth info
)
2633 (assert (wholenump depth
))
2634 (let* ((headlines (org-export-collect-headlines info depth
))
2636 (loop for headline in headlines collect
2637 (list (org-e-odt-format-headline--wrap
2638 headline info
'org-e-odt-format-toc-headline
)
2639 (org-export-get-relative-level headline info
)))))
2641 (let* ((lang-specific-heading "Table of Contents")) ; FIXME
2643 (org-e-odt-begin-toc lang-specific-heading depth
)
2644 (org-e-odt-toc-text toc-entries
)
2645 (org-e-odt-end-toc))))))
2647 (defun org-e-odt-begin-outline (level1 snumber title tags
2648 target extra-targets extra-class
)
2649 (let* ((class (format "outline-%d" level1
))
2650 (class (if extra-class
(concat class
" " extra-class
) class
))
2651 (id (format "outline-container-%s"
2652 (org-lparse-suffix-from-snumber snumber
)))
2653 (extra (concat (when id
(format " id=\"%s\"" id
))
2654 (when class
(format " class=\"%s\"" class
)))))
2655 (org-lparse-insert-tag "<div%s>" extra
)
2657 (org-lparse-format 'HEADING
2659 'HEADLINE title extra-targets tags snumber level1
)
2662 (defun org-e-odt-end-outline ()
2663 (org-lparse-insert-tag "</div>"))
2665 (defun org-e-odt-suffix-from-snumber (snumber)
2666 (let* ((snu (replace-regexp-in-string "\\." "-" snumber
))
2667 (href (cdr (assoc (concat "sec-" snu
)
2668 org-export-preferred-target-alist
))))
2669 (org-solidify-link-text (or href snu
))))
2671 (defun org-e-odt-format-outline (contents level1 snumber title
2672 tags target extra-targets extra-class
)
2675 ;; (defun org-e-odt-format-line (line)
2676 ;; (case org-lparse-dyn-current-environment
2677 ;; ((quote fixedwidth) (concat (org-e-odt-encode-plain-text line) "\n"))
2678 ;; (t (concat line "\n"))))
2680 (defun org-e-odt-fix-class-name (kwd) ; audit callers of this function
2681 "Turn todo keyword into a valid class name.
2682 Replaces invalid characters with \"_\"."
2684 (while (string-match "[^a-zA-Z0-9_]" kwd
)
2685 (setq kwd
(replace-match "_" t t kwd
))))
2688 (defun org-e-odt-format-internal-link (text href
&optional extra
)
2689 (org-e-odt-format-link text
(concat "#" href
) extra
))
2691 (defun org-e-odt-format-extra-targets (extra-targets)
2692 (if (not extra-targets
) ""
2693 (mapconcat (lambda (x)
2695 (setq x
(org-solidify-link-text
2696 (if (org-uuidgen-p x
) (concat "ID-" x
) x
)))
2697 (org-e-odt-format-anchor "" x
))) extra-targets
"")))
2699 (defun org-e-odt-format-org-tags (tags)
2701 (org-e-odt-format-fontify
2704 (org-e-odt-format-fontify
2705 x
(concat "" ;; org-e-odt-tag-class-prefix
2706 (org-e-odt-fix-class-name x
))))
2707 (org-split-string tags
":")
2708 (org-e-odt-format-spaces 1)) "tag")))
2710 (defun org-e-odt-format-section-number (&optional snumber level
)
2712 (and nil org-export-with-section-numbers
2713 ;; (not org-lparse-body-only)
2715 (org-e-odt-format-fontify snumber
(format "section-number-%d" level
))))
2717 ;; (defun org-e-odt-format-headline (title extra-targets tags
2718 ;; &optional snumber level)
2720 ;; (org-e-odt-format-extra-targets extra-targets)
2721 ;; (concat (org-e-odt-format-section-number snumber level) " ")
2723 ;; (and tags (concat (org-e-odt-format-spaces 3)
2724 ;; (org-e-odt-format-org-tags tags)))))
2726 (defun org-e-odt-get-coding-system-for-write ()
2727 (or org-e-odt-coding-system
2728 (and (boundp 'buffer-file-coding-system
) buffer-file-coding-system
)))
2730 (defun org-e-odt-get-coding-system-for-save ()
2731 (or org-e-odt-coding-system
2732 (and (boundp 'buffer-file-coding-system
) buffer-file-coding-system
)))
2734 ;; (defun org-e-odt-format-date (info)
2735 ;; (let ((date (plist-get info :date)))
2737 ;; ((and date (string-match "%" date))
2738 ;; (format-time-string date))
2740 ;; (t (format-time-string "%Y-%m-%d %T %Z")))))
2744 ;;; Internal Functions (Ngz)
2746 (defun org-e-odt--caption/label-string
(caption label info
)
2747 "Return caption and label HTML string for floats.
2749 CAPTION is a cons cell of secondary strings, the car being the
2750 standard caption and the cdr its short form. LABEL is a string
2751 representing the label. INFO is a plist holding contextual
2754 If there's no caption nor label, return the empty string.
2756 For non-floats, see `org-e-odt--wrap-label'."
2757 (setq label nil
) ;; FIXME
2759 (let ((label-str (if label
(format "\\label{%s}" label
) "")))
2761 ((and (not caption
) (not label
)) "")
2762 ((not caption
) (format "\\label{%s}\n" label
))
2763 ;; Option caption format with short name.
2765 (format "\\caption[%s]{%s%s}\n"
2766 (org-export-secondary-string (cdr caption
) 'e-odt info
)
2768 (org-export-secondary-string (car caption
) 'e-odt info
)))
2769 ;; Standard caption format.
2770 ;; (t (format "\\caption{%s%s}\n"
2772 ;; (org-export-secondary-string (car caption) 'e-odt info)))
2774 (t (org-export-secondary-string (car caption
) 'e-odt info
)))))
2776 (defun org-e-odt--find-verb-separator (s)
2777 "Return a character not used in string S.
2778 This is used to choose a separator for constructs like \\verb."
2779 (let ((ll "~,./?;':\"|!@#%^&-_=+abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ<>()[]{}"))
2780 (loop for c across ll
2781 when
(not (string-match (regexp-quote (char-to-string c
)) s
))
2782 return
(char-to-string c
))))
2784 (defun org-e-odt--quotation-marks (text info
)
2785 "Export quotation marks depending on language conventions.
2786 TEXT is a string containing quotation marks to be replaced. INFO
2787 is a plist used as a communication channel."
2790 (while (setq start
(string-match (car l
) text start
))
2791 (let ((new-quote (concat (match-string 1 text
) (cdr l
))))
2792 (setq text
(replace-match new-quote t t text
))))))
2793 (cdr (or (assoc (plist-get info
:language
) org-e-odt-quotes
)
2794 ;; Falls back on English.
2795 (assoc "en" org-e-odt-quotes
))))
2798 (defun org-e-odt--wrap-label (element output
)
2799 "Wrap label associated to ELEMENT around OUTPUT, if appropriate.
2800 This function shouldn't be used for floats. See
2801 `org-e-odt--caption/label-string'."
2802 ;; (let ((label (org-element-property :name element)))
2803 ;; (if (or (not output) (not label) (string= output "") (string= label ""))
2805 ;; (concat (format "\\label{%s}\n" label) output)))
2810 ;;; Transcode Helpers
2812 (defun* org-e-odt-format-headline
2813 (todo todo-type priority text tags
2814 &key level section-number headline-label
&allow-other-keys
)
2815 (concat (org-e-odt-todo todo
) (and todo
" ") text
2816 (and tags
(org-e-odt-format-spaces 3))
2817 (and tags
(org-e-odt-format-org-tags tags
))))
2821 (defun org-e-odt-htmlfontify-string (line)
2822 (let* ((hfy-html-quote-regex "\\([<\"&> ]\\)")
2823 (hfy-html-quote-map '(("\"" """)
2828 (" " "<text:tab/>")))
2829 (hfy-face-to-css 'org-e-odt-hfy-face-to-css
)
2830 (hfy-optimisations-1 (copy-seq hfy-optimisations
))
2831 (hfy-optimisations (add-to-list 'hfy-optimisations-1
2833 (hfy-begin-span-handler
2834 (lambda (style text-block text-id text-begins-block-p
)
2835 (insert (format "<text:span text:style-name=\"%s\">" style
))))
2836 (hfy-end-span-handler (lambda nil
(insert "</text:span>"))))
2837 (htmlfontify-string line
)))
2839 (defun org-e-odt-do-format-code
2840 (code &optional lang refs retain-labels num-start
)
2841 (let* ((lang (or (assoc-default lang org-src-lang-modes
) lang
))
2842 (lang-mode (and lang
(intern (format "%s-mode" lang
))))
2843 (code-lines (org-split-string code
"\n"))
2844 (code-length (length code-lines
))
2845 (use-htmlfontify-p (and (functionp lang-mode
)
2846 org-e-odt-fontify-srcblocks
2847 (require 'htmlfontify nil t
)
2848 (fboundp 'htmlfontify-string
)))
2849 (code (if (not use-htmlfontify-p
) code
2853 (font-lock-fontify-buffer)
2855 (fontifier (if use-htmlfontify-p
'org-e-odt-htmlfontify-string
2856 'org-e-odt-encode-plain-text
))
2857 (par-style (if use-htmlfontify-p
"OrgSrcBlock"
2858 "OrgFixedWidthBlock"))
2860 (assert (= code-length
(length (org-split-string code
"\n"))))
2862 (org-export-format-code
2864 (lambda (loc line-num ref
)
2866 (concat par-style
(and (= (incf i
) code-length
) "LastLine")))
2868 (setq loc
(concat loc
(and ref retain-labels
(format " (%s)" ref
))))
2869 (setq loc
(funcall fontifier loc
))
2871 (setq loc
(org-e-odt-format-target loc
(concat "coderef-" ref
))))
2872 (setq loc
(org-e-odt-format-stylized-paragraph par-style loc
))
2873 (if (not line-num
) loc
2874 (org-e-odt-format-tags
2875 '("<text:list-item>" .
"</text:list-item>") loc
)))
2878 ((not num-start
) code
)
2879 ((equal num-start
0)
2880 (org-e-odt-format-tags
2881 '("<text:list text:style-name=\"OrgSrcBlockNumberedLine\"%s>"
2882 .
"</text:list>") code
" text:continue-numbering=\"false\""))
2883 (t (org-e-odt-format-tags
2884 '("<text:list text:style-name=\"OrgSrcBlockNumberedLine\"%s>"
2885 .
"</text:list>") code
" text:continue-numbering=\"true\"")))))
2887 (defun org-e-odt-format-code (element info
)
2888 (let* ((lang (org-element-property :language element
))
2889 ;; Extract code and references.
2890 (code-info (org-export-unravel-code element
))
2891 (code (car code-info
))
2892 (refs (cdr code-info
))
2893 ;; Does the src block contain labels?
2894 (retain-labels (org-element-property :retain-labels element
))
2895 ;; Does it have line numbers?
2896 (num-start (case (org-element-property :number-lines element
)
2897 (continued (org-export-get-loc element info
))
2899 (org-e-odt-do-format-code code lang refs retain-labels num-start
)))
2905 (defun org-e-odt-template (contents info
)
2906 "Return complete document string after HTML conversion.
2907 CONTENTS is the transcoded contents string. RAW-DATA is the
2908 original parsed data. INFO is a plist holding export options."
2910 (org-e-odt-update-meta-file info
)
2912 (insert-file-contents
2913 (or org-e-odt-content-template-file
2914 (expand-file-name "OrgOdtContentTemplate.xml"
2915 org-e-odt-styles-dir
)))
2916 (goto-char (point-min))
2917 (re-search-forward "</office:text>" nil nil
)
2918 (goto-char (match-beginning 0))
2921 (insert (org-e-odt-format-preamble info
))
2922 ;; Table of Contents
2923 (let ((depth (plist-get info
:with-toc
)))
2924 (when (wholenump depth
) (insert (org-e-odt-toc depth info
))))
2926 ;; Copy styles.xml. Also dump htmlfontify styles, if there is any.
2927 (org-e-odt-update-styles-file info
)
2929 ;; Update styles.xml - take care of outline numbering
2930 (with-current-buffer
2931 (find-file-noselect (expand-file-name "styles.xml") t
)
2932 ;; Don't make automatic backup of styles.xml file. This setting
2933 ;; prevents the backed-up styles.xml file from being zipped in to
2934 ;; odt file. This is more of a hackish fix. Better alternative
2935 ;; would be to fix the zip command so that the output odt file
2936 ;; includes only the needed files and excludes any auto-generated
2937 ;; extra files like backups and auto-saves etc etc. Note that
2938 ;; currently the zip command zips up the entire temp directory so
2939 ;; that any auto-generated files created under the hood ends up in
2940 ;; the resulting odt file.
2941 (set (make-local-variable 'backup-inhibited
) t
)
2942 (org-e-odt-configure-outline-numbering))
2946 (buffer-substring-no-properties (point-min) (point-max))))
2950 ;;; Transcode Functions
2954 (defun org-e-odt-center-block (center-block contents info
)
2955 "Transcode a CENTER-BLOCK element from Org to HTML.
2956 CONTENTS holds the contents of the block. INFO is a plist
2957 holding contextual information."
2958 (org-e-odt--wrap-label center-block contents
))
2963 ;; Comments are ignored.
2968 ;; Comment Blocks are ignored.
2973 (defun org-e-odt-drawer (drawer contents info
)
2974 "Transcode a DRAWER element from Org to HTML.
2975 CONTENTS holds the contents of the block. INFO is a plist
2976 holding contextual information."
2977 (let* ((name (org-element-property :drawer-name drawer
))
2978 (output (if (functionp org-e-odt-format-drawer-function
)
2979 (funcall org-e-odt-format-drawer-function
2981 ;; If there's no user defined function: simply
2982 ;; display contents of the drawer.
2984 (org-e-odt--wrap-label drawer output
)))
2989 (defun org-e-odt-dynamic-block (dynamic-block contents info
)
2990 "Transcode a DYNAMIC-BLOCK element from Org to HTML.
2991 CONTENTS holds the contents of the block. INFO is a plist
2992 holding contextual information. See
2994 (org-e-odt--wrap-label dynamic-block contents
))
2999 (defun org-e-odt-emphasis (emphasis contents info
)
3000 "Transcode EMPHASIS from Org to HTML.
3001 CONTENTS is the contents of the emphasized text. INFO is a plist
3002 holding contextual information.."
3003 ;; (format (cdr (assoc (org-element-property :marker emphasis)
3004 ;; org-e-odt-emphasis-alist))
3006 (org-e-odt-format-fontify
3007 contents
(cadr (assoc
3008 (org-element-property :marker emphasis
)
3019 (defun org-e-odt-entity (entity contents info
)
3020 "Transcode an ENTITY object from Org to HTML.
3021 CONTENTS are the definition itself. INFO is a plist holding
3022 contextual information."
3023 ;; (let ((ent (org-element-property :latex entity)))
3024 ;; (if (org-element-property :latex-math-p entity)
3025 ;; (format "$%s$" ent)
3027 (org-element-property :utf-8 entity
))
3032 (defun org-e-odt-example-block (example-block contents info
)
3033 "Transcode a EXAMPLE-BLOCK element from Org to HTML.
3034 CONTENTS is nil. INFO is a plist holding contextual information."
3035 (let* ((options (or (org-element-property :options example-block
) ""))
3036 (value (org-export-handle-code example-block info nil nil t
)))
3037 (org-e-odt--wrap-label
3038 example-block
(org-e-odt-format-source-code-or-example value nil
))))
3043 (defun org-e-odt-export-snippet (export-snippet contents info
)
3044 "Transcode a EXPORT-SNIPPET object from Org to HTML.
3045 CONTENTS is nil. INFO is a plist holding contextual information."
3046 (when (eq (org-export-snippet-backend export-snippet
) 'e-odt
)
3047 (org-element-property :value export-snippet
)))
3052 (defun org-e-odt-export-block (export-block contents info
)
3053 "Transcode a EXPORT-BLOCK element from Org to HTML.
3054 CONTENTS is nil. INFO is a plist holding contextual information."
3055 (when (string= (org-element-property :type export-block
) "latex")
3056 (org-remove-indentation (org-element-property :value export-block
))))
3061 (defun org-e-odt-fixed-width (fixed-width contents info
)
3062 "Transcode a FIXED-WIDTH element from Org to HTML.
3063 CONTENTS is nil. INFO is a plist holding contextual information."
3064 (let* ((value (org-element-normalize-string
3065 (replace-regexp-in-string
3067 (org-element-property :value fixed-width
)))))
3068 (org-e-odt--wrap-label
3069 fixed-width
(org-e-odt-format-source-code-or-example value nil
))))
3072 ;;;; Footnote Definition
3074 ;; Footnote Definitions are ignored.
3077 ;;;; Footnote Reference
3079 (defun org-e-odt-footnote-def (raw info
) ; FIXME
3080 (if (equal (org-element-type raw
) 'org-data
)
3081 (org-trim (org-export-data raw
'e-odt info
)) ; fix paragraph
3083 (org-e-odt-format-stylized-paragraph
3084 'footnote
(org-trim (org-export-secondary-string raw
'e-odt info
)))))
3086 (defvar org-e-odt-footnote-separator
3087 (org-e-odt-format-fontify "," 'superscript
))
3089 (defun org-e-odt-footnote-reference (footnote-reference contents info
)
3090 "Transcode a FOOTNOTE-REFERENCE element from Org to HTML.
3091 CONTENTS is nil. INFO is a plist holding contextual information."
3093 ;; Insert separator between two footnotes in a row.
3094 (let ((prev (org-export-get-previous-element footnote-reference info
)))
3095 (when (eq (org-element-type prev
) 'footnote-reference
)
3096 org-e-odt-footnote-separator
))
3098 ((not (org-export-footnote-first-reference-p footnote-reference info
))
3099 (let* ((n (org-export-get-footnote-number footnote-reference info
)))
3100 (org-e-odt-format-footnote-reference n
"IGNORED" 100)))
3101 ;; Inline definitions are secondary strings.
3102 ((eq (org-element-property :type footnote-reference
) 'inline
)
3103 (let* ((raw (org-export-get-footnote-definition footnote-reference info
))
3104 (n (org-export-get-footnote-number footnote-reference info
))
3105 (def (org-e-odt-footnote-def raw info
)))
3106 (org-e-odt-format-footnote-reference n def
1)))
3107 ;; Non-inline footnotes definitions are full Org data.
3109 (let* ((raw (org-export-get-footnote-definition footnote-reference info
))
3110 (n (org-export-get-footnote-number footnote-reference info
))
3111 (def (org-e-odt-footnote-def raw info
)))
3112 (org-e-odt-format-footnote-reference n def
1))))))
3117 (defun org-e-odt-todo (todo)
3119 (org-e-odt-format-fontify
3121 "" ; org-e-odt-todo-kwd-class-prefix
3122 (org-e-odt-fix-class-name todo
))
3123 (list (if (member todo org-done-keywords
) "done" "todo")
3126 (defun org-e-odt-format-headline--wrap (headline info
3127 &optional format-function
3129 "Transcode an HEADLINE element from Org to ODT.
3130 CONTENTS holds the contents of the headline. INFO is a plist
3131 holding contextual information."
3132 (let* ((level (+ (org-export-get-relative-level headline info
)))
3133 (headline-number (org-export-get-headline-number headline info
))
3134 (section-number (and (org-export-numbered-headline-p headline info
)
3135 (mapconcat 'number-to-string
3136 headline-number
".")))
3137 (todo (and (plist-get info
:with-todo-keywords
)
3138 (let ((todo (org-element-property
3139 :todo-keyword headline
)))
3141 (org-export-secondary-string todo
'e-odt info
)))))
3142 (todo-type (and todo
(org-element-property :todo-type headline
)))
3143 (priority (and (plist-get info
:with-priority
)
3144 (org-element-property :priority headline
)))
3145 (text (org-export-secondary-string
3146 (org-element-property :title headline
) 'e-odt info
))
3147 (tags (and (plist-get info
:with-tags
)
3148 (org-element-property :tags headline
)))
3149 (headline-label (concat "sec-" (mapconcat 'number-to-string
3150 headline-number
"-")))
3151 (format-function (cond
3152 ((functionp format-function
) format-function
)
3153 ((functionp org-e-odt-format-headline-function
)
3155 (lambda (todo todo-type priority text tags
3157 (funcall org-e-odt-format-headline-function
3158 todo todo-type priority text tags
))))
3159 (t 'org-e-odt-format-headline
))))
3160 (apply format-function
3161 todo todo-type priority text tags
3162 :headline-label headline-label
:level level
3163 :section-number section-number extra-keys
)))
3165 (defun org-e-odt-headline (headline contents info
)
3166 "Transcode an HEADLINE element from Org to HTML.
3167 CONTENTS holds the contents of the headline. INFO is a plist
3168 holding contextual information."
3169 (let* ((numberedp (org-export-numbered-headline-p headline info
))
3170 ;; Get level relative to current parsed data.
3171 (level (org-export-get-relative-level headline info
))
3172 (text (org-export-secondary-string
3173 (org-element-property :title headline
) 'e-odt info
))
3174 ;; Create the headline text.
3175 (full-text (org-e-odt-format-headline--wrap headline info
)))
3177 ;; Case 1: This is a footnote section: ignore it.
3178 ((org-element-property :footnote-section-p headline
) nil
)
3179 ;; Case 2. This is a deep sub-tree: export it as a list item.
3180 ;; Also export as items headlines for which no section
3181 ;; format has been found.
3182 ((org-export-low-level-p headline info
) ; FIXME (or (not section-fmt))
3183 ;; Build the real contents of the sub-tree.
3184 (let* ((type (if numberedp
'unordered
'unordered
)) ; FIXME
3185 (itemized-body (org-e-odt-format-list-item
3186 contents type nil nil full-text
)))
3188 (and (org-export-first-sibling-p headline info
)
3189 (org-e-odt-begin-plain-list type
))
3191 (and (org-export-last-sibling-p headline info
)
3192 (org-e-odt-end-plain-list type
)))))
3193 ;; Case 3. Standard headline. Export it as a section.
3195 (let* ((extra-ids (list (org-element-property :custom-id headline
)
3196 (org-element-property :id headline
)))
3197 (extra-ids nil
) ; FIXME
3198 (id (concat "sec-" (mapconcat 'number-to-string
3199 (org-export-get-headline-number
3200 headline info
) "-"))))
3202 (org-e-odt-format-tags
3203 '("<text:h text:style-name=\"Heading_20_%s\" text:outline-level=\"%s\">" .
3205 (concat (org-e-odt-format-extra-targets extra-ids
)
3206 (if (not id
) full-text
(org-e-odt-format-target full-text id
) ))
3211 ;;;; Horizontal Rule
3213 (defun org-e-odt-horizontal-rule (horizontal-rule contents info
)
3214 "Transcode an HORIZONTAL-RULE object from Org to HTML.
3215 CONTENTS is nil. INFO is a plist holding contextual information."
3216 (let ((attr (mapconcat #'identity
3217 (org-element-property :attr_odt horizontal-rule
)
3219 (org-e-odt--wrap-label horizontal-rule
3220 (org-e-odt-format-horizontal-line))))
3223 ;;;; Inline Babel Call
3225 ;; Inline Babel Calls are ignored.
3228 ;;;; Inline Src Block
3230 (defun org-e-odt-inline-src-block (inline-src-block contents info
)
3231 "Transcode an INLINE-SRC-BLOCK element from Org to HTML.
3232 CONTENTS holds the contents of the item. INFO is a plist holding
3233 contextual information."
3234 (let* ((org-lang (org-element-property :language inline-src-block
))
3235 (code (org-element-property :value inline-src-block
))
3236 (separator (org-e-odt--find-verb-separator code
)))
3242 (defun org-e-odt-format-section (text class
&optional id
)
3243 (let ((extra (concat (when id
(format " id=\"%s\"" id
)))))
3244 (concat (format "<div class=\"%s\"%s>\n" class extra
) text
"</div>\n")))
3246 (defun org-e-odt-inlinetask (inlinetask contents info
)
3247 "Transcode an INLINETASK element from Org to ODT.
3248 CONTENTS holds the contents of the block. INFO is a plist
3249 holding contextual information."
3251 ;; If `org-e-odt-format-inlinetask-function' is provided, call it
3252 ;; with appropriate arguments.
3253 ((functionp org-e-odt-format-inlinetask-function
)
3254 (let ((format-function
3256 (lambda (todo todo-type priority text tags
3257 &key contents
&allow-other-keys
)
3258 (funcall org-e-odt-format-inlinetask-function
3259 todo todo-type priority text tags contents
)))))
3260 (org-e-odt-format-headline--wrap
3261 inlinetask info format-function
:contents contents
)))
3262 ;; Otherwise, use a default template.
3263 (t (org-e-odt--wrap-label
3265 (org-e-odt-format-stylized-paragraph
3266 nil
(org-e-odt-format-textbox
3267 (concat (org-e-odt-format-stylized-paragraph
3268 "OrgInlineTaskHeading" (org-e-odt-format-headline--wrap
3271 nil nil
"OrgInlineTaskFrame" " style:rel-width=\"100%\""))))))
3275 (defun org-e-odt-format-list-item (contents type checkbox
3276 &optional term-counter-id
3280 (org-e-odt-format-fontify (case checkbox
3283 (trans "[-]")) 'code
)))
3285 (org-e-odt-begin-list-item type term-counter-id headline
)
3286 ;; FIXME checkbox (and checkbox " ")
3288 (org-e-odt-end-list-item type
)))
3290 (defun org-e-odt-item (item contents info
)
3291 "Transcode an ITEM element from Org to HTML.
3292 CONTENTS holds the contents of the item. INFO is a plist holding
3293 contextual information."
3294 ;; Grab `:level' from plain-list properties, which is always the
3295 ;; first element above current item.
3296 (let* ((plain-list (org-export-get-parent item info
))
3297 (type (org-element-property :type plain-list
))
3298 (level (org-element-property :level plain-list
))
3299 (counter (org-element-property :counter item
))
3300 (checkbox (org-element-property :checkbox item
))
3301 (tag (let ((tag (org-element-property :tag item
)))
3302 (and tag
(org-export-secondary-string tag
'e-odt info
)))))
3303 (org-e-odt-format-list-item
3304 contents type checkbox
(or tag counter
))))
3309 (defun org-e-odt-keyword (keyword contents info
)
3310 "Transcode a KEYWORD element from Org to HTML.
3311 CONTENTS is nil. INFO is a plist holding contextual information."
3312 (let ((key (org-element-property :key keyword
))
3313 (value (org-element-property :value keyword
)))
3315 ((string= key
"LATEX") value
)
3316 ((string= key
"INDEX") (format "\\index{%s}" value
))
3317 ((string= key
"TARGET") nil
; FIXME
3318 ;; (format "\\label{%s}" (org-export-solidify-link-text value))
3320 ((string= key
"toc")
3321 (let ((value (downcase value
)))
3323 ((string-match "\\<headlines\\>" value
)
3324 (let ((depth (or (and (string-match "[0-9]+" value
)
3325 (string-to-number (match-string 0 value
)))
3326 (plist-get info
:with-toc
))))
3327 (when (wholenump depth
) (org-e-odt-toc depth info
))))
3328 ((string= "tables" value
) "FIXME")
3329 ((string= "figures" value
) "FIXME")
3330 ((string= "listings" value
)
3332 ;; At the moment, src blocks with a caption are wrapped
3333 ;; into a figure environment.
3337 ;;;; Latex Environment
3339 (defun org-e-odt-format-latex (latex-frag processing-type
)
3340 (let* ((prefix (case processing-type
3342 (mathml "ltxmathml/")))
3344 (concat prefix
(file-name-sans-extension
3345 (file-name-nondirectory (buffer-file-name)))))
3346 (cache-dir (file-name-directory (buffer-file-name )))
3347 (display-msg (case processing-type
3348 (dvipng "Creating LaTeX Image...")
3349 (mathml "Creating MathML snippet..."))))
3352 (org-format-latex cache-relpath cache-dir nil display-msg
3353 nil nil processing-type
)
3356 (defun org-e-odt-latex-environment (latex-environment contents info
)
3357 "Transcode a LATEX-ENVIRONMENT element from Org to HTML.
3358 CONTENTS is nil. INFO is a plist holding contextual information."
3359 (org-e-odt--wrap-label
3362 (org-remove-indentation
3363 (org-element-property :value latex-environment
)))
3364 (processing-type (plist-get info
:LaTeX-fragments
))
3365 (caption (org-element-property :caption latex-environment
))
3366 (short-caption (and (cdr caption
) (org-export-secondary-string
3367 (cdr caption
) 'e-odt info
)))
3368 (caption (and (car caption
) (org-export-secondary-string
3369 (car caption
) 'e-odt info
)))
3370 (label (org-element-property :name latex-environment
))
3372 (label (org-element-property :name latex-environment
)))
3374 ((member processing-type
'(t mathjax
))
3375 (org-e-odt-format-formula latex-environment info
))
3376 ((equal processing-type
'dvipng
)
3377 (org-e-odt-format-stylized-paragraph
3378 nil
(org-e-odt-link--inline-image latex-environment info
)))
3385 ;; (when latex-frag ; FIXME
3386 ;; (setq href (org-propertize href :title "LaTeX Fragment"
3387 ;; :description latex-frag)))
3389 ;; provide descriptions
3391 (defun org-e-odt-latex-fragment (latex-fragment contents info
)
3392 "Transcode a LATEX-FRAGMENT object from Org to HTML.
3393 CONTENTS is nil. INFO is a plist holding contextual information."
3394 (let* ((latex-frag (org-element-property :value latex-fragment
))
3395 (processing-type (plist-get info
:LaTeX-fragments
)))
3397 ((member processing-type
'(t mathjax
))
3398 (org-e-odt-format-formula latex-fragment info
))
3399 ((equal processing-type
'dvipng
)
3400 (org-e-odt-link--inline-image latex-fragment info
))
3406 (defun org-e-odt-line-break (line-break contents info
)
3407 "Transcode a LINE-BREAK object from Org to HTML.
3408 CONTENTS is nil. INFO is a plist holding contextual information."
3409 "<text:line-break/>\n")
3414 (defun org-e-odt-link--inline-image (element info
)
3415 "Return HTML code for an inline image.
3416 LINK is the link pointing to the inline image. INFO is a plist
3417 used as a communication channel."
3419 ((eq (org-element-type element
) 'link
)
3420 (let* ((type (org-element-property :type element
))
3421 (raw-path (org-element-property :path element
)))
3422 (cond ((member type
'("http" "https"))
3423 (concat type
":" raw-path
))
3424 ((file-name-absolute-p raw-path
)
3425 (expand-file-name raw-path
))
3427 ((member (org-element-type element
)
3428 '(latex-fragment latex-environment
))
3429 (let* ((latex-frag (org-remove-indentation
3430 (org-element-property
3432 (formula-link (org-e-odt-format-latex
3433 latex-frag
'dvipng
)))
3435 (string-match "file:\\([^]]*\\)" formula-link
)
3436 (match-string 1 formula-link
))))
3437 (t (error "what is this?"))))
3438 (href (org-e-odt-format-tags
3439 "<draw:image xlink:href=\"%s\" xlink:type=\"simple\" xlink:show=\"embed\" xlink:actuate=\"onLoad\"/>" ""
3440 (org-e-odt-copy-image-file src
)))
3441 ;; extract attributes from #+ATTR_ODT line.
3442 (attr-from (case (org-element-type element
)
3443 (link (org-export-get-parent-paragraph element info
))
3445 ;; convert attributes to a plist.
3446 (attr-plist (org-e-odt-element-attributes attr-from info
))
3447 ;; handle `:anchor', `:style' and `:attributes' properties.
3449 (car (assoc-string (plist-get attr-plist
:anchor
)
3450 '(("as-char") ("paragraph") ("page")) t
)))
3452 (and user-frame-anchor
(plist-get attr-plist
:style
)))
3454 (and user-frame-anchor
(plist-get attr-plist
:attributes
)))
3456 (list user-frame-style user-frame-attrs user-frame-anchor
))
3457 ;; (embed-as (or embed-as user-frame-anchor "paragraph"))
3459 ;; handle `:width', `:height' and `:scale' properties.
3460 (size (org-e-odt-image-size-from-file
3461 src
(plist-get attr-plist
:width
)
3462 (plist-get attr-plist
:height
)
3463 (plist-get attr-plist
:scale
) nil
;; embed-as
3466 (width (car size
)) (height (cdr size
))
3468 (case (org-element-type element
)
3469 ((org-e-odt-standalone-image-p element info
) "paragraph")
3470 (latex-fragment "as-char")
3471 (latex-environment "paragraph")
3473 (captions (org-e-odt-format-label element info
'definition
))
3474 (caption (car captions
)) (short-caption (cdr captions
))
3475 (entity (concat (and caption
"Captioned") embed-as
"Image")))
3476 (org-e-odt-format-entity entity href width height
3477 captions user-frame-params
)))
3479 (defun org-e-odt-format-entity (entity href width height
&optional
3480 captions user-frame-params
)
3481 (let* ((caption (car captions
)) (short-caption (cdr captions
))
3482 (entity-style (assoc-string entity org-e-odt-entity-frame-styles t
))
3483 default-frame-params frame-params
)
3486 (setq default-frame-params
(nth 2 entity-style
))
3487 (setq frame-params
(org-e-odt-merge-frame-params
3488 default-frame-params user-frame-params
))
3489 (apply 'org-e-odt-format-frame href width height frame-params
))
3491 (setq default-frame-params
(nth 3 entity-style
))
3492 (setq frame-params
(org-e-odt-merge-frame-params
3493 default-frame-params user-frame-params
))
3494 (apply 'org-e-odt-format-textbox
3495 (org-e-odt-format-stylized-paragraph
3498 (apply 'org-e-odt-format-frame href width height
3499 (let ((entity-style-1 (copy-sequence
3500 (nth 2 entity-style
))))
3501 (setcar (cdr entity-style-1
)
3503 (cadr entity-style-1
)
3505 (format " draw:name=\"%s\" "
3509 width height frame-params
)))))
3511 (defvar org-e-odt-standalone-image-predicate
3512 (function (lambda (paragraph)
3513 (or (org-element-property :caption paragraph
)
3514 (org-element-property :name paragraph
)))))
3516 (defun org-e-odt-standalone-image-p (element info
&optional predicate
)
3517 "Test if ELEMENT is a standalone image for the purpose ODT export.
3518 INFO is a plist holding contextual information.
3520 Return non-nil, if ELEMENT is of type paragraph and it's sole
3521 content, save for whitespaces, is a link that qualifies as an
3524 Return non-nil, if ELEMENT is of type link and it's containing
3525 paragraph has no other content save for leading and trailing
3528 Return nil, otherwise.
3530 Bind `org-e-odt-standalone-image-predicate' to constrain
3531 paragraph further. For example, to check for only captioned
3532 standalone images, do the following.
3534 \(setq org-e-odt-standalone-image-predicate
3535 \(lambda \(paragraph\)
3536 \(org-element-property :caption paragraph\)\)\)
3538 (let ((paragraph (case (org-element-type element
)
3540 (link (and (org-export-inline-image-p
3541 element org-e-odt-inline-image-rules
)
3542 (org-export-get-parent element info
)))
3545 (assert (eq (org-element-type paragraph
) 'paragraph
))
3546 (when (or (not (and (boundp 'org-e-odt-standalone-image-predicate
)
3547 (functionp org-e-odt-standalone-image-predicate
)))
3548 (funcall org-e-odt-standalone-image-predicate paragraph
))
3549 (let ((contents (org-element-contents paragraph
)))
3550 (loop for x in contents
3551 with inline-image-count
= 0
3553 ((eq (org-element-type x
) 'plain-text
)
3554 (not (org-string-nw-p x
)))
3555 ((eq (org-element-type x
) 'link
)
3556 (when (org-export-inline-image-p
3557 x org-e-odt-inline-image-rules
)
3558 (= (incf inline-image-count
) 1)))
3561 (defun org-e-odt-link (link desc info
)
3562 "Transcode a LINK object from Org to HTML.
3564 DESC is the description part of the link, or the empty string.
3565 INFO is a plist holding contextual information. See
3567 (let* ((type (org-element-property :type link
))
3568 (raw-path (org-element-property :path link
))
3569 ;; Ensure DESC really exists, or set it to nil.
3570 (desc (and (not (string= desc
"")) desc
))
3571 (imagep (org-export-inline-image-p
3572 link org-e-odt-inline-image-rules
))
3574 ((member type
'("http" "https" "ftp" "mailto"))
3575 (concat type
":" raw-path
))
3576 ((string= type
"file")
3577 (when (string-match "\\(.+\\)::.+" raw-path
)
3578 (setq raw-path
(match-string 1 raw-path
)))
3579 (if (file-name-absolute-p raw-path
)
3580 (concat "file://" (expand-file-name raw-path
))
3581 ;; TODO: Not implemented yet. Concat also:
3582 ;; (org-export-directory :HTML info)
3583 (concat "file://" raw-path
)))
3588 ((and (not desc
) (org-export-inline-image-p
3589 link org-e-odt-inline-image-rules
))
3590 (org-e-odt-link--inline-image link info
))
3591 ;; Radioed target: Target's name is obtained from original raw
3592 ;; link. Path is parsed and transcoded in order to have a proper
3593 ;; display of the contents.
3594 ((string= type
"radio")
3595 (org-e-odt-format-internal-link
3596 (org-export-secondary-string
3597 (org-element-parse-secondary-string
3598 path
(cdr (assq 'radio-target org-element-object-restrictions
)))
3600 (org-export-solidify-link-text path
)))
3601 ;; Links pointing to an headline: Find destination and build
3602 ;; appropriate referencing command.
3603 ((member type
'("custom-id" "fuzzy" "id"))
3604 (let ((destination (if (string= type
"fuzzy")
3605 (org-export-resolve-fuzzy-link link info
)
3606 (org-export-resolve-id-link link info
))))
3607 (case (org-element-type destination
)
3608 ;; Fuzzy link points nowhere.
3610 (org-e-odt-format-fontify
3611 (or desc
(org-export-secondary-string
3612 (org-element-property :raw-link link
)
3613 'e-odt info
)) 'emphasis
))
3614 ;; Fuzzy link points to an invisible target.
3616 ;; LINK points to an headline. If headlines are numbered
3617 ;; and the link has no description, display headline's
3618 ;; number. Otherwise, display description or headline's
3621 (let* ((headline-no (org-export-get-headline-number destination info
))
3622 (label (format "sec-%s" (mapconcat 'number-to-string
3624 (section-no (mapconcat 'number-to-string headline-no
".")))
3628 ((plist-get info
:section-numbers
) section-no
)
3629 (t (org-export-secondary-string
3630 (org-element-property :title destination
)
3632 (org-e-odt-format-internal-link desc label
)))
3633 ;; Fuzzy link points to a target. Do as above.
3636 ;; (setq number (cond
3637 ;; ((org-e-odt-standalone-image-p destination info)
3638 ;; (org-export-get-ordinal
3639 ;; (assoc 'link (org-element-contents destination))
3640 ;; info 'link 'org-e-odt-standalone-image-p))
3641 ;; (t (org-export-get-ordinal destination info))))
3642 ;; (setq desc (when number
3643 ;; (if (atom number) (number-to-string number)
3644 ;; (mapconcat 'number-to-string number ".")))))
3646 (let ((label-reference
3647 (org-e-odt-format-label destination info
'reference
)))
3648 (assert label-reference
)
3649 label-reference
)))))
3650 ;; Coderef: replace link with the reference name or the
3651 ;; equivalent line number.
3652 ((string= type
"coderef")
3653 (let* ((fmt (org-export-get-coderef-format path
(or desc
"%s")))
3654 (res (org-export-resolve-coderef path info
))
3655 (org-e-odt-suppress-xref nil
)
3656 (href (org-xml-format-href (concat "#coderef-" path
))))
3657 (format fmt
(org-e-odt-format-link res href
))))
3658 ;; Link type is handled by a special function.
3659 ((functionp (setq protocol
(nth 2 (assoc type org-link-protocols
))))
3660 (funcall protocol
(org-link-unescape path
) desc
'html
))
3661 ;; External link with a description part.
3662 ((and path desc
) (org-e-odt-format-link desc path
))
3663 ;; External link without a description part.
3664 (path (org-e-odt-format-link path path
))
3665 ;; No path, only description. Try to do something useful.
3666 (t (org-e-odt-format-fontify desc
'emphasis
)))))
3671 ;; Babel Calls are ignored.
3676 (defun org-e-odt-macro (macro contents info
)
3677 "Transcode a MACRO element from Org to HTML.
3678 CONTENTS is nil. INFO is a plist holding contextual information."
3679 ;; Use available tools.
3680 (org-export-expand-macro macro info
))
3685 (defun org-e-odt-paragraph (paragraph contents info
)
3686 "Transcode a PARAGRAPH element from Org to HTML.
3687 CONTENTS is the contents of the paragraph, as a string. INFO is
3688 the plist used as a communication channel."
3689 (let* ((style nil
) ; FIXME
3690 (class (cdr (assoc style
'((footnote .
"footnote")
3692 (extra (if class
(format " class=\"%s\"" class
) ""))
3693 (parent (org-export-get-parent paragraph info
))
3694 (parent-type (org-element-type parent
))
3695 (style (case parent-type
3696 (quote-block 'quote
)
3697 (center-block 'center
)
3698 (footnote-definition 'footnote
)
3700 (org-e-odt-format-stylized-paragraph style contents
)))
3705 (defun org-e-odt-plain-list (plain-list contents info
)
3706 "Transcode a PLAIN-LIST element from Org to HTML.
3707 CONTENTS is the contents of the list. INFO is a plist holding
3708 contextual information."
3709 (let* (arg1 ;; FIXME
3710 (type (org-element-property :type plain-list
))
3711 (attr (mapconcat #'identity
3712 (org-element-property :attr_odt plain-list
)
3714 (org-e-odt--wrap-label
3715 plain-list
(format "%s\n%s%s"
3716 (org-e-odt-begin-plain-list type
)
3717 contents
(org-e-odt-end-plain-list type
)))))
3721 (defun org-e-odt-convert-special-strings (string)
3722 "Convert special characters in STRING to ODT."
3723 (let ((all org-e-odt-special-string-regexps
)
3725 (while (setq a
(pop all
))
3726 (setq re
(car a
) rpl
(cdr a
) start
0)
3727 (while (string-match re string start
)
3728 (setq string
(replace-match rpl t nil string
))))
3731 ;; (defun org-e-odt-encode-plain-text (s)
3732 ;; "Convert plain text characters to HTML equivalent.
3733 ;; Possible conversions are set in `org-export-html-protect-char-alist'."
3734 ;; (let ((cl org-e-odt-protect-char-alist) c)
3735 ;; (while (setq c (pop cl))
3737 ;; (while (string-match (car c) s start)
3738 ;; (setq s (replace-match (cdr c) t t s)
3739 ;; start (1+ (match-beginning 0))))))
3742 (defun org-e-odt-plain-text (text info
)
3743 "Transcode a TEXT string from Org to HTML.
3744 TEXT is the string to transcode. INFO is a plist holding
3745 contextual information."
3746 (setq text
(org-e-odt-encode-plain-text text t
))
3747 ;; Protect %, #, &, $, ~, ^, _, { and }.
3748 ;; (while (string-match "\\([^\\]\\|^\\)\\([%$#&{}~^_]\\)" text)
3750 ;; (replace-match (format "\\%s" (match-string 2 text)) nil t text 2)))
3752 ;; (setq text (replace-regexp-in-string
3753 ;; "\\(?:[^\\]\\|^\\)\\(\\\\\\)\\(?:[^%$#&{}~^_\\]\\|$\\)"
3754 ;; "$\\backslash$" text nil t 1))
3755 ;; HTML into \HTML{} and TeX into \TeX{}.
3756 ;; (let ((case-fold-search nil)
3758 ;; (while (string-match "\\<\\(\\(?:La\\)?TeX\\)\\>" text start)
3759 ;; (setq text (replace-match
3760 ;; (format "\\%s{}" (match-string 1 text)) nil t text)
3761 ;; start (match-end 0))))
3762 ;; Handle quotation marks
3763 ;; (setq text (org-e-odt--quotation-marks text info))
3764 ;; Convert special strings.
3765 ;; (when (plist-get info :with-special-strings)
3766 ;; (while (string-match (regexp-quote "...") text)
3767 ;; (setq text (replace-match "\\ldots{}" nil t text))))
3768 (when (plist-get info
:with-special-strings
)
3769 (setq text
(org-e-odt-convert-special-strings text
)))
3770 ;; Handle break preservation if required.
3771 (when (plist-get info
:preserve-breaks
)
3772 (setq text
(replace-regexp-in-string "\\(\\\\\\\\\\)?[ \t]*\n" " \\\\\\\\\n"
3778 ;;;; Property Drawer
3780 (defun org-e-odt-property-drawer (property-drawer contents info
)
3781 "Transcode a PROPERTY-DRAWER element from Org to HTML.
3782 CONTENTS is nil. INFO is a plist holding contextual
3784 ;; The property drawer isn't exported but we want separating blank
3785 ;; lines nonetheless.
3791 (defun org-e-odt-quote-block (quote-block contents info
)
3792 "Transcode a QUOTE-BLOCK element from Org to HTML.
3793 CONTENTS holds the contents of the block. INFO is a plist
3794 holding contextual information."
3795 (org-e-odt--wrap-label quote-block contents
))
3800 (defun org-e-odt-quote-section (quote-section contents info
)
3801 "Transcode a QUOTE-SECTION element from Org to HTML.
3802 CONTENTS is nil. INFO is a plist holding contextual information."
3803 (let ((value (org-remove-indentation
3804 (org-element-property :value quote-section
))))
3805 (when value
(org-e-odt-format-source-code-or-example value nil
))))
3810 (defun org-e-odt-section (section contents info
) ; FIXME
3811 "Transcode a SECTION element from Org to HTML.
3812 CONTENTS holds the contents of the section. INFO is a plist
3813 holding contextual information."
3818 (defun org-e-odt-radio-target (radio-target text info
)
3819 "Transcode a RADIO-TARGET object from Org to HTML.
3820 TEXT is the text of the target. INFO is a plist holding
3821 contextual information."
3822 (org-e-odt-format-anchor
3823 text
(org-export-solidify-link-text
3824 (org-element-property :value radio-target
))))
3829 (defun org-e-odt-special-block (special-block contents info
)
3830 "Transcode a SPECIAL-BLOCK element from Org to HTML.
3831 CONTENTS holds the contents of the block. INFO is a plist
3832 holding contextual information."
3833 (let ((type (downcase (org-element-property :type special-block
))))
3834 (org-e-odt--wrap-label
3836 (format "\\begin{%s}\n%s\\end{%s}" type contents type
))))
3841 (defun org-e-odt-src-block (src-block contents info
)
3842 "Transcode a SRC-BLOCK element from Org to HTML.
3843 CONTENTS holds the contents of the item. INFO is a plist holding
3844 contextual information."
3845 (let* ((lang (org-element-property :language src-block
))
3846 (caption (org-element-property :caption src-block
))
3847 (short-caption (and (cdr caption
) (org-export-secondary-string
3848 (cdr caption
) 'e-odt info
)))
3849 (caption (and (car caption
) (org-export-secondary-string
3850 (car caption
) 'e-odt info
)))
3851 (label (org-element-property :name src-block
)))
3852 ;; FIXME: Handle caption
3853 ;; caption-str (when caption)
3854 ;; (main (org-export-secondary-string (car caption) 'e-odt info))
3855 ;; (secondary (org-export-secondary-string (cdr caption) 'e-odt info))
3856 ;; (caption-str (org-e-odt--caption/label-string caption label info))
3857 (let* ((captions (org-e-odt-format-label src-block info
'definition
))
3858 (caption (car captions
)) (short-caption (cdr captions
)))
3860 (and caption
(org-e-odt-format-stylized-paragraph 'listing caption
))
3861 (org-e-odt-format-code src-block info
)))))
3864 ;;;; Statistics Cookie
3866 (defun org-e-odt-statistics-cookie (statistics-cookie contents info
)
3867 "Transcode a STATISTICS-COOKIE object from Org to HTML.
3868 CONTENTS is nil. INFO is a plist holding contextual information."
3869 (let ((cookie-value (org-element-property :value statistics-cookie
)))
3870 (org-e-odt-format-fontify cookie-value
'code
)))
3875 (defun org-e-odt-subscript (subscript contents info
)
3876 "Transcode a SUBSCRIPT object from Org to HTML.
3877 CONTENTS is the contents of the object. INFO is a plist holding
3878 contextual information."
3879 ;; (format (if (= (length contents) 1) "$_%s$" "$_{\\mathrm{%s}}$") contents)
3880 (org-e-odt-format-fontify contents
'subscript
))
3885 (defun org-e-odt-superscript (superscript contents info
)
3886 "Transcode a SUPERSCRIPT object from Org to HTML.
3887 CONTENTS is the contents of the object. INFO is a plist holding
3888 contextual information."
3889 ;; (format (if (= (length contents) 1) "$^%s$" "$^{\\mathrm{%s}}$") contents)
3890 (org-e-odt-format-fontify contents
'superscript
))
3895 (defun org-e-odt-table-style-spec (element info
)
3896 (let* ((table (org-export-get-parent-table element info
))
3897 (table-attributes (org-e-odt-element-attributes table info
))
3898 (table-style (plist-get table-attributes
:style
)))
3899 (assoc table-style org-e-odt-table-styles
)))
3901 (defun org-e-odt-get-table-cell-styles (table-cell info
)
3902 "Retrieve styles applicable to a table cell.
3903 R and C are (zero-based) row and column numbers of the table
3904 cell. STYLE-SPEC is an entry in `org-e-odt-table-styles'
3905 applicable to the current table. It is `nil' if the table is not
3906 associated with any style attributes.
3908 Return a cons of (TABLE-CELL-STYLE-NAME . PARAGRAPH-STYLE-NAME).
3910 When STYLE-SPEC is nil, style the table cell the conventional way
3911 - choose cell borders based on row and column groupings and
3912 choose paragraph alignment based on `org-col-cookies' text
3914 `org-e-odt-get-paragraph-style-cookie-for-table-cell'.
3916 When STYLE-SPEC is non-nil, ignore the above cookie and return
3917 styles congruent with the ODF-1.2 specification."
3918 (let* ((table-cell-address (org-export-table-cell-address table-cell info
))
3919 (r (car table-cell-address
)) (c (cdr table-cell-address
))
3920 (style-spec (org-e-odt-table-style-spec table-cell info
))
3921 (table-dimensions (org-export-table-dimensions
3922 (org-export-get-parent-table table-cell info
)
3925 ;; LibreOffice - particularly the Writer - honors neither table
3926 ;; templates nor custom table-cell styles. Inorder to retain
3927 ;; inter-operability with LibreOffice, only automatic styles are
3928 ;; used for styling of table-cells. The current implementation is
3929 ;; congruent with ODF-1.2 specification and hence is
3930 ;; future-compatible.
3932 ;; Additional Note: LibreOffice's AutoFormat facility for tables -
3933 ;; which recognizes as many as 16 different cell types - is much
3934 ;; richer. Unfortunately it is NOT amenable to easy configuration
3936 (let* ((template-name (nth 1 style-spec
))
3937 (cell-style-selectors (nth 2 style-spec
))
3940 ((and (cdr (assoc 'use-first-column-styles cell-style-selectors
))
3941 (= c
0)) "FirstColumn")
3942 ((and (cdr (assoc 'use-last-column-styles cell-style-selectors
))
3943 (= (1+ c
) (cdr table-dimensions
)))
3945 ((and (cdr (assoc 'use-first-row-styles cell-style-selectors
))
3946 (= r
0)) "FirstRow")
3947 ((and (cdr (assoc 'use-last-row-styles cell-style-selectors
))
3948 (= (1+ r
) (car table-dimensions
)))
3950 ((and (cdr (assoc 'use-banding-rows-styles cell-style-selectors
))
3951 (= (% r
2) 1)) "EvenRow")
3952 ((and (cdr (assoc 'use-banding-rows-styles cell-style-selectors
))
3953 (= (% r
2) 0)) "OddRow")
3954 ((and (cdr (assoc 'use-banding-columns-styles cell-style-selectors
))
3955 (= (% c
2) 1)) "EvenColumn")
3956 ((and (cdr (assoc 'use-banding-columns-styles cell-style-selectors
))
3957 (= (% c
2) 0)) "OddColumn")
3959 (concat template-name cell-type
)))))
3961 (defun org-e-odt-table-cell (table-cell contents info
)
3962 "Transcode a TABLE-CELL element from Org to ODT.
3963 CONTENTS is nil. INFO is a plist used as a communication
3965 (let* ((value (org-export-secondary-string
3966 (org-element-property :value table-cell
) 'e-odt info
))
3968 (table-cell-address (org-export-table-cell-address table-cell info
))
3969 (r (car table-cell-address
))
3970 (c (cdr table-cell-address
))
3971 (horiz-span (or (org-export-table-cell-width table-cell info
) 0))
3972 (table-row (org-export-get-parent table-cell info
))
3973 (custom-style-prefix (org-e-odt-get-table-cell-styles
3977 (and custom-style-prefix
3978 (format "%sTableParagraph" custom-style-prefix
))
3981 ((and (= 1 (org-export-table-row-group table-row info
))
3982 (org-export-table-has-header-p
3983 (org-export-get-parent-table table-row info
) info
))
3985 ((and (zerop c
) t
;; (org-lparse-get 'TABLE-FIRST-COLUMN-AS-LABELS)
3988 (t "OrgTableContents"))
3989 (capitalize (symbol-name (org-export-table-cell-alignment
3990 table-cell info
))))))
3993 (and custom-style-prefix
(format "%sTableCell"
3994 custom-style-prefix
))
3997 (when (or (org-export-table-row-starts-rowgroup-p table-row info
)
3999 (when (org-export-table-row-ends-rowgroup-p table-row info
) "B")
4000 (when (and (org-export-table-cell-starts-colgroup-p table-cell info
)
4001 (not (zerop c
)) ) "L"))))
4004 (format " table:style-name=\"%s\"" cell-style-name
)
4005 (and (> horiz-span
0)
4006 (format " table:number-columns-spanned=\"%d\""
4007 (1+ horiz-span
))))))
4009 (org-e-odt-format-tags
4010 '("<table:table-cell%s>" .
"</table:table-cell>")
4011 (org-e-odt-format-stylized-paragraph paragraph-style value
) cell-attributes
)
4013 (dotimes (i horiz-span s
)
4014 (setq s
(concat s
"\n<table:covered-table-cell/>"))))
4020 (defun org-e-odt-table-row (table-row contents info
)
4021 "Transcode a TABLE-ROW element from Org to ODT.
4022 CONTENTS is the contents of the row. INFO is a plist used as a
4023 communication channel."
4024 ;; Rules are ignored since table separators are deduced from
4025 ;; borders of the current row.
4026 (when (eq (org-element-property :type table-row
) 'standard
)
4027 (let* ((rowgroup-tags
4028 (if (and (= 1 (org-export-table-row-group table-row info
))
4029 (org-export-table-has-header-p
4030 (org-export-get-parent-table table-row info
) info
))
4031 ;; If the row belongs to the first rowgroup and the
4032 ;; table has more than one row groups, then this row
4033 ;; belongs to the header row group.
4034 '("\n<table:table-header-rows>" .
"\n</table:table-header-rows>")
4035 ;; Otherwise, it belongs to non-header row group.
4036 '("\n<table:table-rows>" .
"\n</table:table-rows>"))))
4038 ;; Does this row begin a rowgroup?
4039 (when (org-export-table-row-starts-rowgroup-p table-row info
)
4040 (car rowgroup-tags
))
4042 (org-e-odt-format-tags
4043 '("<table:table-row>" .
"</table:table-row>") contents
)
4044 ;; Does this row end a rowgroup?
4045 (when (org-export-table-row-ends-rowgroup-p table-row info
)
4046 (cdr rowgroup-tags
))))))
4051 (defun org-e-odt-table (table contents info
)
4052 "Transcode a TABLE element from Org to HTML.
4053 CONTENTS is nil. INFO is a plist holding contextual information."
4054 (case (org-element-property :type table
)
4057 (let* ((captions (org-e-odt-format-label table info
'definition
))
4058 (caption (car captions
)) (short-caption (cdr captions
))
4059 (attributes (org-e-odt-element-attributes table info
))
4060 (custom-table-style (nth 1 (org-e-odt-table-style-spec table info
)))
4063 (lambda (table info
)
4064 (let* ((table-style (or custom-table-style
"OrgTable"))
4065 (column-style (format "%sColumn" table-style
)))
4067 (lambda (table-column-properties)
4068 (let ((width (1+ (or (plist-get table-column-properties
4070 (org-e-odt-make-string
4072 (org-e-odt-format-tags
4073 "<table:table-column table:style-name=\"%s\"/>"
4075 (org-export-table-column-properties table info
) "\n"))))))
4078 (when caption
(org-e-odt-format-stylized-paragraph 'table caption
))
4080 (let* ((automatic-name
4081 (org-e-odt-add-automatic-style "Table" attributes
)))
4083 "\n<table:table table:name=\"%s\" table:style-name=\"%s\">\n"
4084 (or short-caption
(car automatic-name
))
4085 (or custom-table-style
(cdr automatic-name
) "OrgTable")))
4086 ;; column specification.
4087 (funcall table-column-specs table info
)
4091 "</table:table>")))))
4096 (defun org-e-odt-target (target contents info
)
4097 "Transcode a TARGET object from Org to HTML.
4098 CONTENTS is nil. INFO is a plist holding contextual
4100 (org-e-odt-format-anchor
4101 "" (org-export-solidify-link-text (org-element-property :value target
))))
4106 (defun org-e-odt-time-stamp (time-stamp contents info
)
4107 "Transcode a TIME-STAMP object from Org to HTML.
4108 CONTENTS is nil. INFO is a plist holding contextual
4110 ;; (let ((value (org-element-property :value time-stamp))
4111 ;; (type (org-element-property :type time-stamp))
4112 ;; (appt-type (org-element-property :appt-type time-stamp)))
4113 ;; (concat (cond ((eq appt-type 'scheduled)
4114 ;; (format "\\textbf{\\textsc{%s}} " org-scheduled-string))
4115 ;; ((eq appt-type 'deadline)
4116 ;; (format "\\textbf{\\textsc{%s}} " org-deadline-string))
4117 ;; ((eq appt-type 'closed)
4118 ;; (format "\\textbf{\\textsc{%s}} " org-closed-string)))
4119 ;; (cond ((memq type '(active active-range))
4120 ;; (format org-e-odt-active-timestamp-format value))
4121 ;; ((memq type '(inactive inactive-range))
4122 ;; (format org-e-odt-inactive-timestamp-format value))
4124 ;; (format org-e-odt-diary-timestamp-format value)))))
4125 (let ((value (org-element-property :value time-stamp
))
4126 (type (org-element-property :type time-stamp
))
4127 (appt-type (org-element-property :appt-type time-stamp
)))
4128 (setq value
(org-export-secondary-string value
'e-odt info
))
4129 (org-e-odt-format-fontify
4131 (org-e-odt-format-fontify
4132 (cond ((eq appt-type
'scheduled
) org-scheduled-string
)
4133 ((eq appt-type
'deadline
) org-deadline-string
)
4134 ((eq appt-type
'closed
) org-closed-string
)) "timestamp-kwd")
4135 ;; FIXME: (org-translate-time value)
4136 (org-e-odt-format-fontify value
"timestamp"))
4137 "timestamp-wrapper")))
4142 (defun org-e-odt-verbatim (verbatim contents info
)
4143 "Transcode a VERBATIM object from Org to HTML.
4144 CONTENTS is nil. INFO is a plist used as a communication
4147 verbatim
(org-element-property :value verbatim
) info
))
4152 (defun org-e-odt-verse-block (verse-block contents info
)
4153 "Transcode a VERSE-BLOCK element from Org to HTML.
4154 CONTENTS is nil. INFO is a plist holding contextual information."
4155 ;; Replace each newline character with line break. Also replace
4156 ;; each blank line with a line break.
4157 (setq contents
(replace-regexp-in-string
4158 "^ *\\\\\\\\$" "<br/>\n"
4159 (replace-regexp-in-string
4160 "\\(\\\\\\\\\\)?[ \t]*\n" " <br/>\n"
4161 (org-remove-indentation
4162 (org-export-secondary-string
4163 (org-element-property :value verse-block
)
4166 ;; Replace each white space at beginning of a line with a
4167 ;; non-breaking space.
4168 (while (string-match "^[ \t]+" contents
)
4169 (let ((new-str (org-e-odt-format-spaces
4170 (length (match-string 0 contents
)))))
4171 (setq contents
(replace-match new-str nil t contents
))))
4173 (org-e-odt--wrap-label
4174 verse-block
(format "<p class=\"verse\">\n%s</p>" contents
)))
4179 ;;; Filter Functions
4181 ;;;; Filter Settings
4184 ;;; Interactive functions
4186 (defun org-e-odt-export-to-odt
4187 (&optional subtreep visible-only body-only ext-plist pub-dir
)
4188 "Export current buffer to a HTML file.
4190 If narrowing is active in the current buffer, only export its
4193 If a region is active, export that region.
4195 When optional argument SUBTREEP is non-nil, export the sub-tree
4196 at point, extracting information from the headline properties
4199 When optional argument VISIBLE-ONLY is non-nil, don't export
4200 contents of hidden elements.
4202 When optional argument BODY-ONLY is non-nil, only write code
4203 between \"\\begin{document}\" and \"\\end{document}\".
4205 EXT-PLIST, when provided, is a property list with external
4206 parameters overriding Org default settings, but still inferior to
4207 file-local settings.
4209 When optional argument PUB-DIR is set, use it as the publishing
4212 Return output file's name."
4214 (setq debug-on-error t
)
4216 ;; (let* ((outfile (org-export-output-file-name ".html" subtreep pub-dir))
4217 ;; (outfile "content.xml"))
4218 ;; (org-export-to-file
4219 ;; 'e-odt outfile subtreep visible-only body-only ext-plist))
4221 (let* ((outbuf (org-e-odt-init-outfile))
4222 (target (org-export-output-file-name ".odt" subtreep pub-dir
))
4223 (outdir (file-name-directory (buffer-file-name outbuf
)))
4224 (default-directory outdir
))
4226 ;; FIXME: for copying embedded images
4227 (setq org-current-export-file
4228 (file-name-directory
4229 (org-export-output-file-name ".odt" subtreep nil
)))
4231 (org-export-to-buffer
4233 (memq 'subtree optns
) (memq 'visible optns
) (memq 'body optns
))
4235 (setq org-lparse-opt-plist nil
) ; FIXME
4236 (org-e-odt-save-as-outfile target
;; info
4241 (if (not org-e-odt-preferred-output-format
) target
4242 (or (org-e-odt-convert target org-e-odt-preferred-output-format
)
4249 (defun org-e-odt-reachable-p (in-fmt out-fmt
)
4250 "Return non-nil if IN-FMT can be converted to OUT-FMT."
4252 (let ((reachable-formats (org-e-odt-do-reachable-formats in-fmt
)))
4253 (dolist (e reachable-formats
)
4254 (let ((out-fmt-spec (assoc out-fmt
(cdr e
))))
4256 (throw 'done
(cons (car e
) out-fmt-spec
))))))))
4258 (defun org-e-odt-do-convert (in-file out-fmt
&optional prefix-arg
)
4259 "Workhorse routine for `org-e-odt-convert'."
4260 (require 'browse-url
)
4261 (let* ((in-file (expand-file-name (or in-file buffer-file-name
)))
4262 (dummy (or (file-readable-p in-file
)
4263 (error "Cannot read %s" in-file
)))
4264 (in-fmt (file-name-extension in-file
))
4265 (out-fmt (or out-fmt
(error "Output format unspecified")))
4266 (how (or (org-e-odt-reachable-p in-fmt out-fmt
)
4267 (error "Cannot convert from %s format to %s format?"
4269 (convert-process (car how
))
4270 (out-file (concat (file-name-sans-extension in-file
) "."
4271 (nth 1 (or (cdr how
) out-fmt
))))
4272 (extra-options (or (nth 2 (cdr how
)) ""))
4273 (out-dir (file-name-directory in-file
))
4274 (cmd (format-spec convert-process
4275 `((?i .
,(shell-quote-argument in-file
))
4276 (?I .
,(browse-url-file-url in-file
))
4279 (?O .
,(browse-url-file-url out-file
))
4280 (?d .
, (shell-quote-argument out-dir
))
4281 (?D .
,(browse-url-file-url out-dir
))
4282 (?x .
,extra-options
)))))
4283 (when (file-exists-p out-file
)
4284 (delete-file out-file
))
4286 (message "Executing %s" cmd
)
4287 (let ((cmd-output (shell-command-to-string cmd
)))
4288 (message "%s" cmd-output
))
4291 ((file-exists-p out-file
)
4292 (message "Exported to %s" out-file
)
4294 (message "Opening %s..." out-file
)
4295 (org-open-file out-file
))
4298 (message "Export to %s failed" out-file
)
4301 (defun org-e-odt-do-reachable-formats (in-fmt)
4302 "Return verbose info about formats to which IN-FMT can be converted.
4303 Return a list where each element is of the
4304 form (CONVERTER-PROCESS . OUTPUT-FMT-ALIST). See
4305 `org-e-odt-convert-processes' for CONVERTER-PROCESS and see
4306 `org-e-odt-convert-capabilities' for OUTPUT-FMT-ALIST."
4308 (and org-e-odt-convert-process
4309 (cadr (assoc-string org-e-odt-convert-process
4310 org-e-odt-convert-processes t
))))
4312 (and org-e-odt-convert-process
4313 (cadr (assoc-string org-e-odt-convert-process
4314 org-e-odt-convert-processes t
))
4315 org-e-odt-convert-capabilities
))
4318 (dolist (c capabilities
)
4319 (when (member in-fmt
(nth 1 c
))
4320 (push (cons converter
(nth 2 c
)) reachable-formats
))))
4323 (defun org-e-odt-reachable-formats (in-fmt)
4324 "Return list of formats to which IN-FMT can be converted.
4325 The list of the form (OUTPUT-FMT-1 OUTPUT-FMT-2 ...)."
4327 (mapc (lambda (e) (add-to-list 'l e
))
4328 (apply 'append
(mapcar
4329 (lambda (e) (mapcar 'car
(cdr e
)))
4330 (org-e-odt-do-reachable-formats in-fmt
))))
4333 (defun org-e-odt-convert-read-params ()
4334 "Return IN-FILE and OUT-FMT params for `org-e-odt-do-convert'.
4335 This is a helper routine for interactive use."
4336 (let* ((input (if (featurep 'ido
) 'ido-completing-read
'completing-read
))
4337 (in-file (read-file-name "File to be converted: "
4338 nil buffer-file-name t
))
4339 (in-fmt (file-name-extension in-file
))
4340 (out-fmt-choices (org-e-odt-reachable-formats in-fmt
))
4342 (or (and out-fmt-choices
4343 (funcall input
"Output format: "
4344 out-fmt-choices nil nil nil
))
4346 "No known converter or no known output formats for %s files"
4348 (list in-file out-fmt
)))
4351 (defun org-e-odt-convert (&optional in-file out-fmt prefix-arg
)
4352 "Convert IN-FILE to format OUT-FMT using a command line converter.
4353 IN-FILE is the file to be converted. If unspecified, it defaults
4354 to variable `buffer-file-name'. OUT-FMT is the desired output
4355 format. Use `org-e-odt-convert-process' as the converter.
4356 If PREFIX-ARG is non-nil then the newly converted file is opened
4357 using `org-open-file'."
4359 (append (org-e-odt-convert-read-params) current-prefix-arg
))
4360 (org-e-odt-do-convert in-file out-fmt prefix-arg
))
4362 ;;; FIXMES, TODOS, FOR REVIEW etc
4364 ;; (defun org-e-odt-discontinue-list ()
4365 ;; (let ((stashed-stack org-lparse-list-stack))
4366 ;; (loop for list-type in stashed-stack
4367 ;; do (org-lparse-end-list-item-1 list-type)
4368 ;; (org-lparse-end-list list-type))
4369 ;; (setq org-e-odt-list-stack-stashed stashed-stack)))
4371 ;; (defun org-e-odt-continue-list ()
4372 ;; (setq org-e-odt-list-stack-stashed (nreverse org-e-odt-list-stack-stashed))
4373 ;; (loop for list-type in org-e-odt-list-stack-stashed
4374 ;; do (org-lparse-begin-list list-type)
4375 ;; (org-lparse-begin-list-item list-type)))
4377 ;; FIXME: Begin indented table
4378 ;; (setq org-e-odt-table-indentedp (not (null org-lparse-list-stack)))
4379 ;; (setq org-e-odt-table-indentedp nil) ; FIXME
4380 ;; (when org-e-odt-table-indentedp
4381 ;; ;; Within the Org file, the table is appearing within a list item.
4382 ;; ;; OpenDocument doesn't allow table to appear within list items.
4383 ;; ;; Temporarily terminate the list, emit the table and then
4384 ;; ;; re-continue the list.
4385 ;; (org-e-odt-discontinue-list)
4386 ;; ;; Put the Table in an indented section.
4387 ;; (let ((level (length org-e-odt-list-stack-stashed)))
4388 ;; (org-e-odt-begin-section (format "OrgIndentedSection-Level-%d" level))))
4390 ;; FIXME: End indented table
4391 ;; (when org-e-odt-table-indentedp
4392 ;; (org-e-odt-end-section)
4393 ;; (org-e-odt-continue-list))
4396 ;;;; org-format-table-html
4397 ;;;; org-format-org-table-html
4398 ;;;; org-format-table-table-html
4399 ;;;; org-table-number-fraction
4400 ;;;; org-table-number-regexp
4401 ;;;; org-e-odt-table-caption-above
4404 ;;;; "<span style=\"visibility:hidden;\">%s</span>"
4405 ;;;; Remove display properties
4407 ;;;; org-e-odt-with-timestamp
4408 ;;;; org-e-odt-html-helper-timestamp
4410 ;;;; org-export-as-html-and-open
4411 ;;;; org-export-as-html-batch
4412 ;;;; org-export-as-html-to-buffer
4413 ;;;; org-replace-region-by-html
4414 ;;;; org-export-region-as-html
4415 ;;;; org-export-as-html
4417 ;;;; (org-export-directory :html opt-plist)
4418 ;;;; (plist-get opt-plist :html-extension)
4419 ;;;; org-e-odt-toplevel-hlevel
4420 ;;;; org-e-odt-coding-system
4421 ;;;; org-e-odt-coding-system
4422 ;;;; org-e-odt-inline-image-extensions
4423 ;;;; org-e-odt-protect-char-alist
4424 ;;;; org-e-odt-table-use-header-tags-for-first-column
4425 ;;;; org-e-odt-todo-kwd-class-prefix
4426 ;;;; org-e-odt-tag-class-prefix
4427 ;;;; org-e-odt-footnote-separator
4430 ;;; Library Initializations
4434 ;; Let Org open all OpenDocument files using system-registered app
4435 (add-to-list 'org-file-apps
4436 (cons (concat "\\." (car desc
) "\\'") 'system
))
4437 ;; Let Emacs open all OpenDocument files in archive mode
4438 (add-to-list 'auto-mode-alist
4439 (cons (concat "\\." (car desc
) "\\'") 'archive-mode
)))
4440 org-e-odt-file-extensions
)
4442 (defvar org-e-odt-display-outline-level
2)
4443 (defun org-e-odt-enumerate-element (element info
&optional predicate n
)
4444 (let* ((numbered-parent-headline-at-<=-n
4446 (lambda (element n info
)
4447 (loop for x in
(org-export-get-genealogy element info
)
4448 thereis
(and (eq (org-element-type x
) 'headline
)
4449 (<= (org-export-get-relative-level x info
) n
)
4450 (org-export-numbered-headline-p x info
)
4454 (lambda (element scope info
&optional predicate
)
4457 (or scope
(plist-get info
:parse-tree
))
4458 (org-element-type element
)
4460 (and (or (not predicate
) (funcall predicate el info
))
4464 info
'first-match
)))))
4465 (scope (funcall numbered-parent-headline-at-
<=-n
4466 element
(or n org-e-odt-display-outline-level
) info
))
4467 (ordinal (funcall enumerate element scope info predicate
))
4472 (mapconcat 'number-to-string
4473 (org-export-get-headline-number scope info
) "."))
4477 (number-to-string ordinal
))))
4478 ;; (message "%s:\t%s" (org-element-property :name element) tag)
4481 (provide 'org-e-odt
)
4483 ;;; org-e-odt.el ends here