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-data (plist-get info
:title
) info
))
51 (author (and (plist-get info
:with-author
)
52 (let ((auth (plist-get info
:author
)))
53 (and auth
(org-export-data auth info
)))))
54 (date (plist-get info
:date
))
55 (iso-date (org-e-odt-format-date date
))
56 (date (org-e-odt-format-date date
"%d %b %Y"))
57 (email (plist-get info
:email
))
58 ;; switch on or off above vars based on user settings
59 (author (and (plist-get info
:with-author
) (or author email
)))
60 ;; (date (and (plist-get info :time-stamp-file) date))
61 (email (and (plist-get info
:with-email
) email
)))
66 (org-e-odt-format-stylized-paragraph
67 'title
(format "\n<text:title>%s</text:title>" title
))
69 "\n<text:p text:style-name=\"OrgTitle\"/>"))
71 ((and author
(not email
))
74 (org-e-odt-format-stylized-paragraph
76 (format "<text:initial-creator>%s</text:initial-creator>" author
))
78 "\n<text:p text:style-name=\"OrgSubtitle\"/>"))
82 (org-e-odt-format-stylized-paragraph
84 (org-e-odt-format-link
85 (format "<text:initial-creator>%s</text:initial-creator>" author
)
86 (concat "mailto:" email
)))
88 "\n<text:p text:style-name=\"OrgSubtitle\"/>")))
92 (org-e-odt-format-stylized-paragraph
94 (org-e-odt-format-tags
95 '("<text:date style:data-style-name=\"%s\" text:date-value=\"%s\">"
99 "<text:p text:style-name=\"OrgSubtitle\"/>")))))
101 (defun org-e-odt-begin-section (style &optional name
)
102 (let ((default-name (car (org-e-odt-add-automatic-style "Section"))))
103 (format "<text:section text:style-name=\"%s\" text:name=\"%s\">"
104 style
(or name default-name
))))
106 (defun org-e-odt-end-section ()
109 (defun org-e-odt-begin-paragraph (&optional style
)
110 (format "<text:p%s>" (org-e-odt-get-extra-attrs-for-paragraph-style style
)))
112 (defun org-e-odt-end-paragraph ()
115 (defun org-e-odt-get-extra-attrs-for-paragraph-style (style)
119 ((stringp style
) style
)
120 ((symbolp style
) (org-e-odt-get-style-name-for-entity
123 (error "Don't know how to handle paragraph style %s" style
))
124 (format " text:style-name=\"%s\"" style-name
)))
126 (defun org-e-odt-format-stylized-paragraph (style text
)
127 (format "\n<text:p%s>%s</text:p>"
128 (org-e-odt-get-extra-attrs-for-paragraph-style style
)
131 (defun org-e-odt-format-author (&optional author
)
132 (when (setq author
(or author
(plist-get org-lparse-opt-plist
:author
)))
133 (format "<dc:creator>%s</dc:creator>" author
)))
135 (defun org-e-odt-format-date (&optional org-ts fmt
)
138 (and (stringp org-ts
)
139 (string-match org-ts-regexp0 org-ts
)
141 (org-fix-decoded-time
142 (org-parse-time-string (match-string 0 org-ts
) t
)))))
145 (fmt (format-time-string fmt time
))
146 (t (setq date
(format-time-string "%Y-%m-%dT%H:%M:%S%z" time
))
147 (format "%s:%s" (substring date
0 -
2) (substring date -
2)))))))
149 (defun org-e-odt-begin-annotation (&optional author date
)
151 "<office:annotation>\n"
152 (and author
(org-e-odt-format-author author
))
153 (org-e-odt-format-tags
154 '("<dc:date>" .
"</dc:date>")
155 (org-e-odt-format-date
156 (or date
(plist-get org-lparse-opt-plist
:date
))))
157 (org-e-odt-begin-paragraph)))
159 (defun org-e-odt-end-annotation ()
160 "</office:annotation>")
162 (defun org-e-odt-begin-plain-list (ltype)
163 (let* ((style-name (org-e-odt-get-style-name-for-entity 'list ltype
))
165 ;; (if (or org-lparse-list-table-p
166 ;; (and (= 1 (length org-lparse-list-stack))
167 ;; (null org-e-odt-list-stack-stashed)))
168 ;; " text:continue-numbering=\"false\""
169 ;; " text:continue-numbering=\"true\"")
171 " text:continue-numbering=\"true\""
174 (format " text:style-name=\"%s\"" style-name
)))))
176 ((ordered unordered descriptive
)
178 ;; (org-e-odt-end-paragraph)
179 (format "<text:list%s>" extra
)))
180 (t (error "Unknown list type: %s" ltype
)))))
182 (defun org-e-odt-end-plain-list (ltype)
183 (if ltype
"</text:list>"
184 (error "Unknown list type: %s" ltype
)))
186 (defun org-e-odt-begin-list-item (ltype &optional arg headline
)
189 (assert (not headline
) t
)
190 (let* ((counter arg
) (extra ""))
191 (concat "<text:list-item>" ;; (org-e-odt-begin-paragraph)
193 ;; (if (= (length org-lparse-list-stack)
194 ;; (length org-e-odt-list-stack-stashed))
195 ;; "<text:list-header>" "<text:list-item>")
198 (let* ((id arg
) (extra ""))
201 ;; (org-e-odt-begin-paragraph)
202 (if headline
(org-e-odt-format-target headline id
)
203 (org-e-odt-format-bookmark "" id
)))
204 ;; (if (= (length org-lparse-list-stack)
205 ;; (length org-e-odt-list-stack-stashed))
206 ;; "<text:list-header>" "<text:list-item>")
209 (assert (not headline
) t
)
210 (let ((term (or arg
"(no term)")))
212 (org-e-odt-format-tags
213 '("<text:list-item>" .
"</text:list-item>")
214 (org-e-odt-format-stylized-paragraph 'definition-term term
))
215 (org-e-odt-begin-list-item 'unordered
)
216 (org-e-odt-begin-plain-list 'descriptive
)
217 (org-e-odt-begin-list-item 'unordered
))))
218 (t (error "Unknown list type"))))
220 (defun org-e-odt-end-list-item (ltype)
223 ;; (org-lparse-insert-tag
224 ;; (if (= (length org-lparse-list-stack)
225 ;; (length org-e-odt-list-stack-stashed))
226 ;; (prog1 "</text:list-header>"
227 ;; (setq org-e-odt-list-stack-stashed nil))
228 ;; "</text:list-item>")
234 (org-e-odt-end-list-item 'unordered
)
235 (org-e-odt-end-plain-list 'descriptive
)
236 (org-e-odt-end-list-item 'unordered
)
238 (t (error "Unknown list type"))))
240 (defun org-e-odt-write-automatic-styles ()
241 "Write automatic styles to \"content.xml\"."
243 (find-file-noselect (expand-file-name "content.xml") t
)
244 ;; position the cursor
245 (goto-char (point-min))
246 (re-search-forward " </office:automatic-styles>" nil t
)
247 (goto-char (match-beginning 0))
248 ;; write automatic table styles
249 (loop for
(style-name props
) in
250 (plist-get org-e-odt-automatic-styles
'Table
) do
251 (when (setq props
(or (plist-get props
:rel-width
) 96))
252 (insert (format org-e-odt-table-style-format style-name props
))))))
254 (defun org-e-odt-update-display-level (&optional level
)
256 (find-file-noselect (expand-file-name "content.xml") t
)
257 ;; position the cursor.
258 (goto-char (point-min))
259 ;; remove existing sequence decls.
260 (when (re-search-forward "<text:sequence-decls" nil t
)
261 (delete-region (match-beginning 0)
262 (re-search-forward "</text:sequence-decls>" nil nil
)))
265 <text:sequence-decls>")
266 (loop for x in org-e-odt-category-map-alist
268 <text:sequence-decl text:display-outline-level=\"%d\" text:name=\"%s\"/>"
271 </text:sequence-decls>")))
273 (defun org-e-odt-add-automatic-style (object-type &optional object-props
)
274 "Create an automatic style of type OBJECT-TYPE with param OBJECT-PROPS.
275 OBJECT-PROPS is (typically) a plist created by passing
276 \"#+ATTR_ODT: \" option of the object in question to
277 `org-e-odt-parse-block-attributes'.
279 Use `org-e-odt-object-counters' to generate an automatic
280 OBJECT-NAME and STYLE-NAME. If OBJECT-PROPS is non-nil, add a
281 new entry in `org-e-odt-automatic-styles'. Return (OBJECT-NAME
283 (assert (stringp object-type
))
284 (let* ((object (intern object-type
))
286 (seqno (1+ (or (plist-get org-e-odt-object-counters seqvar
) 0)))
287 (object-name (format "%s%d" object-type seqno
)) style-name
)
288 (setq org-e-odt-object-counters
289 (plist-put org-e-odt-object-counters seqvar seqno
))
291 (setq style-name
(format "Org%s" object-name
))
292 (setq org-e-odt-automatic-styles
293 (plist-put org-e-odt-automatic-styles object
294 (append (list (list style-name object-props
))
295 (plist-get org-e-odt-automatic-styles object
)))))
296 (cons object-name style-name
)))
298 (defun org-e-odt-begin-toc (lang-specific-heading max-level
)
301 <text:table-of-content text:style-name=\"Sect2\" text:protected=\"true\" text:name=\"Table of Contents1\">
302 <text:table-of-content-source text:outline-level=\"%d\">
303 <text:index-title-template text:style-name=\"Contents_20_Heading\">%s</text:index-title-template>
304 " max-level lang-specific-heading
)
306 (let ((entry-templates ""))
307 (loop for level from
1 upto
10
308 do
(setq entry-templates
309 (concat entry-templates
312 <text:table-of-content-entry-template text:outline-level=\"%d\" text:style-name=\"Contents_20_%d\">
313 <text:index-entry-link-start text:style-name=\"Internet_20_link\"/>
314 <text:index-entry-chapter/>
315 <text:index-entry-text/>
316 <text:index-entry-link-end/>
317 </text:table-of-content-entry-template>
322 </text:table-of-content-source>
325 <text:index-title text:style-name=\"Sect1\" text:name=\"Table of Contents1_Head\">
326 <text:p text:style-name=\"Contents_20_Heading\">%s</text:p>
328 " lang-specific-heading
)))
330 (defun org-e-odt-end-toc ()
333 </text:table-of-content>
336 (defun org-e-odt-format-toc-entry (snumber todo headline tags href
)
339 (setq headline
(concat
340 (and org-export-with-section-numbers
341 (concat snumber
". "))
345 (org-e-odt-format-spaces 3)
346 (org-e-odt-format-fontify tags
"tag")))))
348 (setq headline
(org-e-odt-format-fontify headline
"todo")))
350 (let ((org-e-odt-suppress-xref t
))
351 (org-e-odt-format-link headline
(concat "#" href
))))
353 (defun org-e-odt-format-toc-item (toc-entry level org-last-level
)
354 (let ((style (format "Contents_20_%d" level
)))
355 (concat "\n" (org-e-odt-format-stylized-paragraph style toc-entry
) "\n")))
357 ;; Following variable is let bound during 'ORG-LINK callback. See
360 (defun org-e-odt-format-link (desc href
&optional attr
)
362 ((and (= (string-to-char href
) ?
#) (not org-e-odt-suppress-xref
))
363 (setq href
(substring href
1))
364 (let ((xref-format "text"))
366 (setq desc
(format "%d" desc
) xref-format
"number"))
368 (setq desc
(mapconcat 'identity desc
".") xref-format
"chapter"))
369 (setq href
(concat org-e-odt-bookmark-prefix href
))
370 (org-e-odt-format-tags-simple
371 '("<text:bookmark-ref text:reference-format=\"%s\" text:ref-name=\"%s\">" .
372 "</text:bookmark-ref>")
373 desc xref-format href
)))
374 (org-lparse-link-description-is-image
375 (org-e-odt-format-tags
376 '("<draw:a xlink:type=\"simple\" xlink:href=\"%s\" %s>" .
"</draw:a>")
377 desc href
(or attr
"")))
379 (org-e-odt-format-tags-simple
380 '("<text:a xlink:type=\"simple\" xlink:href=\"%s\" %s>" .
"</text:a>")
381 desc href
(or attr
"")))))
383 (defun org-e-odt-format-spaces (n)
387 " " (org-e-odt-format-tags "<text:s text:c=\"%d\"/>" "" (1- n
))))
390 (defun org-e-odt-format-tabs (&optional n
)
391 (let ((tab "<text:tab/>")
395 (defun org-e-odt-format-line-break ()
396 (org-e-odt-format-tags "<text:line-break/>" ""))
398 (defun org-e-odt-format-horizontal-line ()
399 (org-e-odt-format-stylized-paragraph 'horizontal-line
""))
401 (defun org-e-odt-encode-plain-text (line &optional no-whitespace-filling
)
402 (setq line
(org-e-html-encode-plain-text line
))
403 (if no-whitespace-filling line
404 (org-e-odt-fill-tabs-and-spaces line
)))
406 (defun org-e-odt-format-line (line)
407 (case org-lparse-dyn-current-environment
409 (org-e-odt-format-stylized-paragraph
410 'fixedwidth
(org-e-odt-encode-plain-text line
)) "\n"))
411 (t (concat line
"\n"))))
413 (defun org-e-odt-format-comment (fmt &rest args
)
414 (let ((comment (apply 'format fmt args
)))
415 (format "\n<!-- %s -->\n" comment
)))
417 (defun org-e-odt-format-org-entity (wd)
418 (org-entity-get-representation wd
'utf8
))
420 (defun org-e-odt-fill-tabs-and-spaces (line)
421 (replace-regexp-in-string
422 "\\([\t]\\|\\([ ]+\\)\\)" (lambda (s)
424 ((string= s
"\t") (org-e-odt-format-tabs))
425 (t (org-e-odt-format-spaces (length s
))))) line
))
427 (defun org-e-odt-hfy-face-to-css (fn)
428 "Create custom style for face FN.
429 When FN is the default face, use it's foreground and background
430 properties to create \"OrgSrcBlock\" paragraph style. Otherwise
431 use it's color attribute to create a character style whose name
432 is obtained from FN. Currently all attributes of FN other than
435 The style name for a face FN is derived using the following
436 operations on the face name in that order - de-dash, CamelCase
437 and prefix with \"OrgSrc\". For example,
438 `font-lock-function-name-face' is associated with
439 \"OrgSrcFontLockFunctionNameFace\"."
440 (let* ((css-list (hfy-face-to-style fn
))
441 (style-name ((lambda (fn)
444 'capitalize
(split-string
445 (hfy-face-or-def-to-name fn
) "-")
447 (color-val (cdr (assoc "color" css-list
)))
448 (background-color-val (cdr (assoc "background" css-list
)))
449 (style (and org-e-odt-create-custom-styles-for-srcblocks
452 (format org-src-block-paragraph-format
453 background-color-val color-val
))
457 <style:style style:name=\"%s\" style:family=\"text\">
458 <style:text-properties fo:color=\"%s\"/>
459 </style:style>" style-name color-val
))))))
460 (cons style-name style
)))
462 (defun org-e-odt-insert-custom-styles-for-srcblocks (styles)
463 "Save STYLES used for colorizing of source blocks.
464 Update styles.xml with styles that were collected as part of
465 `org-e-odt-hfy-face-to-css' callbacks."
468 (find-file-noselect (expand-file-name "styles.xml") t
)
469 (goto-char (point-min))
470 (when (re-search-forward "</office:styles>" nil t
)
471 (goto-char (match-beginning 0))
472 (insert "\n<!-- Org Htmlfontify Styles -->\n" styles
"\n")))))
474 (defun org-e-odt-remap-stylenames (style-name)
476 (cdr (assoc style-name
'(("timestamp-wrapper" .
"OrgTimestampWrapper")
477 ("timestamp" .
"OrgTimestamp")
478 ("timestamp-kwd" .
"OrgTimestampKeyword")
482 ("target" .
"OrgTarget"))))
485 (defun org-e-odt-format-fontify (text style
&optional id
)
489 (org-e-odt-remap-stylenames style
))
491 (org-e-odt-get-style-name-for-entity 'character style
))
493 (assert (< 1 (length style
)))
494 (let ((parent-style (pop style
)))
495 (mapconcat (lambda (s)
496 ;; (assert (stringp s) t)
497 (org-e-odt-remap-stylenames s
)) style
"")
498 (org-e-odt-remap-stylenames parent-style
)))
499 (t (error "Don't how to handle style %s" style
)))))
500 (org-e-odt-format-tags-simple
501 '("<text:span text:style-name=\"%s\">" .
"</text:span>")
504 (defun org-e-odt-relocate-relative-path (path dir
)
505 (if (file-name-absolute-p path
) path
506 (file-relative-name (expand-file-name path dir
)
507 (expand-file-name "eyecandy" dir
))))
509 (defun org-e-odt-format-formula (element info
)
511 ((eq (org-element-type element
) 'link
) ; FIXME
512 (let* ((type (org-element-property :type element
))
513 (raw-path (org-element-property :path element
)))
515 ((file-name-absolute-p raw-path
)
516 (expand-file-name raw-path
))
518 ((member (org-element-type element
)
519 '(latex-fragment latex-environment
))
520 (let* ((latex-frag (org-remove-indentation
521 (org-element-property
523 (formula-link (org-e-odt-format-latex
524 latex-frag
'mathml
)))
526 (string-match "file:\\([^]]*\\)" formula-link
)
527 (match-string 1 formula-link
))))
528 (t (error "what is this?"))))
530 (case (org-element-type element
)
531 (link (org-export-get-parent-paragraph element info
))
533 (captions (org-e-odt-format-label caption-from info
'definition
))
534 (caption (car captions
))
536 (org-e-odt-format-tags
537 "<draw:object xlink:href=\"%s\" xlink:type=\"simple\" xlink:show=\"embed\" xlink:actuate=\"onLoad\"/>" ""
538 (file-name-directory (org-e-odt-copy-formula-file src
))))
539 (embed-as (if caption
'paragraph
'character
))
542 ((eq embed-as
'character
)
543 (org-e-odt-format-entity "InlineFormula" href width height
))
545 (let ((table-info nil
)
547 '(:alignment
["c" "c"]
548 :column-groups
[nil nil
]
550 :special-column-p nil
:width
[8 1]))
551 (org-lparse-table-ncols 2)) ; FIXME
552 (org-e-odt-list-table ; FIXME
555 (org-e-odt-format-entity
556 "CaptionedDisplayFormula" href width height captions
)
557 (let* ((org-e-odt-category-map-alist
558 '(("__Table__" "Table" "value")
559 ("__Figure__" "Illustration" "value")
560 ("__MathFormula__" "Text" "math-label")
561 ("__DvipngImage__" "Equation" "value")
562 ("__Listing__" "Listing" "value"))))
563 (car (org-e-odt-format-label caption-from info
'definition
)))))
564 '(table (:attr_odt
(":style \"OrgEquation\""))) info
))))))
566 (defun org-e-odt-copy-formula-file (path)
567 "Returns the internal name of the file"
568 (let* ((src-file (expand-file-name
569 path
(file-name-directory org-current-export-file
)))
570 (target-dir (format "Formula-%04d/"
571 (incf org-e-odt-embedded-formulas-count
)))
572 (target-file (concat target-dir
"content.xml")))
573 (message "Embedding %s as %s ..."
574 (substring-no-properties path
) target-file
)
576 (make-directory target-dir
)
577 (org-e-odt-create-manifest-file-entry
578 "application/vnd.oasis.opendocument.formula" target-dir
"1.2")
580 (case (org-e-odt-is-formula-link-p src-file
)
582 (copy-file src-file target-file
'overwrite
))
584 (org-e-odt-zip-extract-one src-file
"content.xml" target-dir
))
586 (error "%s is not a formula file" src-file
)))
588 (org-e-odt-create-manifest-file-entry "text/xml" target-file
)
591 (defun org-e-odt-is-formula-link-p (file)
592 (let ((case-fold-search nil
))
594 ((string-match "\\.\\(mathml\\|mml\\)\\'" file
)
596 ((string-match "\\.odf\\'" file
)
599 (defun org-e-odt-format-org-link (opt-plist type-1 path fragment desc attr
601 "Make a OpenDocument link.
602 OPT-PLIST is an options list.
603 TYPE-1 is the device-type of the link (THIS://foo.html).
604 PATH is the path of the link (http://THIS#location).
605 FRAGMENT is the fragment part of the link, if any (foo.html#THIS).
606 DESC is the link description, if any.
607 ATTR is a string of other attributes of the a element."
608 (declare (special org-lparse-par-open
))
611 (and (member type-1
'("http" "https" "file"))
612 (org-lparse-should-inline-p path descp
)
614 (type (if (equal type-1
"id") "file" type-1
))
618 ;; check for inlined images
619 ((and (member type
'("file"))
622 filename org-e-odt-inline-image-extensions
)
624 (org-e-odt-format-inline-image thefile
))
625 ;; check for embedded formulas
626 ((and (member type
'("file"))
628 (org-e-odt-is-formula-link-p filename
)
630 (org-e-odt-format-formula thefile
))
631 ((string= type
"coderef")
632 (let* ((ref fragment
)
633 (lineno-or-ref (cdr (assoc ref org-export-code-refs
)))
634 (desc (and descp desc
))
635 (org-e-odt-suppress-xref nil
)
636 (href (org-xml-format-href (concat "#coderef-" ref
))))
638 ((and (numberp lineno-or-ref
) (not desc
))
639 (org-e-odt-format-link lineno-or-ref href
))
640 ((and (numberp lineno-or-ref
) desc
641 (string-match (regexp-quote (concat "(" ref
")")) desc
))
642 (format (replace-match "%s" t t desc
)
643 (org-e-odt-format-link lineno-or-ref href
)))
646 (if (and desc
(string-match
647 (regexp-quote (concat "(" ref
")"))
649 (replace-match "%s" t t desc
)
652 (org-e-odt-format-link (org-xml-format-desc desc
) href
)))))
654 (when (string= type
"file")
657 ((file-name-absolute-p path
)
658 (concat "file://" (expand-file-name path
)))
659 (t (org-e-odt-relocate-relative-path
660 thefile org-current-export-file
)))))
662 (when (and (member type
'("" "http" "https" "file")) fragment
)
663 (setq thefile
(concat thefile
"#" fragment
)))
665 (setq thefile
(org-xml-format-href thefile
))
667 (when (not (member type
'("" "file")))
668 (setq thefile
(concat type
":" thefile
)))
670 (let ((org-e-odt-suppress-xref nil
))
671 (org-e-odt-format-link
672 (org-xml-format-desc desc
) thefile attr
)))))))
674 (defun org-e-odt-format-anchor (text name
&optional class
)
675 (org-e-odt-format-target text name
))
677 (defun org-e-odt-format-bookmark (text id
)
679 (org-e-odt-format-tags "<text:bookmark text:name=\"%s\"/>" text id
)
682 (defun org-e-odt-format-target (text id
)
683 (let ((name (concat org-e-odt-bookmark-prefix id
)))
685 (and id
(org-e-odt-format-tags
686 "<text:bookmark-start text:name=\"%s\"/>" "" name
))
687 (org-e-odt-format-bookmark text id
)
688 (and id
(org-e-odt-format-tags
689 "<text:bookmark-end text:name=\"%s\"/>" "" name
)))))
691 (defun org-e-odt-format-footnote (n def
)
692 (setq n
(format "%d" n
))
693 (let ((id (concat "fn" n
))
694 (note-class "footnote")
695 (par-style "Footnote"))
696 (org-e-odt-format-tags-simple
697 '("<text:note text:id=\"%s\" text:note-class=\"%s\">" .
"</text:note>")
699 (org-e-odt-format-tags-simple
700 '("<text:note-citation>" .
"</text:note-citation>") n
)
701 (org-e-odt-format-tags-simple
702 '("<text:note-body>" .
"</text:note-body>") def
))
705 (defun org-e-odt-format-footnote-reference (n def refcnt
)
707 (org-e-odt-format-footnote n def
)
708 (org-e-odt-format-footnote-ref n
)))
710 (defun org-e-odt-format-footnote-ref (n)
711 (setq n
(format "%d" n
))
712 (let ((note-class "footnote")
714 (ref-name (concat "fn" n
)))
715 (org-e-odt-format-tags-simple
716 '("<text:span text:style-name=\"%s\">" .
"</text:span>")
717 (org-e-odt-format-tags-simple
718 '("<text:note-ref text:note-class=\"%s\" text:reference-format=\"%s\" text:ref-name=\"%s\">" .
"</text:note-ref>")
719 n note-class ref-format ref-name
)
722 (defun org-e-odt-element-attributes (element info
)
723 (let* ((raw-attr (org-element-property :attr_odt element
))
724 (raw-attr (and raw-attr
725 (org-trim (mapconcat #'identity raw-attr
" ")))))
726 (unless (and raw-attr
(string-match "\\`(.*)\\'" raw-attr
))
727 (setq raw-attr
(format "(%s)" raw-attr
)))
728 (ignore-errors (read raw-attr
))))
730 (defun org-e-odt-format-object-description (title description
)
731 (concat (and title
(org-e-odt-format-tags
732 '("<svg:title>" .
"</svg:title>")
733 (org-e-odt-encode-plain-text title t
)))
734 (and description
(org-e-odt-format-tags
735 '("<svg:desc>" .
"</svg:desc>")
736 (org-e-odt-encode-plain-text description t
)))))
738 (defun org-e-odt-format-frame (text width height style
&optional
742 (if width
(format " svg:width=\"%0.2fcm\"" width
) "")
743 (if height
(format " svg:height=\"%0.2fcm\"" height
) "")
745 (format " text:anchor-type=\"%s\"" (or anchor-type
"paragraph")))))
746 (org-e-odt-format-tags
747 '("<draw:frame draw:style-name=\"%s\"%s>" .
"</draw:frame>")
748 (concat text
(org-e-odt-format-object-description
749 (get-text-property 0 :title text
)
750 (get-text-property 0 :description text
)))
753 (defun org-e-odt-format-textbox (text width height style
&optional
755 (org-e-odt-format-frame
756 (org-e-odt-format-tags
757 '("<draw:text-box %s>" .
"</draw:text-box>")
758 text
(concat (format " fo:min-height=\"%0.2fcm\"" (or height
.2))
760 (format " fo:min-width=\"%0.2fcm\"" (or width
.2)))))
761 width nil style extra anchor-type
))
763 (defun org-e-odt-merge-frame-params(default-frame-params user-frame-params
)
764 (if (not user-frame-params
) default-frame-params
765 (assert (= (length default-frame-params
) 3))
766 (assert (= (length user-frame-params
) 3))
767 (loop for user-frame-param in user-frame-params
768 for default-frame-param in default-frame-params
769 collect
(or user-frame-param default-frame-param
))))
771 (defun org-e-odt-copy-image-file (path)
772 "Returns the internal name of the file"
773 (let* ((image-type (file-name-extension path
))
774 (media-type (format "image/%s" image-type
))
775 (src-file (expand-file-name
776 path
(file-name-directory org-current-export-file
)))
777 (target-dir "Images/")
779 (format "%s%04d.%s" target-dir
780 (incf org-e-odt-embedded-images-count
) image-type
)))
781 (message "Embedding %s as %s ..."
782 (substring-no-properties path
) target-file
)
784 (when (= 1 org-e-odt-embedded-images-count
)
785 (make-directory target-dir
)
786 (org-e-odt-create-manifest-file-entry "" target-dir
))
788 (copy-file src-file target-file
'overwrite
)
789 (org-e-odt-create-manifest-file-entry media-type target-file
)
792 (defun org-e-odt-do-image-size (probe-method file
&optional dpi anchor-type
)
793 (setq dpi
(or dpi org-e-odt-pixels-per-inch
))
794 (setq anchor-type
(or anchor-type
"paragraph"))
795 (flet ((size-in-cms (size-in-pixels)
796 (flet ((pixels-to-cms (pixels)
797 (let* ((cms-per-inch 2.54)
798 (inches (/ pixels dpi
)))
799 (* cms-per-inch inches
))))
801 (cons (pixels-to-cms (car size-in-pixels
))
802 (pixels-to-cms (cdr size-in-pixels
)))))))
805 (size-in-cms (ignore-errors ; Emacs could be in batch mode
807 (image-size (create-image file
) 'pixels
))))
810 (let ((dim (shell-command-to-string
811 (format "identify -format \"%%w:%%h\" \"%s\"" file
))))
812 (when (string-match "\\([0-9]+\\):\\([0-9]+\\)" dim
)
813 (cons (string-to-number (match-string 1 dim
))
814 (string-to-number (match-string 2 dim
)))))))
816 (cdr (assoc-string anchor-type
817 org-e-odt-default-image-sizes-alist
))))))
819 (defun org-e-odt-image-size-from-file (file &optional user-width
820 user-height scale dpi embed-as
)
821 (unless (file-name-absolute-p file
)
822 (setq file
(expand-file-name
823 file
(file-name-directory org-current-export-file
))))
824 (let* (size width height
)
825 (unless (and user-height user-width
)
826 (loop for probe-method in org-e-odt-image-size-probe-method
828 do
(setq size
(org-e-odt-do-image-size
829 probe-method file dpi embed-as
)))
830 (or size
(error "Cannot determine Image size. Aborting ..."))
831 (setq width
(car size
) height
(cdr size
)))
834 (setq width
(* width scale
) height
(* height scale
)))
835 ((and user-height user-width
)
836 (setq width user-width height user-height
))
838 (setq width
(* user-height
(/ width height
)) height user-height
))
840 (setq height
(* user-width
(/ height width
)) width user-width
))
842 ;; ensure that an embedded image fits comfortably within a page
843 (let ((max-width (car org-e-odt-max-image-size
))
844 (max-height (cdr org-e-odt-max-image-size
)))
845 (when (or (> width max-width
) (> height max-height
))
846 (let* ((scale1 (/ max-width width
))
847 (scale2 (/ max-height height
))
848 (scale (min scale1 scale2
)))
849 (setq width
(* scale width
) height
(* scale height
)))))
850 (cons width height
)))
852 (defun org-e-odt-format-label (element info op
)
854 (case (org-element-type element
)
855 (link (org-export-get-parent-paragraph element info
))
857 ;; get label and caption.
858 (label (org-element-property :name caption-from
))
859 (caption (org-element-property :caption caption-from
))
860 (short-caption (cdr caption
))
861 ;; transcode captions.
862 (caption (and (car caption
) (org-export-data (car caption
) info
)))
863 (short-caption (and short-caption
864 (org-export-data short-caption info
))))
865 (when (or label caption
)
866 (let* ((default-category
868 ((eq (org-element-type element
) 'table
)
870 ((org-e-odt-standalone-image-p element info
)
872 ((member (org-element-type element
)
873 '(latex-environment latex-fragment
))
874 (let ((processing-type (plist-get info
:LaTeX-fragments
)))
876 ((eq processing-type
'dvipng
) "__DvipngImage__")
877 ((eq processing-type
'mathjax
) "__MathFormula__")
878 ((eq processing-type
't
) "__MathFormula__")
879 (t (error "Handle LaTeX:verbatim")))))
880 ((eq (org-element-type element
) 'src-block
)
882 (t (error "Handle enumeration of %S" element
))))
885 ((member (org-element-type element
)
886 '(table latex-environment src-block
))
888 ((org-e-odt-standalone-image-p element info
)
889 'org-e-odt-standalone-image-p
)
890 (t (error "Handle enumeration of %S" element
))))
891 (seqno (org-e-odt-enumerate-element
892 element info predicate
)) ; FIXME
893 ;; handle label props.
894 (label-props (assoc default-category org-e-odt-category-map-alist
))
895 ;; identify opendocument counter
896 (counter (nth 1 label-props
))
897 ;; identify label style
898 (label-style (nth 2 label-props
))
899 ;; grok language setting
900 (en-strings (assoc-default "en" org-e-odt-category-strings
))
901 (lang (plist-get info
:language
)) ; FIXME
902 (lang-strings (assoc-default lang org-e-odt-category-strings
))
903 ;; retrieve localized category sting
904 (pos (- (length org-e-odt-category-map-alist
)
905 (length (memq label-props org-e-odt-category-map-alist
))))
906 (category (or (nth pos lang-strings
) (nth pos en-strings
))))
909 ;; assign an internal label, if user has not provided one
910 (setq label
(or label
(format "%s-%s" default-category seqno
)))
911 (setq label
(org-solidify-link-text label
))
915 (cadr (assoc-string label-style org-e-odt-label-styles t
))
917 (?n .
,(org-e-odt-format-tags-simple
918 '("<text:sequence text:ref-name=\"%s\" text:name=\"%s\" text:formula=\"ooow:%s+1\" style:num-format=\"1\">" .
"</text:sequence>")
919 seqno label counter counter
))
920 (?c .
,(or caption
""))))
924 (setq label
(org-solidify-link-text label
))
925 (let* ((fmt (cddr (assoc-string label-style org-e-odt-label-styles t
)))
928 (org-e-odt-format-tags-simple
929 '("<text:sequence-ref text:reference-format=\"%s\" text:ref-name=\"%s\">"
930 .
"</text:sequence-ref>")
931 (format-spec fmt2
`((?e .
,category
)
932 (?n .
,seqno
))) fmt1 label
)))
933 (t (error "Unknow %S on label" op
)))))))
935 (defun org-e-odt-format-tags-1 (tag text prefix suffix
&rest args
)
938 (concat prefix
(apply 'format
(car tag
) args
) text suffix
940 ((stringp tag
) ; singleton tag
941 (concat prefix
(apply 'format tag args
) text
))))
943 (defun org-e-odt-format-tags (tag text
&rest args
)
944 (apply 'org-e-odt-format-tags-1 tag text
"\n" "\n" args
))
946 (defun org-e-odt-format-tags-simple (tag text
&rest args
)
947 (apply 'org-e-odt-format-tags-1 tag text nil nil args
))
949 (defun org-e-odt-init-outfile ()
950 (unless (executable-find "zip")
951 ;; Not at all OSes ship with zip by default
952 (error "Executable \"zip\" needed for creating OpenDocument files"))
954 (let* ((outdir (make-temp-file
955 (format org-e-odt-tmpdir-prefix
'odt
) t
)) ; FIXME
956 (content-file (expand-file-name "content.xml" outdir
)))
959 (setq org-e-odt-manifest-file-entries nil
960 org-e-odt-embedded-images-count
0
961 org-e-odt-embedded-formulas-count
0
962 org-e-odt-section-count
0
963 org-e-odt-entity-labels-alist nil
964 org-e-odt-list-stack-stashed nil
965 org-e-odt-automatic-styles nil
966 org-e-odt-object-counters nil
967 org-e-odt-entity-counts-plist nil
)
969 ;; let `htmlfontify' know that we are interested in collecting
972 (setq hfy-user-sheet-assoc nil
)
976 (find-file-noselect content-file t
)
979 (defun org-e-odt-save-as-outfile (target opt-plist
)
980 ;; write automatic styles
981 (org-e-odt-write-automatic-styles)
983 ;; update display levels
984 (org-e-odt-update-display-level org-e-odt-display-outline-level
)
987 ;; (when (equal org-lparse-backend 'odt) FIXME
990 ;; (org-e-odt-update-styles-file opt-plist)
992 ;; create mimetype file
993 (let ((mimetype (org-e-odt-write-mimetype-file ;; org-lparse-backend FIXME
995 (org-e-odt-create-manifest-file-entry mimetype
"/" "1.2"))
997 ;; create a manifest entry for content.xml
998 (org-e-odt-create-manifest-file-entry "text/xml" "content.xml")
1000 ;; write out the manifest entries before zipping
1001 (org-e-odt-write-manifest-file)
1003 (let ((xml-files '("mimetype" "META-INF/manifest.xml" "content.xml"
1005 (zipdir default-directory
))
1006 (when (or t
(equal org-lparse-backend
'odt
)) ; FIXME
1007 (push "styles.xml" xml-files
))
1008 (message "Switching to directory %s" (expand-file-name zipdir
))
1010 ;; save all xml files
1011 (mapc (lambda (file)
1012 (with-current-buffer
1013 (find-file-noselect (expand-file-name file
) t
)
1014 ;; prettify output if needed
1015 (when org-e-odt-prettify-xml
1016 (indent-region (point-min) (point-max)))
1020 (let* ((target-name (file-name-nondirectory target
))
1021 (target-dir (file-name-directory target
))
1022 (cmds `(("zip" "-mX0" ,target-name
"mimetype")
1023 ("zip" "-rmTq" ,target-name
"."))))
1024 (when (file-exists-p target
)
1025 ;; FIXME: If the file is locked this throws a cryptic error
1026 (delete-file target
))
1028 (let ((coding-system-for-write 'no-conversion
) exitcode err-string
)
1029 (message "Creating odt file...")
1032 (message "Running %s" (mapconcat 'identity cmd
" "))
1034 (with-output-to-string
1036 (apply 'call-process
(car cmd
)
1037 nil standard-output nil
(cdr cmd
)))))
1038 (or (zerop exitcode
)
1039 (ignore (message "%s" err-string
))
1040 (error "Unable to create odt file (%S)" exitcode
)))
1043 ;; move the file from outdir to target-dir
1044 (rename-file target-name target-dir
)
1046 ;; kill all xml buffers
1047 (mapc (lambda (file)
1049 (find-file-noselect (expand-file-name file zipdir
) t
)))
1052 (delete-directory zipdir
)))
1053 (message "Created %s" target
)
1054 (set-buffer (find-file-noselect target t
)))
1057 (defun org-e-odt-create-manifest-file-entry (&rest args
)
1058 (push args org-e-odt-manifest-file-entries
))
1060 (defun org-e-odt-write-manifest-file ()
1061 (make-directory "META-INF")
1062 (let ((manifest-file (expand-file-name "META-INF/manifest.xml")))
1063 (with-current-buffer
1064 (find-file-noselect manifest-file t
)
1066 "<?xml version=\"1.0\" encoding=\"UTF-8\"?>
1067 <manifest:manifest xmlns:manifest=\"urn:oasis:names:tc:opendocument:xmlns:manifest:1.0\" manifest:version=\"1.2\">\n")
1069 (lambda (file-entry)
1070 (let* ((version (nth 2 file-entry
))
1072 (format " manifest:version=\"%s\"" version
)
1075 (format org-e-odt-manifest-file-entry-tag
1076 (nth 0 file-entry
) (nth 1 file-entry
) extra
))))
1077 org-e-odt-manifest-file-entries
)
1078 (insert "\n</manifest:manifest>"))))
1080 (defun org-e-odt-update-meta-file (info) ; FIXME opt-plist
1081 (let ((title (org-export-data (plist-get info
:title
) info
))
1082 (author (or (let ((auth (plist-get info
:author
)))
1083 (and auth
(org-export-data auth info
))) ""))
1084 (date (org-e-odt-format-date (plist-get info
:date
)))
1085 (email (plist-get info
:email
))
1086 (keywords (plist-get info
:keywords
))
1087 (description (plist-get info
:description
)))
1090 "<?xml version=\"1.0\" encoding=\"UTF-8\"?>
1091 <office:document-meta
1092 xmlns:office=\"urn:oasis:names:tc:opendocument:xmlns:office:1.0\"
1093 xmlns:xlink=\"http://www.w3.org/1999/xlink\"
1094 xmlns:dc=\"http://purl.org/dc/elements/1.1/\"
1095 xmlns:meta=\"urn:oasis:names:tc:opendocument:xmlns:meta:1.0\"
1096 xmlns:ooo=\"http://openoffice.org/2004/office\"
1097 office:version=\"1.2\">
1099 (org-e-odt-format-author author
) "\n"
1100 (format "<meta:initial-creator>%s</meta:initial-creator>\n" author
)
1101 (format "<dc:date>%s</dc:date>\n" date
)
1102 (format "<meta:creation-date>%s</meta:creation-date>\n" date
)
1103 (format "<meta:generator>%s</meta:generator>\n"
1104 (concat (and org-export-creator-info org-export-creator-string
)))
1105 (format "<meta:keyword>%s</meta:keyword>\n" keywords
)
1106 (format "<dc:subject>%s</dc:subject>\n" description
)
1107 (format "<dc:title>%s</dc:title>\n" title
)
1109 " </office:meta>\n" "</office:document-meta>")
1110 nil
(expand-file-name "meta.xml")))
1112 ;; create a manifest entry for meta.xml
1113 (org-e-odt-create-manifest-file-entry "text/xml" "meta.xml"))
1115 (defun org-e-odt-update-styles-file (info)
1116 ;; write styles file
1117 (let ((styles-file (plist-get info
:odt-styles-file
)))
1118 (org-e-odt-copy-styles-file (and styles-file
1119 (read (org-trim styles-file
))))
1121 ;; FIXME: Who is opening an empty styles.xml before this point?
1122 (with-current-buffer
1123 (find-file-noselect (expand-file-name "styles.xml") t
)
1124 (revert-buffer t t
)))
1126 ;; Write custom styles for source blocks
1127 (org-e-odt-insert-custom-styles-for-srcblocks
1130 (format " %s\n" (cddr style
)))
1131 hfy-user-sheet-assoc
"")))
1133 (defun org-e-odt-write-mimetype-file (format)
1134 ;; create mimetype file
1137 (odt "application/vnd.oasis.opendocument.text")
1138 (odf "application/vnd.oasis.opendocument.formula")
1139 (t (error "Unknown OpenDocument backend %S" org-lparse-backend
)))))
1140 (write-region mimetype nil
(expand-file-name "mimetype"))
1143 (declare-function org-create-math-formula
"org"
1144 (latex-frag &optional mathml-file
))
1146 (defun org-e-odt-get (what &optional opt-plist
)
1148 (EXPORT-DIR (org-export-directory :html opt-plist
))
1149 (TABLE-FIRST-COLUMN-AS-LABELS nil
)
1150 (CODING-SYSTEM-FOR-WRITE 'utf-8
)
1151 (CODING-SYSTEM-FOR-SAVE 'utf-8
)
1152 (t (error "Unknown property: %s" what
))))
1154 (defun org-e-odt-do-preprocess-latex-fragments ()
1155 "Convert LaTeX fragments to images."
1156 (let* ((latex-frag-opt (plist-get org-lparse-opt-plist
:LaTeX-fragments
))
1157 (latex-frag-opt ; massage the options
1158 (or (and (member latex-frag-opt
'(mathjax t
))
1159 (not (and (fboundp 'org-format-latex-mathml-available-p
)
1160 (org-format-latex-mathml-available-p)))
1161 (prog1 org-lparse-latex-fragment-fallback
1164 "LaTeX to MathML converter not available. "
1165 (format "Using %S instead."
1166 org-lparse-latex-fragment-fallback
)))))
1168 cache-dir display-msg
)
1170 ((eq latex-frag-opt
'dvipng
)
1171 (setq cache-dir
"ltxpng/")
1172 (setq display-msg
"Creating LaTeX image %s"))
1173 ((member latex-frag-opt
'(mathjax t
))
1174 (setq latex-frag-opt
'mathml
)
1175 (setq cache-dir
"ltxmathml/")
1176 (setq display-msg
"Creating MathML formula %s")))
1177 (when (and org-current-export-file
)
1179 (concat cache-dir
(file-name-sans-extension
1180 (file-name-nondirectory org-current-export-file
)))
1181 org-current-export-dir nil display-msg
1182 nil nil latex-frag-opt
))))
1184 (eval-after-load 'org-odt
1185 '(ad-deactivate 'org-format-latex-as-mathml
))
1189 ;; (defadvice org-format-latex-as-mathml ; FIXME
1190 ;; (after org-e-odt-protect-latex-fragment activate)
1191 ;; "Encode LaTeX fragment as XML.
1192 ;; Do this when translation to MathML fails."
1193 ;; (when (or (not (> (length ad-return-value) 0))
1194 ;; (get-text-property 0 'org-protected ad-return-value))
1195 ;; (setq ad-return-value
1196 ;; (org-propertize (org-e-odt-encode-plain-text (ad-get-arg 0))
1197 ;; 'org-protected t))))
1199 (defun org-e-odt-zip-extract-one (archive member
&optional target
)
1201 (let* ((target (or target default-directory
))
1202 (archive (expand-file-name archive
))
1203 (archive-zip-extract
1204 (list "unzip" "-qq" "-o" "-d" target
))
1205 exit-code command-output
)
1206 (setq command-output
1208 (setq exit-code
(archive-zip-extract archive member
))
1210 (unless (zerop exit-code
)
1211 (message command-output
)
1212 (error "Extraction failed"))))
1214 (defun org-e-odt-zip-extract (archive members
&optional target
)
1215 (when (atom members
) (setq members
(list members
)))
1216 (mapc (lambda (member)
1217 (org-e-odt-zip-extract-one archive member target
))
1220 (defun org-e-odt-copy-styles-file (&optional styles-file
)
1221 ;; Non-availability of styles.xml is not a critical error. For now
1222 ;; throw an error purely for aesthetic reasons.
1223 (setq styles-file
(or styles-file
1224 org-e-odt-styles-file
1225 (expand-file-name "OrgOdtStyles.xml"
1226 org-e-odt-styles-dir
)
1227 (error "org-e-odt: Missing styles file?")))
1229 ((listp styles-file
)
1230 (let ((archive (nth 0 styles-file
))
1231 (members (nth 1 styles-file
)))
1232 (org-e-odt-zip-extract archive members
)
1235 (when (org-file-image-p member
)
1236 (let* ((image-type (file-name-extension member
))
1237 (media-type (format "image/%s" image-type
)))
1238 (org-e-odt-create-manifest-file-entry media-type member
))))
1240 ((and (stringp styles-file
) (file-exists-p styles-file
))
1241 (let ((styles-file-type (file-name-extension styles-file
)))
1243 ((string= styles-file-type
"xml")
1244 (copy-file styles-file
(expand-file-name "styles.xml") t
))
1245 ((member styles-file-type
'("odt" "ott"))
1246 (org-e-odt-zip-extract styles-file
"styles.xml")))))
1248 (error (format "Invalid specification of styles.xml file: %S"
1249 org-e-odt-styles-file
))))
1251 ;; create a manifest entry for styles.xml
1252 (org-e-odt-create-manifest-file-entry "text/xml" "styles.xml"))
1254 (defun org-e-odt-configure-outline-numbering ()
1255 "Outline numbering is retained only upto LEVEL.
1256 To disable outline numbering pass a LEVEL of 0."
1257 (goto-char (point-min))
1259 "<text:outline-level-style\\([^>]*\\)text:level=\"\\([^\"]*\\)\"\\([^>]*\\)>")
1261 "<text:outline-level-style\\1text:level=\"\\2\" style:num-format=\"\">"))
1262 (while (re-search-forward regex nil t
)
1263 (unless (let ((sec-num (plist-get info
:section-numbers
))
1264 (level (string-to-number (match-string 2))))
1265 (if (wholenump sec-num
) (<= level sec-num
) sec-num
))
1266 (replace-match replacement t nil
))))
1270 (defun org-export-as-odf (latex-frag &optional odf-file
)
1271 "Export LATEX-FRAG as OpenDocument formula file ODF-FILE.
1272 Use `org-create-math-formula' to convert LATEX-FRAG first to
1273 MathML. When invoked as an interactive command, use
1274 `org-latex-regexps' to infer LATEX-FRAG from currently active
1275 region. If no LaTeX fragments are found, prompt for it. Push
1276 MathML source to kill ring, if `org-export-copy-to-kill-ring' is
1280 (setq frag
(and (setq frag
(and (region-active-p)
1281 (buffer-substring (region-beginning)
1283 (loop for e in org-latex-regexps
1284 thereis
(when (string-match (nth 1 e
) frag
)
1285 (match-string (nth 2 e
) frag
)))))
1286 (read-string "LaTeX Fragment: " frag nil frag
))
1287 ,(let ((odf-filename (expand-file-name
1289 (file-name-sans-extension
1290 (or (file-name-nondirectory buffer-file-name
)))
1292 (file-name-directory buffer-file-name
))))
1293 (read-file-name "ODF filename: " nil odf-filename nil
1294 (file-name-nondirectory odf-filename
)))))
1295 (let* ((org-lparse-backend 'odf
)
1296 org-lparse-opt-plist
1297 (filename (or odf-file
1300 (file-name-sans-extension
1301 (or (file-name-nondirectory buffer-file-name
)))
1303 (file-name-directory buffer-file-name
))))
1304 (buffer (find-file-noselect (org-e-odt-init-outfile filename
)))
1305 (coding-system-for-write 'utf-8
)
1306 (save-buffer-coding-system 'utf-8
))
1308 (set-buffer-file-coding-system coding-system-for-write
)
1309 (let ((mathml (org-create-math-formula latex-frag
)))
1310 (unless mathml
(error "No Math formula created"))
1312 (or (org-export-push-to-kill-ring
1313 (upcase (symbol-name org-lparse-backend
)))
1314 (message "Exporting... done")))
1315 (org-e-odt-save-as-outfile filename nil
; FIXME
1319 (defun org-export-as-odf-and-open ()
1320 "Export LaTeX fragment as OpenDocument formula and immediately open it.
1321 Use `org-export-as-odf' to read LaTeX fragment and OpenDocument
1324 (org-lparse-and-open
1325 nil nil nil
(call-interactively 'org-export-as-odf
)))
1330 ;;; Driver Starts here
1333 (require 'format-spec
)
1334 (eval-when-compile (require 'cl
) (require 'table
))
1340 ;; FIXME: it already exists in org-e-odt.el
1341 ;;; Function Declarations
1343 (declare-function org-element-property
"org-element" (property element
))
1344 (declare-function org-element-normalize-string
"org-element" (s))
1345 (declare-function org-element-parse-secondary-string
1346 "org-element" (string restriction
&optional buffer
))
1347 (defvar org-element-string-restrictions
)
1348 (defvar org-element-object-restrictions
)
1350 (declare-function org-export-data
"org-export" (data info
))
1351 (declare-function org-export-directory
"org-export" (type plist
))
1352 (declare-function org-export-expand-macro
"org-export" (macro info
))
1353 (declare-function org-export-first-sibling-p
"org-export" (headline info
))
1354 (declare-function org-export-footnote-first-reference-p
"org-export"
1355 (footnote-reference info
))
1356 (declare-function org-export-get-coderef-format
"org-export" (path desc
))
1357 (declare-function org-export-get-footnote-definition
"org-export"
1358 (footnote-reference info
))
1359 (declare-function org-export-get-footnote-number
"org-export" (footnote info
))
1360 (declare-function org-export-get-previous-element
"org-export" (blob info
))
1361 (declare-function org-export-get-relative-level
"org-export" (headline info
))
1362 (declare-function org-export-handle-code
1363 "org-export" (element info
&optional num-fmt ref-fmt delayed
))
1364 (declare-function org-export-included-file
"org-export" (keyword backend info
))
1365 (declare-function org-export-inline-image-p
"org-export"
1366 (link &optional extensions
))
1367 (declare-function org-export-last-sibling-p
"org-export" (headline info
))
1368 (declare-function org-export-low-level-p
"org-export" (headline info
))
1369 (declare-function org-export-output-file-name
1370 "org-export" (extension &optional subtreep pub-dir
))
1371 (declare-function org-export-resolve-coderef
"org-export" (ref info
))
1372 (declare-function org-export-resolve-fuzzy-link
"org-export" (link info
))
1373 (declare-function org-export-solidify-link-text
"org-export" (s))
1375 org-export-to-buffer
"org-export"
1376 (backend buffer
&optional subtreep visible-only body-only ext-plist
))
1378 org-export-to-file
"org-export"
1379 (backend file
&optional subtreep visible-only body-only ext-plist
))
1381 (declare-function org-id-find-id-file
"org-id" (id))
1382 (declare-function htmlize-region
"ext:htmlize" (beg end
))
1383 (declare-function org-pop-to-buffer-same-window
1384 "org-compat" (&optional buffer-or-name norecord label
))
1390 (declare-function hfy-face-to-style
"htmlfontify" (fn))
1391 (declare-function hfy-face-or-def-to-name
"htmlfontify" (fn))
1392 (declare-function archive-zip-extract
"arc-mode.el" (archive name
))
1394 ;;; Internal Variables
1396 ;;;; ODT Internal Variables
1398 (defconst org-e-odt-lib-dir
1399 (file-name-directory load-file-name
)
1400 "Location of ODT exporter.
1401 Use this to infer values of `org-e-odt-styles-dir' and
1402 `org-e-odt-schema-dir'.")
1404 (defvar org-e-odt-data-dir
1405 (expand-file-name "../../etc/" org-e-odt-lib-dir
)
1406 "Data directory for ODT exporter.
1407 Use this to infer values of `org-e-odt-styles-dir' and
1408 `org-e-odt-schema-dir'.")
1410 (defconst org-e-odt-special-string-regexps
1411 '(("\\\\-" .
"­\\1") ; shy
1412 ("---\\([^-]\\)" .
"—\\1") ; mdash
1413 ("--\\([^-]\\)" .
"–\\1") ; ndash
1414 ("\\.\\.\\." .
"…")) ; hellip
1415 "Regular expressions for special string conversion.")
1417 (defconst org-e-odt-schema-dir-list
1419 (and org-e-odt-data-dir
1420 (expand-file-name "./schema/" org-e-odt-data-dir
)) ; bail out
1422 (and (boundp 'org-e-odt-data-dir
) org-e-odt-data-dir
; see make install
1423 (expand-file-name "./schema/" org-e-odt-data-dir
))))
1424 "List of directories to search for OpenDocument schema files.
1425 Use this list to set the default value of
1426 `org-e-odt-schema-dir'. The entries in this list are
1427 populated heuristically based on the values of `org-e-odt-lib-dir'
1428 and `org-e-odt-data-dir'.")
1430 (defconst org-e-odt-styles-dir-list
1432 (and org-e-odt-data-dir
1433 (expand-file-name "./styles/" org-e-odt-data-dir
)) ; bail out
1435 (and (boundp 'org-e-odt-data-dir
) org-e-odt-data-dir
; see make install
1436 (expand-file-name "./styles/" org-e-odt-data-dir
)))
1437 (expand-file-name "../../etc/styles/" org-e-odt-lib-dir
) ; git
1438 (expand-file-name "./etc/styles/" org-e-odt-lib-dir
) ; elpa
1439 (expand-file-name "./org/" data-directory
) ; system
1441 "List of directories to search for OpenDocument styles files.
1442 See `org-e-odt-styles-dir'. The entries in this list are populated
1443 heuristically based on the values of `org-e-odt-lib-dir' and
1444 `org-e-odt-data-dir'.")
1446 (defconst org-e-odt-styles-dir
1449 (message "Debug (org-e-odt): Searching for OpenDocument styles files...")
1450 (mapc (lambda (styles-dir)
1452 (message "Debug (org-e-odt): Trying %s..." styles-dir
)
1453 (when (and (file-readable-p
1455 "OrgOdtContentTemplate.xml" styles-dir
))
1458 "OrgOdtStyles.xml" styles-dir
)))
1459 (message "Debug (org-e-odt): Using styles under %s"
1461 (throw 'styles-dir styles-dir
))))
1462 org-e-odt-styles-dir-list
)
1465 (error "Error (org-e-odt): Cannot find factory styles files. Aborting."))
1467 "Directory that holds auxiliary XML files used by the ODT exporter.
1469 This directory contains the following XML files -
1470 \"OrgOdtStyles.xml\" and \"OrgOdtContentTemplate.xml\". These
1471 XML files are used as the default values of
1472 `org-e-odt-styles-file' and
1473 `org-e-odt-content-template-file'.
1475 The default value of this variable varies depending on the
1476 version of org in use and is initialized from
1477 `org-e-odt-styles-dir-list'. Note that the user could be using org
1478 from one of: org's own private git repository, GNU ELPA tar or
1481 (defconst org-e-odt-tmpdir-prefix
"%s-")
1482 (defconst org-e-odt-bookmark-prefix
"OrgXref.")
1484 (defconst org-e-odt-manifest-file-entry-tag
1486 <manifest:file-entry manifest:media-type=\"%s\" manifest:full-path=\"%s\"%s/>")
1490 (defvar org-lparse-dyn-first-heading-pos
) ; let bound during org-do-lparse
1492 (defvar org-e-odt-suppress-xref nil
)
1493 (defvar org-e-odt-file-extensions
1494 '(("odt" .
"OpenDocument Text")
1495 ("ott" .
"OpenDocument Text Template")
1496 ("odm" .
"OpenDocument Master Document")
1497 ("ods" .
"OpenDocument Spreadsheet")
1498 ("ots" .
"OpenDocument Spreadsheet Template")
1499 ("odg" .
"OpenDocument Drawing (Graphics)")
1500 ("otg" .
"OpenDocument Drawing Template")
1501 ("odp" .
"OpenDocument Presentation")
1502 ("otp" .
"OpenDocument Presentation Template")
1503 ("odi" .
"OpenDocument Image")
1504 ("odf" .
"OpenDocument Formula")
1505 ("odc" .
"OpenDocument Chart")))
1507 (defvar org-e-odt-default-org-styles-alist
1508 '((paragraph .
((default .
"Text_20_body")
1509 (fixedwidth .
"OrgFixedWidthBlock")
1510 (verse .
"OrgVerse")
1511 (quote .
"Quotations")
1512 (blockquote .
"Quotations")
1513 (center .
"OrgCenter")
1515 (right .
"OrgRight")
1516 (title .
"OrgTitle")
1517 (subtitle .
"OrgSubtitle")
1518 (footnote .
"Footnote")
1519 (src .
"OrgSrcBlock")
1520 (illustration .
"Illustration")
1522 (listing .
"Listing")
1523 (definition-term .
"Text_20_body_20_bold")
1524 (horizontal-line .
"Horizontal_20_Line")))
1525 (character .
((bold .
"Bold")
1526 (emphasis .
"Emphasis")
1528 (verbatim .
"OrgCode")
1529 (strike .
"Strikethrough")
1530 (underline .
"Underline")
1531 (subscript .
"OrgSubscript")
1532 (superscript .
"OrgSuperscript")))
1533 (list .
((ordered .
"OrgNumberedList")
1534 (unordered .
"OrgBulletedList")
1535 (descriptive .
"OrgDescriptionList"))))
1536 "Default styles for various entities.")
1538 (defvar org-e-odt-org-styles-alist org-e-odt-default-org-styles-alist
)
1541 ;;;_. control callbacks
1542 ;;;_ , document body
1544 (defvar org-lparse-body-only
) ; let bound during org-do-lparse
1545 (defvar org-lparse-opt-plist
) ; bound during org-do-lparse
1546 (defvar org-lparse-list-stack
) ; dynamically bound in org-do-lparse
1547 (defvar org-e-odt-list-stack-stashed
)
1548 (defvar org-lparse-table-ncols
)
1549 (defvar org-e-odt-table-rowgrp-open
)
1550 (defvar org-e-odt-table-rownum
)
1551 (defvar org-e-odt-table-cur-rowgrp-is-hdr
)
1552 (defvar org-lparse-table-is-styled
)
1553 (defvar org-lparse-table-rowgrp-info
)
1554 (defvar org-lparse-table-colalign-vector
)
1556 (defvar org-e-odt-table-style nil
1557 "Table style specified by \"#+ATTR_ODT: <style-name>\" line.
1558 This is set during `org-e-odt-begin-table'.")
1560 (defvar org-e-odt-table-style-spec nil
1561 "Entry for `org-e-odt-table-style' in `org-e-odt-table-styles'.")
1564 (defvar org-e-odt-table-style-format
1566 <style:style style:name=\"%s\" style:family=\"table\">
1567 <style:table-properties style:rel-width=\"%d%%\" fo:margin-top=\"0cm\" fo:margin-bottom=\"0.20cm\" table:align=\"center\"/>
1570 "Template for auto-generated Table styles.")
1572 (defvar org-e-odt-automatic-styles
'()
1573 "Registry of automatic styles for various OBJECT-TYPEs.
1574 The variable has the following form:
1576 \(\(OBJECT-NAME-A.1 OBJECT-PROPS-A.1\)
1577 \(OBJECT-NAME-A.2 OBJECT-PROPS-A.2\) ...\)\)
1579 \(\(OBJECT-NAME-B.1 OBJECT-PROPS-B.1\)
1580 \(OBJECT-NAME-B.2 OBJECT-PROPS-B.2\) ...\)\)
1583 OBJECT-TYPEs could be \"Section\", \"Table\", \"Figure\" etc.
1584 OBJECT-PROPS is (typically) a plist created by passing
1585 \"#+ATTR_ODT: \" option to `org-e-odt-parse-block-attributes'.
1587 Use `org-e-odt-add-automatic-style' to add update this variable.'")
1589 (defvar org-e-odt-object-counters nil
1590 "Running counters for various OBJECT-TYPEs.
1591 Use this to generate automatic names and style-names. See
1592 `org-e-odt-add-automatic-style'.")
1594 (defvar org-e-odt-table-indentedp nil
)
1595 (defvar org-lparse-table-colalign-info
)
1596 (defvar org-lparse-link-description-is-image nil
)
1599 (defvar org-src-block-paragraph-format
1600 "<style:style style:name=\"OrgSrcBlock\" style:family=\"paragraph\" style:parent-style-name=\"Preformatted_20_Text\">
1601 <style:paragraph-properties fo:background-color=\"%s\" fo:padding=\"0.049cm\" fo:border=\"0.51pt solid #000000\" style:shadow=\"none\">
1602 <style:background-image/>
1603 </style:paragraph-properties>
1604 <style:text-properties fo:color=\"%s\"/>
1606 "Custom paragraph style for colorized source and example blocks.
1607 This style is much the same as that of \"OrgFixedWidthBlock\"
1608 except that the foreground and background colors are set
1609 according to the default face identified by the `htmlfontify'.")
1611 (defvar hfy-optimisations
)
1612 (defvar org-e-odt-embedded-formulas-count
0)
1613 (defvar org-e-odt-entity-frame-styles
1614 '(("As-CharImage" "__Figure__" ("OrgInlineImage" nil
"as-char"))
1615 ("ParagraphImage" "__Figure__" ("OrgDisplayImage" nil
"paragraph"))
1616 ("PageImage" "__Figure__" ("OrgPageImage" nil
"page"))
1617 ("CaptionedAs-CharImage" "__Figure__"
1618 ("OrgCaptionedImage"
1619 " style:rel-width=\"100%\" style:rel-height=\"scale\"" "paragraph")
1620 ("OrgInlineImage" nil
"as-char"))
1621 ("CaptionedParagraphImage" "__Figure__"
1622 ("OrgCaptionedImage"
1623 " style:rel-width=\"100%\" style:rel-height=\"scale\"" "paragraph")
1624 ("OrgImageCaptionFrame" nil
"paragraph"))
1625 ("CaptionedPageImage" "__Figure__"
1626 ("OrgCaptionedImage"
1627 " style:rel-width=\"100%\" style:rel-height=\"scale\"" "paragraph")
1628 ("OrgPageImageCaptionFrame" nil
"page"))
1629 ("InlineFormula" "__MathFormula__" ("OrgInlineFormula" nil
"as-char"))
1630 ("DisplayFormula" "__MathFormula__" ("OrgDisplayFormula" nil
"as-char"))
1631 ("CaptionedDisplayFormula" "__MathFormula__"
1632 ("OrgCaptionedFormula" nil
"paragraph")
1633 ("OrgFormulaCaptionFrame" nil
"as-char"))))
1635 (defvar org-e-odt-embedded-images-count
0)
1637 (defvar org-e-odt-image-size-probe-method
1638 (append (and (executable-find "identify") '(imagemagick)) ; See Bug#10675
1640 "Ordered list of methods for determining image sizes.")
1642 (defvar org-e-odt-default-image-sizes-alist
1643 '(("as-char" .
(5 .
0.4))
1644 ("paragraph" .
(5 .
5)))
1645 "Hardcoded image dimensions one for each of the anchor
1648 ;; A4 page size is 21.0 by 29.7 cms
1649 ;; The default page settings has 2cm margin on each of the sides. So
1650 ;; the effective text area is 17.0 by 25.7 cm
1651 (defvar org-e-odt-max-image-size
'(17.0 .
20.0)
1652 "Limiting dimensions for an embedded image.")
1654 (defvar org-e-odt-entity-labels-alist nil
1655 "Associate Labels with the Labeled entities.
1656 Each element of the alist is of the form (LABEL-NAME
1657 CATEGORY-NAME SEQNO LABEL-STYLE-NAME). LABEL-NAME is same as
1658 that specified by \"#+LABEL: ...\" line. CATEGORY-NAME is the
1659 type of the entity that LABEL-NAME is attached to. CATEGORY-NAME
1660 can be one of \"Table\", \"Figure\" or \"Equation\". SEQNO is
1661 the unique number assigned to the referenced entity on a
1662 per-CATEGORY basis. It is generated sequentially and is 1-based.
1663 LABEL-STYLE-NAME is a key `org-e-odt-label-styles'.
1665 See `org-e-odt-add-label-definition' and
1666 `org-e-odt-fixup-label-references'.")
1668 (defvar org-e-odt-entity-counts-plist nil
1669 "Plist of running counters of SEQNOs for each of the CATEGORY-NAMEs.
1670 See `org-e-odt-entity-labels-alist' for known CATEGORY-NAMEs.")
1672 (defvar org-e-odt-label-styles
1673 '(("math-formula" "%c" "text" "(%n)")
1674 ("math-label" "(%n)" "text" "(%n)")
1675 ("category-and-value" "%e %n: %c" "category-and-value" "%e %n")
1676 ("value" "%e %n: %c" "value" "%n"))
1677 "Specify how labels are applied and referenced.
1678 This is an alist where each element is of the
1679 form (LABEL-STYLE-NAME LABEL-ATTACH-FMT LABEL-REF-MODE
1682 LABEL-ATTACH-FMT controls how labels and captions are attached to
1683 an entity. It may contain following specifiers - %e, %n and %c.
1684 %e is replaced with the CATEGORY-NAME. %n is replaced with
1685 \"<text:sequence ...> SEQNO </text:sequence>\". %c is replaced
1686 with CAPTION. See `org-e-odt-format-label-definition'.
1688 LABEL-REF-MODE and LABEL-REF-FMT controls how label references
1689 are generated. The following XML is generated for a label
1690 reference - \"<text:sequence-ref
1691 text:reference-format=\"LABEL-REF-MODE\" ...> LABEL-REF-FMT
1692 </text:sequence-ref>\". LABEL-REF-FMT may contain following
1693 specifiers - %e and %n. %e is replaced with the CATEGORY-NAME.
1694 %n is replaced with SEQNO. See
1695 `org-e-odt-format-label-reference'.")
1697 (defcustom org-e-odt-category-strings
1698 '(("en" "Table" "Figure" "Equation" "Equation" "Listing"))
1699 "Specify category strings for various captionable entities.
1700 Captionable entity can be one of a Table, an Embedded Image, a
1701 LaTeX fragment (generated with dvipng) or a Math Formula.
1703 For example, when `org-export-default-language' is \"en\", an
1704 embedded image will be captioned as \"Figure 1: Orgmode Logo\".
1705 If you want the images to be captioned instead as \"Illustration
1706 1: Orgmode Logo\", then modify the entry for \"en\" as shown
1709 \(setq org-e-odt-category-strings
1710 '\(\(\"en\" \"Table\" \"Illustration\"
1711 \"Equation\" \"Equation\"\)\)\)"
1712 :group
'org-export-e-odt
1714 :type
'(repeat (list (string :tag
"Language tag")
1715 (choice :tag
"Table"
1716 (const :tag
"Use Default" nil
)
1717 (string :tag
"Category string"))
1718 (choice :tag
"Figure"
1719 (const :tag
"Use Default" nil
)
1720 (string :tag
"Category string"))
1721 (choice :tag
"Math Formula"
1722 (const :tag
"Use Default" nil
)
1723 (string :tag
"Category string"))
1724 (choice :tag
"Dvipng Image"
1725 (const :tag
"Use Default" nil
)
1726 (string :tag
"Category string"))
1727 (choice :tag
"Listing"
1728 (const :tag
"Use Default" nil
)
1729 (string :tag
"Category string")))))
1731 (defvar org-e-odt-category-map-alist
1732 '(("__Table__" "Table" "value")
1733 ("__Figure__" "Illustration" "value")
1734 ("__MathFormula__" "Text" "math-formula")
1735 ("__DvipngImage__" "Equation" "value")
1736 ("__Listing__" "Listing" "value")
1737 ;; ("__Table__" "Table" "category-and-value")
1738 ;; ("__Figure__" "Figure" "category-and-value")
1739 ;; ("__DvipngImage__" "Equation" "category-and-value")
1741 "Map a CATEGORY-HANDLE to OD-VARIABLE and LABEL-STYLE.
1742 This is a list where each entry is of the form \\(CATEGORY-HANDLE
1743 OD-VARIABLE LABEL-STYLE\\). CATEGORY_HANDLE identifies the
1744 captionable entity in question. OD-VARIABLE is the OpenDocument
1745 sequence counter associated with the entity. These counters are
1747 \"<text:sequence-decls>...</text:sequence-decls>\" block of
1748 `org-e-odt-content-template-file'. LABEL-STYLE is a key
1749 into `org-e-odt-label-styles' and specifies how a given entity
1750 should be captioned and referenced.
1752 The position of a CATEGORY-HANDLE in this list is used as an
1753 index in to per-language entry for
1754 `org-e-odt-category-strings' to retrieve a CATEGORY-NAME.
1755 This CATEGORY-NAME is then used for qualifying the user-specified
1756 captions on export.")
1758 (defvar org-e-odt-manifest-file-entries nil
)
1759 (defvar hfy-user-sheet-assoc
) ; bound during org-do-lparse
1760 (defvar org-lparse-latex-fragment-fallback
) ; set by org-do-lparse
1763 ;;;; HTML Internal Variables
1765 (defvar org-e-odt-option-alist
1767 ;; (:agenda-style nil nil org-agenda-export-html-style)
1768 ;; (:convert-org-links nil nil org-e-odt-link-org-files-as-html)
1769 ;; ;; FIXME Use (org-xml-encode-org-text-skip-links s) ??
1770 ;; ;; (:expand-quoted-html nil "@" org-e-odt-expand)
1771 ;; (:inline-images nil nil org-e-odt-inline-images)
1772 ;; ;; (:link-home nil nil org-e-odt-link-home) FIXME
1773 ;; ;; (:link-up nil nil org-e-odt-link-up) FIXME
1774 ;; (:style nil nil org-e-odt-style)
1775 ;; (:style-extra nil nil org-e-odt-style-extra)
1776 ;; (:style-include-default nil nil org-e-odt-style-include-default)
1777 ;; (:style-include-scripts nil nil org-e-odt-style-include-scripts)
1778 ;; ;; (:timestamp nil nil org-e-odt-with-timestamp)
1779 ;; (:html-extension nil nil org-e-odt-extension)
1780 ;; (:html-postamble nil nil org-e-odt-postamble)
1781 ;; (:html-preamble nil nil org-e-odt-preamble)
1782 ;; (:html-table-tag nil nil org-e-odt-table-tag)
1783 ;; (:xml-declaration nil nil org-e-odt-xml-declaration)
1784 (:odt-styles-file
"ODT_STYLES_FILE" nil nil t
)
1785 (:LaTeX-fragments nil
"LaTeX" org-export-with-LaTeX-fragments
))
1786 "Alist between export properties and ways to set them.
1788 The car of the alist is the property name, and the cdr is a list
1789 like \(KEYWORD OPTION DEFAULT BEHAVIOUR\) where:
1791 KEYWORD is a string representing a buffer keyword, or nil.
1792 OPTION is a string that could be found in an #+OPTIONS: line.
1793 DEFAULT is the default value for the property.
1794 BEHAVIOUR determine how Org should handle multiple keywords for
1795 the same property. It is a symbol among:
1796 nil Keep old value and discard the new one.
1797 t Replace old value with the new one.
1798 `space' Concatenate the values, separating them with a space.
1799 `newline' Concatenate the values, separating them with
1801 `split' Split values at white spaces, and cons them to the
1804 KEYWORD and OPTION have precedence over DEFAULT.
1806 All these properties should be back-end agnostic. For back-end
1807 specific properties, define a similar variable named
1808 `org-BACKEND-option-alist', replacing BACKEND with the name of
1809 the appropriate back-end. You can also redefine properties
1810 there, as they have precedence over these.")
1812 (defvar html-table-tag nil
) ; dynamically scoped into this.
1814 ;; FIXME: it already exists in org-e-odt.el
1815 (defconst org-e-odt-cvt-link-fn
1817 "Function to convert link URLs to exportable URLs.
1818 Takes two arguments, TYPE and PATH.
1819 Returns exportable url as (TYPE PATH), or nil to signal that it
1820 didn't handle this case.
1821 Intended to be locally bound around a call to `org-export-as-html'." )
1826 (defvar org-e-odt-format-table-no-css
)
1827 (defvar htmlize-buffer-places
) ; from htmlize.el
1828 (defvar body-only
) ; dynamically scoped into this.
1830 (defvar org-e-odt-table-rowgrp-open
)
1831 (defvar org-e-odt-table-rownum
)
1832 (defvar org-e-odt-table-cur-rowgrp-is-hdr
)
1833 (defvar org-lparse-table-is-styled
)
1836 (defvar org-e-odt-headline-formatter
1837 (lambda (level snumber todo todo-type priority
1838 title tags target extra-targets extra-class
)
1839 (concat snumber
" " title
)))
1843 ;;; User Configuration Variables
1845 (defgroup org-export-e-odt nil
1846 "Options for exporting Org mode files to ODT."
1847 :tag
"Org Export ODT"
1850 (defcustom org-e-odt-protect-char-alist
1854 "Alist of characters to be converted by `org-e-html-protect'."
1855 :group
'org-export-e-html
1856 :type
'(repeat (cons (string :tag
"Character")
1857 (string :tag
"ODT equivalent"))))
1858 (defcustom org-e-odt-schema-dir
1861 (message "Debug (org-e-odt): Searching for OpenDocument schema files...")
1863 (lambda (schema-dir)
1865 (message "Debug (org-e-odt): Trying %s..." schema-dir
)
1866 (when (and (file-readable-p
1867 (expand-file-name "od-manifest-schema-v1.2-cs01.rnc"
1870 (expand-file-name "od-schema-v1.2-cs01.rnc"
1873 (expand-file-name "schemas.xml" schema-dir
)))
1874 (message "Debug (org-e-odt): Using schema files under %s"
1876 (throw 'schema-dir schema-dir
))))
1877 org-e-odt-schema-dir-list
)
1878 (message "Debug (org-e-odt): No OpenDocument schema files installed")
1881 "Directory that contains OpenDocument schema files.
1883 This directory contains:
1884 1. rnc files for OpenDocument schema
1885 2. a \"schemas.xml\" file that specifies locating rules needed
1886 for auto validation of OpenDocument XML files.
1888 Use the customize interface to set this variable. This ensures
1889 that `rng-schema-locating-files' is updated and auto-validation
1890 of OpenDocument XML takes place based on the value
1891 `rng-nxml-auto-validate-flag'.
1893 The default value of this variable varies depending on the
1894 version of org in use and is initialized from
1895 `org-e-odt-schema-dir-list'. The OASIS schema files are available
1896 only in the org's private git repository. It is *not* bundled
1897 with GNU ELPA tar or standard Emacs distribution."
1899 (const :tag
"Not set" nil
)
1900 (directory :tag
"Schema directory"))
1901 :group
'org-export-e-odt
1905 "Set `org-e-odt-schema-dir'.
1906 Also add it to `rng-schema-locating-files'."
1907 (let ((schema-dir value
))
1911 (expand-file-name "od-manifest-schema-v1.2-cs01.rnc" schema-dir
))
1913 (expand-file-name "od-schema-v1.2-cs01.rnc" schema-dir
))
1915 (expand-file-name "schemas.xml" schema-dir
)))
1918 (message "Error (org-e-odt): %s has no OpenDocument schema files"
1921 (when org-e-odt-schema-dir
1922 (eval-after-load 'rng-loc
1923 '(add-to-list 'rng-schema-locating-files
1924 (expand-file-name "schemas.xml"
1925 org-e-odt-schema-dir
))))))
1927 (defcustom org-e-odt-content-template-file nil
1928 "Template file for \"content.xml\".
1929 The exporter embeds the exported content just before
1930 \"</office:text>\" element.
1932 If unspecified, the file named \"OrgOdtContentTemplate.xml\"
1933 under `org-e-odt-styles-dir' is used."
1935 :group
'org-export-e-odt
1938 (defcustom org-e-odt-styles-file nil
1939 "Default styles file for use with ODT export.
1940 Valid values are one of:
1942 2. path to a styles.xml file
1943 3. path to a *.odt or a *.ott file
1944 4. list of the form (ODT-OR-OTT-FILE (FILE-MEMBER-1 FILE-MEMBER-2
1947 In case of option 1, an in-built styles.xml is used. See
1948 `org-e-odt-styles-dir' for more information.
1950 In case of option 3, the specified file is unzipped and the
1951 styles.xml embedded therein is used.
1953 In case of option 4, the specified ODT-OR-OTT-FILE is unzipped
1954 and FILE-MEMBER-1, FILE-MEMBER-2 etc are copied in to the
1955 generated odt file. Use relative path for specifying the
1956 FILE-MEMBERS. styles.xml must be specified as one of the
1959 Use options 1, 2 or 3 only if styles.xml alone suffices for
1960 achieving the desired formatting. Use option 4, if the styles.xml
1961 references additional files like header and footer images for
1962 achieving the desired formatting.
1964 Use \"#+ODT_STYLES_FILE: ...\" directive to set this variable on
1965 a per-file basis. For example,
1967 #+ODT_STYLES_FILE: \"/path/to/styles.xml\" or
1968 #+ODT_STYLES_FILE: (\"/path/to/file.ott\" (\"styles.xml\" \"image/hdr.png\"))."
1969 :group
'org-export-e-odt
1973 (const :tag
"Factory settings" nil
)
1974 (file :must-match t
:tag
"styles.xml")
1975 (file :must-match t
:tag
"ODT or OTT file")
1976 (list :tag
"ODT or OTT file + Members"
1977 (file :must-match t
:tag
"ODF Text or Text Template file")
1978 (cons :tag
"Members"
1979 (file :tag
" Member" "styles.xml")
1980 (repeat (file :tag
"Member"))))))
1983 (defcustom org-e-odt-inline-image-extensions
1984 '("png" "jpeg" "jpg" "gif")
1985 "Extensions of image files that can be inlined into HTML."
1986 :type
'(repeat (string :tag
"Extension"))
1987 :group
'org-export-e-odt
1990 (defcustom org-e-odt-pixels-per-inch display-pixels-per-inch
1991 "Scaling factor for converting images pixels to inches.
1992 Use this for sizing of embedded images. See Info node `(org)
1993 Images in ODT export' for more information."
1995 :group
'org-export-e-odt
1998 (defcustom org-e-odt-create-custom-styles-for-srcblocks t
1999 "Whether custom styles for colorized source blocks be automatically created.
2000 When this option is turned on, the exporter creates custom styles
2001 for source blocks based on the advice of `htmlfontify'. Creation
2002 of custom styles happen as part of `org-e-odt-hfy-face-to-css'.
2004 When this option is turned off exporter does not create such
2007 Use the latter option if you do not want the custom styles to be
2008 based on your current display settings. It is necessary that the
2009 styles.xml already contains needed styles for colorizing to work.
2011 This variable is effective only if
2012 `org-e-odt-fontify-srcblocks' is turned on."
2013 :group
'org-export-e-odt
2017 (defcustom org-e-odt-preferred-output-format nil
2018 "Automatically post-process to this format after exporting to \"odt\".
2019 Interactive commands `org-export-as-e-odt' and
2020 `org-export-as-e-odt-and-open' export first to \"odt\" format and
2021 then use `org-e-odt-convert-process' to convert the
2022 resulting document to this format. During customization of this
2023 variable, the list of valid values are populated based on
2024 `org-e-odt-convert-capabilities'."
2025 :group
'org-export-e-odt
2027 :type
'(choice :convert-widget
2029 (apply 'widget-convert
(widget-type w
)
2030 (eval (car (widget-get w
:args
)))))
2031 `((const :tag
"None" nil
)
2032 ,@(mapcar (lambda (c)
2033 `(const :tag
,c
,c
))
2034 (org-e-odt-reachable-formats "odt")))))
2036 (defcustom org-e-odt-table-styles
2037 '(("OrgEquation" "OrgEquation"
2038 ((use-first-column-styles . t
)
2039 (use-last-column-styles . t
))))
2040 "Specify how Table Styles should be derived from a Table Template.
2041 This is a list where each element is of the
2042 form (TABLE-STYLE-NAME TABLE-TEMPLATE-NAME TABLE-CELL-OPTIONS).
2044 TABLE-STYLE-NAME is the style associated with the table through
2045 `org-e-odt-table-style'.
2047 TABLE-TEMPLATE-NAME is a set of - upto 9 - automatic
2048 TABLE-CELL-STYLE-NAMEs and PARAGRAPH-STYLE-NAMEs (as defined
2049 below) that is included in
2050 `org-e-odt-content-template-file'.
2052 TABLE-CELL-STYLE-NAME := TABLE-TEMPLATE-NAME + TABLE-CELL-TYPE +
2054 PARAGRAPH-STYLE-NAME := TABLE-TEMPLATE-NAME + TABLE-CELL-TYPE +
2056 TABLE-CELL-TYPE := \"FirstRow\" | \"LastColumn\" |
2057 \"FirstRow\" | \"LastRow\" |
2058 \"EvenRow\" | \"OddRow\" |
2059 \"EvenColumn\" | \"OddColumn\" | \"\"
2060 where \"+\" above denotes string concatenation.
2062 TABLE-CELL-OPTIONS is an alist where each element is of the
2063 form (TABLE-CELL-STYLE-SELECTOR . ON-OR-OFF).
2064 TABLE-CELL-STYLE-SELECTOR := `use-first-row-styles' |
2065 `use-last-row-styles' |
2066 `use-first-column-styles' |
2067 `use-last-column-styles' |
2068 `use-banding-rows-styles' |
2069 `use-banding-columns-styles' |
2070 `use-first-row-styles'
2071 ON-OR-OFF := `t' | `nil'
2073 For example, with the following configuration
2075 \(setq org-e-odt-table-styles
2076 '\(\(\"TableWithHeaderRowsAndColumns\" \"Custom\"
2077 \(\(use-first-row-styles . t\)
2078 \(use-first-column-styles . t\)\)\)
2079 \(\"TableWithHeaderColumns\" \"Custom\"
2080 \(\(use-first-column-styles . t\)\)\)\)\)
2082 1. A table associated with \"TableWithHeaderRowsAndColumns\"
2083 style will use the following table-cell styles -
2084 \"CustomFirstRowTableCell\", \"CustomFirstColumnTableCell\",
2085 \"CustomTableCell\" and the following paragraph styles
2086 \"CustomFirstRowTableParagraph\",
2087 \"CustomFirstColumnTableParagraph\", \"CustomTableParagraph\"
2090 2. A table associated with \"TableWithHeaderColumns\" style will
2091 use the following table-cell styles -
2092 \"CustomFirstColumnTableCell\", \"CustomTableCell\" and the
2093 following paragraph styles
2094 \"CustomFirstColumnTableParagraph\", \"CustomTableParagraph\"
2097 Note that TABLE-TEMPLATE-NAME corresponds to the
2098 \"<table:table-template>\" elements contained within
2099 \"<office:styles>\". The entries (TABLE-STYLE-NAME
2100 TABLE-TEMPLATE-NAME TABLE-CELL-OPTIONS) correspond to
2101 \"table:template-name\" and \"table:use-first-row-styles\" etc
2102 attributes of \"<table:table>\" element. Refer ODF-1.2
2103 specification for more information. Also consult the
2104 implementation filed under `org-e-odt-get-table-cell-styles'.
2106 The TABLE-STYLE-NAME \"OrgEquation\" is used internally for
2107 formatting of numbered display equations. Do not delete this
2108 style from the list."
2109 :group
'org-export-e-odt
2112 (const :tag
"None" nil
)
2113 (repeat :tag
"Table Styles"
2114 (list :tag
"Table Style Specification"
2115 (string :tag
"Table Style Name")
2116 (string :tag
"Table Template Name")
2117 (alist :options
(use-first-row-styles
2119 use-first-column-styles
2120 use-last-column-styles
2121 use-banding-rows-styles
2122 use-banding-columns-styles
)
2124 :value-type
(const :tag
"True" t
))))))
2125 (defcustom org-e-odt-fontify-srcblocks t
2126 "Specify whether or not source blocks need to be fontified.
2127 Turn this option on if you want to colorize the source code
2128 blocks in the exported file. For colorization to work, you need
2129 to make available an enhanced version of `htmlfontify' library."
2131 :group
'org-export-e-odt
2134 (defcustom org-e-odt-prettify-xml t
; FIXME
2135 "Specify whether or not the xml output should be prettified.
2136 When this option is turned on, `indent-region' is run on all
2137 component xml buffers before they are saved. Turn this off for
2138 regular use. Turn this on if you need to examine the xml
2140 :group
'org-export-e-odt
2144 (defcustom org-e-odt-convert-processes
2146 "soffice --headless --convert-to %f%x --outdir %d %i")
2148 "unoconv -f %f -o %d %i"))
2149 "Specify a list of document converters and their usage.
2150 The converters in this list are offered as choices while
2151 customizing `org-e-odt-convert-process'.
2153 This variable is a list where each element is of the
2154 form (CONVERTER-NAME CONVERTER-CMD). CONVERTER-NAME is the name
2155 of the converter. CONVERTER-CMD is the shell command for the
2156 converter and can contain format specifiers. These format
2157 specifiers are interpreted as below:
2159 %i input file name in full
2160 %I input file name as a URL
2161 %f format of the output file
2162 %o output file name in full
2163 %O output file name as a URL
2164 %d output dir in full
2165 %D output dir as a URL.
2166 %x extra options as set in `org-e-odt-convert-capabilities'."
2167 :group
'org-export-e-odt
2171 (const :tag
"None" nil
)
2172 (alist :tag
"Converters"
2173 :key-type
(string :tag
"Converter Name")
2174 :value-type
(group (string :tag
"Command line")))))
2176 (defcustom org-e-odt-convert-process
"LibreOffice"
2177 "Use this converter to convert from \"odt\" format to other formats.
2178 During customization, the list of converter names are populated
2179 from `org-e-odt-convert-processes'."
2180 :group
'org-export-e-odt
2182 :type
'(choice :convert-widget
2184 (apply 'widget-convert
(widget-type w
)
2185 (eval (car (widget-get w
:args
)))))
2186 `((const :tag
"None" nil
)
2187 ,@(mapcar (lambda (c)
2188 `(const :tag
,(car c
) ,(car c
)))
2189 org-e-odt-convert-processes
))))
2191 (defcustom org-e-odt-convert-capabilities
2193 ("odt" "ott" "doc" "rtf" "docx")
2194 (("pdf" "pdf") ("odt" "odt") ("rtf" "rtf") ("ott" "ott")
2195 ("doc" "doc" ":\"MS Word 97\"") ("docx" "docx") ("html" "html")))
2198 (("pdf" "pdf") ("odt" "odt") ("html" "html")))
2200 ("ods" "ots" "xls" "csv" "xlsx")
2201 (("pdf" "pdf") ("ots" "ots") ("html" "html") ("csv" "csv") ("ods" "ods")
2202 ("xls" "xls") ("xlsx" "xlsx")))
2204 ("odp" "otp" "ppt" "pptx")
2205 (("pdf" "pdf") ("swf" "swf") ("odp" "odp") ("otp" "otp") ("ppt" "ppt")
2206 ("pptx" "pptx") ("odg" "odg"))))
2207 "Specify input and output formats of `org-e-odt-convert-process'.
2208 More correctly, specify the set of input and output formats that
2209 the user is actually interested in.
2211 This variable is an alist where each element is of the
2212 form (DOCUMENT-CLASS INPUT-FMT-LIST OUTPUT-FMT-ALIST).
2213 INPUT-FMT-LIST is a list of INPUT-FMTs. OUTPUT-FMT-ALIST is an
2214 alist where each element is of the form (OUTPUT-FMT
2215 OUTPUT-FILE-EXTENSION EXTRA-OPTIONS).
2217 The variable is interpreted as follows:
2218 `org-e-odt-convert-process' can take any document that is in
2219 INPUT-FMT-LIST and produce any document that is in the
2220 OUTPUT-FMT-LIST. A document converted to OUTPUT-FMT will have
2221 OUTPUT-FILE-EXTENSION as the file name extension. OUTPUT-FMT
2222 serves dual purposes:
2223 - It is used for populating completion candidates during
2224 `org-e-odt-convert' commands.
2225 - It is used as the value of \"%f\" specifier in
2226 `org-e-odt-convert-process'.
2228 EXTRA-OPTIONS is used as the value of \"%x\" specifier in
2229 `org-e-odt-convert-process'.
2231 DOCUMENT-CLASS is used to group a set of file formats in
2232 INPUT-FMT-LIST in to a single class.
2234 Note that this variable inherently captures how LibreOffice based
2235 converters work. LibreOffice maps documents of various formats
2236 to classes like Text, Web, Spreadsheet, Presentation etc and
2237 allow document of a given class (irrespective of it's source
2238 format) to be converted to any of the export formats associated
2241 See default setting of this variable for an typical
2243 :group
'org-export-e-odt
2247 (const :tag
"None" nil
)
2248 (alist :tag
"Capabilities"
2249 :key-type
(string :tag
"Document Class")
2251 (group (repeat :tag
"Input formats" (string :tag
"Input format"))
2252 (alist :tag
"Output formats"
2253 :key-type
(string :tag
"Output format")
2255 (group (string :tag
"Output file extension")
2257 (const :tag
"None" nil
)
2258 (string :tag
"Extra options"))))))))
2265 ;;;; Document Header (Styles)
2267 ;;;; Document Header (Scripts)
2269 ;;;; Document Header (Mathjax)
2282 ;;;; Statistics Cookie
2302 ;;;; Horizontal Rule
2303 ;;;; Inline Babel Call
2304 ;;;; Inline Src Block
2308 ;;;; Latex Environment
2317 ;;;; Property Drawer
2343 ;;; User Configurable Variables (MAYBE)
2351 (defcustom org-e-odt-format-headline-function nil
2352 "Function to format headline text.
2354 This function will be called with 5 arguments:
2355 TODO the todo keyword \(string or nil\).
2356 TODO-TYPE the type of todo \(symbol: `todo', `done', nil\)
2357 PRIORITY the priority of the headline \(integer or nil\)
2358 TEXT the main headline text \(string\).
2359 TAGS the tags string, separated with colons \(string or nil\).
2361 The function result will be used in the section format string.
2363 As an example, one could set the variable to the following, in
2364 order to reproduce the default set-up:
2366 \(defun org-e-odt-format-headline \(todo todo-type priority text tags\)
2367 \"Default format function for an headline.\"
2368 \(concat \(when todo
2369 \(format \"\\\\textbf{\\\\textsc{\\\\textsf{%s}}} \" todo\)\)
2371 \(format \"\\\\framebox{\\\\#%c} \" priority\)\)
2373 \(when tags \(format \"\\\\hfill{}\\\\textsc{%s}\" tags\)\)\)\)"
2374 :group
'org-export-e-odt
2381 (defcustom org-e-odt-active-timestamp-format
"\\textit{%s}"
2382 "A printf format string to be applied to active timestamps."
2383 :group
'org-export-e-odt
2386 (defcustom org-e-odt-inactive-timestamp-format
"\\textit{%s}"
2387 "A printf format string to be applied to inactive timestamps."
2388 :group
'org-export-e-odt
2391 (defcustom org-e-odt-diary-timestamp-format
"\\textit{%s}"
2392 "A printf format string to be applied to diary timestamps."
2393 :group
'org-export-e-odt
2399 (defcustom org-e-odt-inline-image-rules
2400 '(("file" .
"\\.\\(jpeg\\|jpg\\|png\\|gif\\)\\'"))
2401 "Rules characterizing image files that can be inlined into HTML.
2403 A rule consists in an association whose key is the type of link
2404 to consider, and value is a regexp that will be matched against
2407 Note that, by default, the image extension *actually* allowed
2408 depend on the way the HTML file is processed. When used with
2409 pdflatex, pdf, jpg and png images are OK. When processing
2410 through dvi to Postscript, only ps and eps are allowed. The
2411 default we use here encompasses both."
2412 :group
'org-export-e-odt
2413 :type
'(alist :key-type
(string :tag
"Type")
2414 :value-type
(regexp :tag
"Path")))
2418 (defcustom org-e-odt-table-caption-above t
2419 "When non-nil, place caption string at the beginning of the table.
2420 Otherwise, place it near the end."
2421 :group
'org-export-e-odt
2426 (defcustom org-e-odt-format-drawer-function nil
2427 "Function called to format a drawer in HTML code.
2429 The function must accept two parameters:
2430 NAME the drawer name, like \"LOGBOOK\"
2431 CONTENTS the contents of the drawer.
2433 The function should return the string to be exported.
2435 For example, the variable could be set to the following function
2436 in order to mimic default behaviour:
2438 \(defun org-e-odt-format-drawer-default \(name contents\)
2439 \"Format a drawer element for HTML export.\"
2441 :group
'org-export-e-odt
2447 (defcustom org-e-odt-format-inlinetask-function nil
2448 "Function called to format an inlinetask in HTML code.
2450 The function must accept six parameters:
2451 TODO the todo keyword, as a string
2452 TODO-TYPE the todo type, a symbol among `todo', `done' and nil.
2453 PRIORITY the inlinetask priority, as a string
2454 NAME the inlinetask name, as a string.
2455 TAGS the inlinetask tags, as a string.
2456 CONTENTS the contents of the inlinetask, as a string.
2458 The function should return the string to be exported.
2460 For example, the variable could be set to the following function
2461 in order to mimic default behaviour:
2463 \(defun org-e-odt-format-inlinetask \(todo type priority name tags contents\)
2464 \"Format an inline task element for HTML export.\"
2465 \(let \(\(full-title
2468 \(format \"\\\\textbf{\\\\textsf{\\\\textsc{%s}}} \" todo\)\)
2469 \(when priority \(format \"\\\\framebox{\\\\#%c} \" priority\)\)
2471 \(when tags \(format \"\\\\hfill{}\\\\textsc{%s}\" tags\)\)\)\)\)
2472 \(format \(concat \"\\\\begin{center}\\n\"
2474 \"\\\\begin{minipage}[c]{.6\\\\textwidth}\\n\"
2476 \"\\\\rule[.8em]{\\\\textwidth}{2pt}\\n\\n\"
2478 \"\\\\end{minipage}}\"
2479 \"\\\\end{center}\"\)
2480 full-title contents\)\)"
2481 :group
'org-export-e-odt
2489 (defcustom org-e-odt-quotes
2490 '(("fr" ("\\(\\s-\\|[[(]\\)\"" .
"«~") ("\\(\\S-\\)\"" .
"~»") ("\\(\\s-\\|(\\)'" .
"'"))
2491 ("en" ("\\(\\s-\\|[[(]\\)\"" .
"``") ("\\(\\S-\\)\"" .
"''") ("\\(\\s-\\|(\\)'" .
"`")))
2492 "Alist for quotes to use when converting english double-quotes.
2494 The CAR of each item in this alist is the language code.
2495 The CDR of each item in this alist is a list of three CONS:
2496 - the first CONS defines the opening quote;
2497 - the second CONS defines the closing quote;
2498 - the last CONS defines single quotes.
2500 For each item in a CONS, the first string is a regexp
2501 for allowed characters before/after the quote, the second
2502 string defines the replacement string for this quote."
2503 :group
'org-export-e-odt
2505 (cons :tag
"Opening quote"
2506 (string :tag
"Regexp for char before")
2507 (string :tag
"Replacement quote "))
2508 (cons :tag
"Closing quote"
2509 (string :tag
"Regexp for char after ")
2510 (string :tag
"Replacement quote "))
2511 (cons :tag
"Single quote"
2512 (string :tag
"Regexp for char before")
2513 (string :tag
"Replacement quote "))))
2520 ;;; Internal Functions (HTML)
2522 ;; (defun org-e-odt-format-inline-image (path &optional caption label attr)
2523 ;; ;; FIXME: alt text missing here?
2524 ;; (let ((inline-image (format "<img src=\"%s\" alt=\"%s\"/>"
2525 ;; path (file-name-nondirectory path))))
2526 ;; (if (not label) inline-image
2527 ;; (org-e-odt-format-section inline-image "figure" label))))
2531 (defun org-e-odt-bibliography ()
2532 "Find bibliography, cut it out and return it."
2534 (let (beg end
(cnt 1) bib
)
2536 (goto-char (point-min))
2537 (when (re-search-forward
2538 "^[ \t]*<div \\(id\\|class\\)=\"bibliography\"" nil t
)
2539 (setq beg
(match-beginning 0))
2540 (while (re-search-forward "</?div\\>" nil t
)
2541 (setq cnt
(+ cnt
(if (string= (match-string 0) "<div") +1 -
1)))
2543 (and (looking-at ">") (forward-char 1))
2544 (setq bib
(buffer-substring beg
(point)))
2545 (delete-region beg
(point))
2546 (throw 'exit bib
))))
2551 (defun org-e-odt-format-table (lines olines
)
2552 (let ((org-e-odt-format-table-no-css nil
))
2553 (org-lparse-format-table lines olines
)))
2555 (defun org-e-odt-splice-attributes (tag attributes
)
2556 "Read attributes in string ATTRIBUTES, add and replace in HTML tag TAG."
2557 (if (not attributes
)
2559 (let (oldatt newatt
)
2560 (setq oldatt
(org-extract-attributes-from-string tag
)
2562 newatt
(cdr (org-extract-attributes-from-string attributes
)))
2564 (setq oldatt
(plist-put oldatt
(pop newatt
) (pop newatt
))))
2565 (if (string-match ">" tag
)
2567 (replace-match (concat (org-attributes-to-string oldatt
) ">")
2571 (defun org-export-splice-style (style extra
)
2572 "Splice EXTRA into STYLE, just before \"</style>\"."
2573 (if (and (stringp extra
)
2574 (string-match "\\S-" extra
)
2575 (string-match "</style>" style
))
2576 (concat (substring style
0 (match-beginning 0))
2578 (substring style
(match-beginning 0)))
2581 (defun org-e-odt-toc-entry-formatter
2582 (level snumber todo todo-type priority
2583 headline tags target extra-targets extra-class
)
2584 (org-e-odt-format-toc-entry snumber todo headline tags target
))
2586 (defun org-e-odt-make-string (n string
)
2587 (let (out) (dotimes (i n out
) (setq out
(concat string out
)))))
2589 (defun org-e-odt-toc-text (toc-entries)
2590 (let* ((prev-level (1- (nth 1 (car toc-entries
))))
2591 (start-level prev-level
))
2594 (let ((headline (nth 0 entry
))
2595 (level (nth 1 entry
)))
2596 (prog1 (org-e-odt-format-toc-item headline level prev-level
)
2597 (setq prev-level level
))))
2600 (defun* org-e-odt-format-toc-headline
2601 (todo todo-type priority text tags
2602 &key level section-number headline-label
&allow-other-keys
)
2605 (and org-export-with-section-numbers
2606 (concat section-number
". "))
2610 (org-e-odt-format-spaces 3)
2611 (org-e-odt-format-fontify tags
"tag")))))
2613 (setq text
(org-e-odt-format-fontify text
"todo")))
2615 (let ((org-e-odt-suppress-xref t
))
2616 (org-e-odt-format-link text
(concat "#" headline-label
))))
2618 (defun org-e-odt-toc (depth info
)
2619 (assert (wholenump depth
))
2620 (let* ((headlines (org-export-collect-headlines info depth
))
2622 (loop for headline in headlines collect
2623 (list (org-e-odt-format-headline--wrap
2624 headline info
'org-e-odt-format-toc-headline
)
2625 (org-export-get-relative-level headline info
)))))
2627 (let* ((lang-specific-heading "Table of Contents")) ; FIXME
2629 (org-e-odt-begin-toc lang-specific-heading depth
)
2630 (org-e-odt-toc-text toc-entries
)
2631 (org-e-odt-end-toc))))))
2633 (defun org-e-odt-begin-outline (level1 snumber title tags
2634 target extra-targets extra-class
)
2635 (let* ((class (format "outline-%d" level1
))
2636 (class (if extra-class
(concat class
" " extra-class
) class
))
2637 (id (format "outline-container-%s"
2638 (org-lparse-suffix-from-snumber snumber
)))
2639 (extra (concat (when id
(format " id=\"%s\"" id
))
2640 (when class
(format " class=\"%s\"" class
)))))
2641 (org-lparse-insert-tag "<div%s>" extra
)
2643 (org-lparse-format 'HEADING
2645 'HEADLINE title extra-targets tags snumber level1
)
2648 (defun org-e-odt-end-outline ()
2649 (org-lparse-insert-tag "</div>"))
2651 (defun org-e-odt-suffix-from-snumber (snumber)
2652 (let* ((snu (replace-regexp-in-string "\\." "-" snumber
))
2653 (href (cdr (assoc (concat "sec-" snu
)
2654 org-export-preferred-target-alist
))))
2655 (org-solidify-link-text (or href snu
))))
2657 (defun org-e-odt-format-outline (contents level1 snumber title
2658 tags target extra-targets extra-class
)
2661 ;; (defun org-e-odt-format-line (line)
2662 ;; (case org-lparse-dyn-current-environment
2663 ;; ((quote fixedwidth) (concat (org-e-odt-encode-plain-text line) "\n"))
2664 ;; (t (concat line "\n"))))
2666 (defun org-e-odt-fix-class-name (kwd) ; audit callers of this function
2667 "Turn todo keyword into a valid class name.
2668 Replaces invalid characters with \"_\"."
2670 (while (string-match "[^a-zA-Z0-9_]" kwd
)
2671 (setq kwd
(replace-match "_" t t kwd
))))
2674 (defun org-e-odt-format-internal-link (text href
&optional extra
)
2675 (org-e-odt-format-link text
(concat "#" href
) extra
))
2677 (defun org-e-odt-format-extra-targets (extra-targets)
2678 (if (not extra-targets
) ""
2679 (mapconcat (lambda (x)
2681 (setq x
(org-solidify-link-text
2682 (if (org-uuidgen-p x
) (concat "ID-" x
) x
)))
2683 (org-e-odt-format-anchor "" x
))) extra-targets
"")))
2685 (defun org-e-odt-format-org-tags (tags)
2687 (org-e-odt-format-fontify
2690 (org-e-odt-format-fontify
2691 x
(concat "" ;; org-e-odt-tag-class-prefix
2692 (org-e-odt-fix-class-name x
))))
2693 (org-split-string tags
":")
2694 (org-e-odt-format-spaces 1)) "tag")))
2696 (defun org-e-odt-format-section-number (&optional snumber level
)
2698 (and nil org-export-with-section-numbers
2699 ;; (not org-lparse-body-only)
2701 (org-e-odt-format-fontify snumber
(format "section-number-%d" level
))))
2703 ;; (defun org-e-odt-format-headline (title extra-targets tags
2704 ;; &optional snumber level)
2706 ;; (org-e-odt-format-extra-targets extra-targets)
2707 ;; (concat (org-e-odt-format-section-number snumber level) " ")
2709 ;; (and tags (concat (org-e-odt-format-spaces 3)
2710 ;; (org-e-odt-format-org-tags tags)))))
2712 ;; (defun org-e-odt-format-date (info)
2713 ;; (let ((date (plist-get info :date)))
2715 ;; ((and date (string-match "%" date))
2716 ;; (format-time-string date))
2718 ;; (t (format-time-string "%Y-%m-%d %T %Z")))))
2722 ;;; Internal Functions (Ngz)
2724 (defun org-e-odt--caption/label-string
(caption label info
)
2725 "Return caption and label HTML string for floats.
2727 CAPTION is a cons cell of secondary strings, the car being the
2728 standard caption and the cdr its short form. LABEL is a string
2729 representing the label. INFO is a plist holding contextual
2732 If there's no caption nor label, return the empty string.
2734 For non-floats, see `org-e-odt--wrap-label'."
2735 (setq label nil
) ;; FIXME
2737 (let ((label-str (if label
(format "\\label{%s}" label
) "")))
2739 ((and (not caption
) (not label
)) "")
2740 ((not caption
) (format "\\label{%s}\n" label
))
2741 ;; Option caption format with short name.
2743 (format "\\caption[%s]{%s%s}\n"
2744 (org-export-data (cdr caption
) info
)
2746 (org-export-data (car caption
) info
)))
2747 ;; Standard caption format.
2748 ;; (t (format "\\caption{%s%s}\n"
2750 ;; (org-export-data (car caption) info)))
2751 (t (org-export-data (car caption
) info
)))))
2753 (defun org-e-odt--find-verb-separator (s)
2754 "Return a character not used in string S.
2755 This is used to choose a separator for constructs like \\verb."
2756 (let ((ll "~,./?;':\"|!@#%^&-_=+abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ<>()[]{}"))
2757 (loop for c across ll
2758 when
(not (string-match (regexp-quote (char-to-string c
)) s
))
2759 return
(char-to-string c
))))
2761 (defun org-e-odt--quotation-marks (text info
)
2762 "Export quotation marks depending on language conventions.
2763 TEXT is a string containing quotation marks to be replaced. INFO
2764 is a plist used as a communication channel."
2767 (while (setq start
(string-match (car l
) text start
))
2768 (let ((new-quote (concat (match-string 1 text
) (cdr l
))))
2769 (setq text
(replace-match new-quote t t text
))))))
2770 (cdr (or (assoc (plist-get info
:language
) org-e-odt-quotes
)
2771 ;; Falls back on English.
2772 (assoc "en" org-e-odt-quotes
))))
2775 (defun org-e-odt--wrap-label (element output
)
2776 "Wrap label associated to ELEMENT around OUTPUT, if appropriate.
2777 This function shouldn't be used for floats. See
2778 `org-e-odt--caption/label-string'."
2779 ;; (let ((label (org-element-property :name element)))
2780 ;; (if (or (not output) (not label) (string= output "") (string= label ""))
2782 ;; (concat (format "\\label{%s}\n" label) output)))
2787 ;;; Transcode Helpers
2789 (defun* org-e-odt-format-headline
2790 (todo todo-type priority text tags
2791 &key level section-number headline-label
&allow-other-keys
)
2792 (concat (org-e-odt-todo todo
) (and todo
" ") text
2793 (and tags
(org-e-odt-format-spaces 3))
2794 (and tags
(org-e-odt-format-org-tags tags
))))
2798 (defun org-e-odt-htmlfontify-string (line)
2799 (let* ((hfy-html-quote-regex "\\([<\"&> ]\\)")
2800 (hfy-html-quote-map '(("\"" """)
2805 (" " "<text:tab/>")))
2806 (hfy-face-to-css 'org-e-odt-hfy-face-to-css
)
2807 (hfy-optimisations-1 (copy-seq hfy-optimisations
))
2808 (hfy-optimisations (add-to-list 'hfy-optimisations-1
2810 (hfy-begin-span-handler
2811 (lambda (style text-block text-id text-begins-block-p
)
2812 (insert (format "<text:span text:style-name=\"%s\">" style
))))
2813 (hfy-end-span-handler (lambda nil
(insert "</text:span>"))))
2814 (htmlfontify-string line
)))
2816 (defun org-e-odt-do-format-code
2817 (code &optional lang refs retain-labels num-start
)
2818 (let* ((lang (or (assoc-default lang org-src-lang-modes
) lang
))
2819 (lang-mode (and lang
(intern (format "%s-mode" lang
))))
2820 (code-lines (org-split-string code
"\n"))
2821 (code-length (length code-lines
))
2822 (use-htmlfontify-p (and (functionp lang-mode
)
2823 org-e-odt-fontify-srcblocks
2824 (require 'htmlfontify nil t
)
2825 (fboundp 'htmlfontify-string
)))
2826 (code (if (not use-htmlfontify-p
) code
2830 (font-lock-fontify-buffer)
2832 (fontifier (if use-htmlfontify-p
'org-e-odt-htmlfontify-string
2833 'org-e-odt-encode-plain-text
))
2834 (par-style (if use-htmlfontify-p
"OrgSrcBlock"
2835 "OrgFixedWidthBlock"))
2837 (assert (= code-length
(length (org-split-string code
"\n"))))
2839 (org-export-format-code
2841 (lambda (loc line-num ref
)
2843 (concat par-style
(and (= (incf i
) code-length
) "LastLine")))
2845 (setq loc
(concat loc
(and ref retain-labels
(format " (%s)" ref
))))
2846 (setq loc
(funcall fontifier loc
))
2848 (setq loc
(org-e-odt-format-target loc
(concat "coderef-" ref
))))
2849 (setq loc
(org-e-odt-format-stylized-paragraph par-style loc
))
2850 (if (not line-num
) loc
2851 (org-e-odt-format-tags
2852 '("<text:list-item>" .
"</text:list-item>") loc
)))
2855 ((not num-start
) code
)
2856 ((equal num-start
0)
2857 (org-e-odt-format-tags
2858 '("<text:list text:style-name=\"OrgSrcBlockNumberedLine\"%s>"
2859 .
"</text:list>") code
" text:continue-numbering=\"false\""))
2860 (t (org-e-odt-format-tags
2861 '("<text:list text:style-name=\"OrgSrcBlockNumberedLine\"%s>"
2862 .
"</text:list>") code
" text:continue-numbering=\"true\"")))))
2864 (defun org-e-odt-format-code (element info
)
2865 (let* ((lang (org-element-property :language element
))
2866 ;; Extract code and references.
2867 (code-info (org-export-unravel-code element
))
2868 (code (car code-info
))
2869 (refs (cdr code-info
))
2870 ;; Does the src block contain labels?
2871 (retain-labels (org-element-property :retain-labels element
))
2872 ;; Does it have line numbers?
2873 (num-start (case (org-element-property :number-lines element
)
2874 (continued (org-export-get-loc element info
))
2876 (org-e-odt-do-format-code code lang refs retain-labels num-start
)))
2882 (defun org-e-odt-template (contents info
)
2883 "Return complete document string after HTML conversion.
2884 CONTENTS is the transcoded contents string. RAW-DATA is the
2885 original parsed data. INFO is a plist holding export options."
2887 (org-e-odt-update-meta-file info
)
2889 (insert-file-contents
2890 (or org-e-odt-content-template-file
2891 (expand-file-name "OrgOdtContentTemplate.xml"
2892 org-e-odt-styles-dir
)))
2893 (goto-char (point-min))
2894 (re-search-forward "</office:text>" nil nil
)
2895 (goto-char (match-beginning 0))
2898 (insert (org-e-odt-format-preamble info
))
2899 ;; Table of Contents
2900 (let ((depth (plist-get info
:with-toc
)))
2901 (when (wholenump depth
) (insert (org-e-odt-toc depth info
))))
2903 ;; Copy styles.xml. Also dump htmlfontify styles, if there is any.
2904 (org-e-odt-update-styles-file info
)
2906 ;; Update styles.xml - take care of outline numbering
2907 (with-current-buffer
2908 (find-file-noselect (expand-file-name "styles.xml") t
)
2909 ;; Don't make automatic backup of styles.xml file. This setting
2910 ;; prevents the backed-up styles.xml file from being zipped in to
2911 ;; odt file. This is more of a hackish fix. Better alternative
2912 ;; would be to fix the zip command so that the output odt file
2913 ;; includes only the needed files and excludes any auto-generated
2914 ;; extra files like backups and auto-saves etc etc. Note that
2915 ;; currently the zip command zips up the entire temp directory so
2916 ;; that any auto-generated files created under the hood ends up in
2917 ;; the resulting odt file.
2918 (set (make-local-variable 'backup-inhibited
) t
)
2919 (org-e-odt-configure-outline-numbering))
2923 (buffer-substring-no-properties (point-min) (point-max))))
2927 ;;; Transcode Functions
2931 (defun org-e-odt-bold (bold contents info
)
2932 "Transcode BOLD from Org to HTML.
2933 CONTENTS is the text with bold markup. INFO is a plist holding
2934 contextual information."
2935 (org-e-odt-format-fontify contents
'bold
))
2940 (defun org-e-odt-center-block (center-block contents info
)
2941 "Transcode a CENTER-BLOCK element from Org to HTML.
2942 CONTENTS holds the contents of the center block. INFO is a plist
2943 holding contextual information."
2944 (org-e-odt--wrap-label center-block contents
))
2949 (defun org-e-odt-clock (clock contents info
)
2950 "Transcode a CLOCK element from Org to HTML.
2951 CONTENTS is nil. INFO is a plist used as a communication
2953 (org-e-odt-format-fontify
2954 (concat (org-e-odt-format-fontify org-clock-string
"timestamp-kwd")
2955 (org-e-odt-format-fontify
2956 (concat (org-translate-time (org-element-property :value clock
))
2957 (let ((time (org-element-property :time clock
)))
2958 (and time
(format " (%s)" time
))))
2960 "timestamp-wrapper"))
2965 (defun org-e-odt-code (code contents info
)
2966 "Transcode a CODE object from Org to HTML.
2967 CONTENTS is nil. INFO is a plist used as a communication
2969 (org-e-odt-format-fontify (org-element-property :value code
) 'code
))
2974 ;; Comments are ignored.
2979 ;; Comment Blocks are ignored.
2984 (defun org-e-odt-drawer (drawer contents info
)
2985 "Transcode a DRAWER element from Org to HTML.
2986 CONTENTS holds the contents of the block. INFO is a plist
2987 holding contextual information."
2988 (let* ((name (org-element-property :drawer-name drawer
))
2989 (output (if (functionp org-e-odt-format-drawer-function
)
2990 (funcall org-e-odt-format-drawer-function
2992 ;; If there's no user defined function: simply
2993 ;; display contents of the drawer.
2995 (org-e-odt--wrap-label drawer output
)))
3000 (defun org-e-odt-dynamic-block (dynamic-block contents info
)
3001 "Transcode a DYNAMIC-BLOCK element from Org to HTML.
3002 CONTENTS holds the contents of the block. INFO is a plist
3003 holding contextual information. See `org-export-data'."
3004 (org-e-odt--wrap-label dynamic-block contents
))
3009 (defun org-e-odt-entity (entity contents info
)
3010 "Transcode an ENTITY object from Org to HTML.
3011 CONTENTS are the definition itself. INFO is a plist holding
3012 contextual information."
3013 ;; (let ((ent (org-element-property :latex entity)))
3014 ;; (if (org-element-property :latex-math-p entity)
3015 ;; (format "$%s$" ent)
3017 (org-element-property :utf-8 entity
))
3022 (defun org-e-odt-example-block (example-block contents info
)
3023 "Transcode a EXAMPLE-BLOCK element from Org to HTML.
3024 CONTENTS is nil. INFO is a plist holding contextual information."
3025 (let* ((options (or (org-element-property :options example-block
) ""))
3026 (value (org-export-handle-code example-block info nil nil t
)))
3027 (org-e-odt--wrap-label
3028 example-block
(org-e-odt-format-source-code-or-example value nil
))))
3033 (defun org-e-odt-export-snippet (export-snippet contents info
)
3034 "Transcode a EXPORT-SNIPPET object from Org to HTML.
3035 CONTENTS is nil. INFO is a plist holding contextual information."
3036 (when (eq (org-export-snippet-backend export-snippet
) 'e-odt
)
3037 (org-element-property :value export-snippet
)))
3042 (defun org-e-odt-export-block (export-block contents info
)
3043 "Transcode a EXPORT-BLOCK element from Org to HTML.
3044 CONTENTS is nil. INFO is a plist holding contextual information."
3045 (when (string= (org-element-property :type export-block
) "latex")
3046 (org-remove-indentation (org-element-property :value export-block
))))
3051 (defun org-e-odt-fixed-width (fixed-width contents info
)
3052 "Transcode a FIXED-WIDTH element from Org to HTML.
3053 CONTENTS is nil. INFO is a plist holding contextual information."
3054 (let* ((value (org-element-normalize-string
3055 (replace-regexp-in-string
3057 (org-element-property :value fixed-width
)))))
3058 (org-e-odt--wrap-label
3059 fixed-width
(org-e-odt-format-source-code-or-example value nil
))))
3062 ;;;; Footnote Definition
3064 ;; Footnote Definitions are ignored.
3067 ;;;; Footnote Reference
3069 (defun org-e-odt-footnote-def (raw info
) ; FIXME
3070 (if (equal (org-element-type raw
) 'org-data
)
3071 (org-trim (org-export-data raw info
)) ; fix paragraph style
3072 (org-e-odt-format-stylized-paragraph
3073 'footnote
(org-trim (org-export-data raw info
)))))
3075 (defvar org-e-odt-footnote-separator
3076 (org-e-odt-format-fontify "," 'superscript
))
3078 (defun org-e-odt-footnote-reference (footnote-reference contents info
)
3079 "Transcode a FOOTNOTE-REFERENCE element from Org to HTML.
3080 CONTENTS is nil. INFO is a plist holding contextual information."
3082 ;; Insert separator between two footnotes in a row.
3083 (let ((prev (org-export-get-previous-element footnote-reference info
)))
3084 (when (eq (org-element-type prev
) 'footnote-reference
)
3085 org-e-odt-footnote-separator
))
3087 ((not (org-export-footnote-first-reference-p footnote-reference info
))
3088 (let* ((n (org-export-get-footnote-number footnote-reference info
)))
3089 (org-e-odt-format-footnote-reference n
"IGNORED" 100)))
3090 ;; Inline definitions are secondary strings.
3091 ((eq (org-element-property :type footnote-reference
) 'inline
)
3092 (let* ((raw (org-export-get-footnote-definition footnote-reference info
))
3093 (n (org-export-get-footnote-number footnote-reference info
))
3094 (def (org-e-odt-footnote-def raw info
)))
3095 (org-e-odt-format-footnote-reference n def
1)))
3096 ;; Non-inline footnotes definitions are full Org data.
3098 (let* ((raw (org-export-get-footnote-definition footnote-reference info
))
3099 (n (org-export-get-footnote-number footnote-reference info
))
3100 (def (org-e-odt-footnote-def raw info
)))
3101 (org-e-odt-format-footnote-reference n def
1))))))
3106 (defun org-e-odt-todo (todo)
3108 (org-e-odt-format-fontify
3110 "" ; org-e-odt-todo-kwd-class-prefix
3111 (org-e-odt-fix-class-name todo
))
3112 (list (if (member todo org-done-keywords
) "done" "todo")
3115 (defun org-e-odt-format-headline--wrap (headline info
3116 &optional format-function
3118 "Transcode an HEADLINE element from Org to ODT.
3119 CONTENTS holds the contents of the headline. INFO is a plist
3120 holding contextual information."
3121 (let* ((level (+ (org-export-get-relative-level headline info
)))
3122 (headline-number (org-export-get-headline-number headline info
))
3123 (section-number (and (org-export-numbered-headline-p headline info
)
3124 (mapconcat 'number-to-string
3125 headline-number
".")))
3126 (todo (and (plist-get info
:with-todo-keywords
)
3127 (let ((todo (org-element-property :todo-keyword headline
)))
3128 (and todo
(org-export-data todo info
)))))
3129 (todo-type (and todo
(org-element-property :todo-type headline
)))
3130 (priority (and (plist-get info
:with-priority
)
3131 (org-element-property :priority headline
)))
3132 (text (org-export-data (org-element-property :title headline
) info
))
3133 (tags (and (plist-get info
:with-tags
)
3134 (org-element-property :tags headline
)))
3135 (headline-label (concat "sec-" (mapconcat 'number-to-string
3136 headline-number
"-")))
3137 (format-function (cond
3138 ((functionp format-function
) format-function
)
3139 ((functionp org-e-odt-format-headline-function
)
3141 (lambda (todo todo-type priority text tags
3143 (funcall org-e-odt-format-headline-function
3144 todo todo-type priority text tags
))))
3145 (t 'org-e-odt-format-headline
))))
3146 (apply format-function
3147 todo todo-type priority text tags
3148 :headline-label headline-label
:level level
3149 :section-number section-number extra-keys
)))
3151 (defun org-e-odt-headline (headline contents info
)
3152 "Transcode an HEADLINE element from Org to HTML.
3153 CONTENTS holds the contents of the headline. INFO is a plist
3154 holding contextual information."
3155 (let* ((numberedp (org-export-numbered-headline-p headline info
))
3156 ;; Get level relative to current parsed data.
3157 (level (org-export-get-relative-level headline info
))
3158 (text (org-export-data (org-element-property :title headline
) info
))
3159 ;; Create the headline text.
3160 (full-text (org-e-odt-format-headline--wrap headline info
)))
3162 ;; Case 1: This is a footnote section: ignore it.
3163 ((org-element-property :footnote-section-p headline
) nil
)
3164 ;; Case 2. This is a deep sub-tree: export it as a list item.
3165 ;; Also export as items headlines for which no section
3166 ;; format has been found.
3167 ((org-export-low-level-p headline info
) ; FIXME (or (not section-fmt))
3168 ;; Build the real contents of the sub-tree.
3169 (let* ((type (if numberedp
'unordered
'unordered
)) ; FIXME
3170 (itemized-body (org-e-odt-format-list-item
3171 contents type nil nil full-text
)))
3173 (and (org-export-first-sibling-p headline info
)
3174 (org-e-odt-begin-plain-list type
))
3176 (and (org-export-last-sibling-p headline info
)
3177 (org-e-odt-end-plain-list type
)))))
3178 ;; Case 3. Standard headline. Export it as a section.
3180 (let* ((extra-ids (list (org-element-property :custom-id headline
)
3181 (org-element-property :id headline
)))
3182 (extra-ids nil
) ; FIXME
3183 (id (concat "sec-" (mapconcat 'number-to-string
3184 (org-export-get-headline-number
3185 headline info
) "-"))))
3187 (org-e-odt-format-tags
3188 '("<text:h text:style-name=\"Heading_20_%s\" text:outline-level=\"%s\">" .
3190 (concat (org-e-odt-format-extra-targets extra-ids
)
3191 (if (not id
) full-text
(org-e-odt-format-target full-text id
) ))
3196 ;;;; Horizontal Rule
3198 (defun org-e-odt-horizontal-rule (horizontal-rule contents info
)
3199 "Transcode an HORIZONTAL-RULE object from Org to HTML.
3200 CONTENTS is nil. INFO is a plist holding contextual information."
3201 (let ((attr (mapconcat #'identity
3202 (org-element-property :attr_odt horizontal-rule
)
3204 (org-e-odt--wrap-label horizontal-rule
3205 (org-e-odt-format-horizontal-line))))
3208 ;;;; Inline Babel Call
3210 ;; Inline Babel Calls are ignored.
3213 ;;;; Inline Src Block
3215 (defun org-e-odt-inline-src-block (inline-src-block contents info
)
3216 "Transcode an INLINE-SRC-BLOCK element from Org to HTML.
3217 CONTENTS holds the contents of the item. INFO is a plist holding
3218 contextual information."
3219 (let* ((org-lang (org-element-property :language inline-src-block
))
3220 (code (org-element-property :value inline-src-block
))
3221 (separator (org-e-odt--find-verb-separator code
)))
3227 (defun org-e-odt-format-section (text class
&optional id
)
3228 (let ((extra (concat (when id
(format " id=\"%s\"" id
)))))
3229 (concat (format "<div class=\"%s\"%s>\n" class extra
) text
"</div>\n")))
3231 (defun org-e-odt-inlinetask (inlinetask contents info
)
3232 "Transcode an INLINETASK element from Org to ODT.
3233 CONTENTS holds the contents of the block. INFO is a plist
3234 holding contextual information."
3236 ;; If `org-e-odt-format-inlinetask-function' is provided, call it
3237 ;; with appropriate arguments.
3238 ((functionp org-e-odt-format-inlinetask-function
)
3239 (let ((format-function
3241 (lambda (todo todo-type priority text tags
3242 &key contents
&allow-other-keys
)
3243 (funcall org-e-odt-format-inlinetask-function
3244 todo todo-type priority text tags contents
)))))
3245 (org-e-odt-format-headline--wrap
3246 inlinetask info format-function
:contents contents
)))
3247 ;; Otherwise, use a default template.
3248 (t (org-e-odt--wrap-label
3250 (org-e-odt-format-stylized-paragraph
3251 nil
(org-e-odt-format-textbox
3252 (concat (org-e-odt-format-stylized-paragraph
3253 "OrgInlineTaskHeading" (org-e-odt-format-headline--wrap
3256 nil nil
"OrgInlineTaskFrame" " style:rel-width=\"100%\""))))))
3260 (defun org-e-odt-italic (italic contents info
)
3261 "Transcode ITALIC from Org to HTML.
3262 CONTENTS is the text with italic markup. INFO is a plist holding
3263 contextual information."
3264 (org-e-odt-format-fontify contents
'italic
))
3269 (defun org-e-odt-format-list-item (contents type checkbox
3270 &optional term-counter-id
3274 (org-e-odt-format-fontify (case checkbox
3277 (trans "[-]")) 'code
)))
3279 (org-e-odt-begin-list-item type term-counter-id headline
)
3280 ;; FIXME checkbox (and checkbox " ")
3282 (org-e-odt-end-list-item type
)))
3284 (defun org-e-odt-item (item contents info
)
3285 "Transcode an ITEM element from Org to HTML.
3286 CONTENTS holds the contents of the item. INFO is a plist holding
3287 contextual information."
3288 ;; Grab `:level' from plain-list properties, which is always the
3289 ;; first element above current item.
3290 (let* ((plain-list (org-export-get-parent item info
))
3291 (type (org-element-property :type plain-list
))
3292 (level (org-element-property :level plain-list
))
3293 (counter (org-element-property :counter item
))
3294 (checkbox (org-element-property :checkbox item
))
3295 (tag (let ((tag (org-element-property :tag item
)))
3296 (and tag
(org-export-data tag info
)))))
3297 (org-e-odt-format-list-item
3298 contents type checkbox
(or tag counter
))))
3303 (defun org-e-odt-keyword (keyword contents info
)
3304 "Transcode a KEYWORD element from Org to HTML.
3305 CONTENTS is nil. INFO is a plist holding contextual information."
3306 (let ((key (org-element-property :key keyword
))
3307 (value (org-element-property :value keyword
)))
3309 ((string= key
"LATEX") value
)
3310 ((string= key
"INDEX") (format "\\index{%s}" value
))
3311 ((string= key
"TARGET") nil
; FIXME
3312 ;; (format "\\label{%s}" (org-export-solidify-link-text value))
3314 ((string= key
"toc")
3315 (let ((value (downcase value
)))
3317 ((string-match "\\<headlines\\>" value
)
3318 (let ((depth (or (and (string-match "[0-9]+" value
)
3319 (string-to-number (match-string 0 value
)))
3320 (plist-get info
:with-toc
))))
3321 (when (wholenump depth
) (org-e-odt-toc depth info
))))
3322 ((string= "tables" value
) "FIXME")
3323 ((string= "figures" value
) "FIXME")
3324 ((string= "listings" value
)
3326 ;; At the moment, src blocks with a caption are wrapped
3327 ;; into a figure environment.
3331 ;;;; Latex Environment
3333 (defun org-e-odt-format-latex (latex-frag processing-type
)
3334 (let* ((prefix (case processing-type
3336 (mathml "ltxmathml/")))
3338 (concat prefix
(file-name-sans-extension
3339 (file-name-nondirectory (buffer-file-name)))))
3340 (cache-dir (file-name-directory (buffer-file-name )))
3341 (display-msg (case processing-type
3342 (dvipng "Creating LaTeX Image...")
3343 (mathml "Creating MathML snippet..."))))
3346 (org-format-latex cache-relpath cache-dir nil display-msg
3347 nil nil processing-type
)
3350 (defun org-e-odt-latex-environment (latex-environment contents info
)
3351 "Transcode a LATEX-ENVIRONMENT element from Org to HTML.
3352 CONTENTS is nil. INFO is a plist holding contextual information."
3353 (org-e-odt--wrap-label
3356 (org-remove-indentation
3357 (org-element-property :value latex-environment
)))
3358 (processing-type (plist-get info
:LaTeX-fragments
))
3359 (caption (org-element-property :caption latex-environment
))
3360 (short-caption (and (cdr caption
)
3361 (org-export-data (cdr caption
) info
)))
3362 (caption (and (car caption
) (org-export-data (car caption
) info
)))
3363 (label (org-element-property :name latex-environment
))
3365 (label (org-element-property :name latex-environment
)))
3367 ((member processing-type
'(t mathjax
))
3368 (org-e-odt-format-formula latex-environment info
))
3369 ((equal processing-type
'dvipng
)
3370 (org-e-odt-format-stylized-paragraph
3371 nil
(org-e-odt-link--inline-image latex-environment info
)))
3378 ;; (when latex-frag ; FIXME
3379 ;; (setq href (org-propertize href :title "LaTeX Fragment"
3380 ;; :description latex-frag)))
3382 ;; provide descriptions
3384 (defun org-e-odt-latex-fragment (latex-fragment contents info
)
3385 "Transcode a LATEX-FRAGMENT object from Org to HTML.
3386 CONTENTS is nil. INFO is a plist holding contextual information."
3387 (let* ((latex-frag (org-element-property :value latex-fragment
))
3388 (processing-type (plist-get info
:LaTeX-fragments
)))
3390 ((member processing-type
'(t mathjax
))
3391 (org-e-odt-format-formula latex-fragment info
))
3392 ((equal processing-type
'dvipng
)
3393 (org-e-odt-link--inline-image latex-fragment info
))
3399 (defun org-e-odt-line-break (line-break contents info
)
3400 "Transcode a LINE-BREAK object from Org to HTML.
3401 CONTENTS is nil. INFO is a plist holding contextual information."
3402 "<text:line-break/>\n")
3407 (defun org-e-odt-link--inline-image (element info
)
3408 "Return HTML code for an inline image.
3409 LINK is the link pointing to the inline image. INFO is a plist
3410 used as a communication channel."
3412 ((eq (org-element-type element
) 'link
)
3413 (let* ((type (org-element-property :type element
))
3414 (raw-path (org-element-property :path element
)))
3415 (cond ((member type
'("http" "https"))
3416 (concat type
":" raw-path
))
3417 ((file-name-absolute-p raw-path
)
3418 (expand-file-name raw-path
))
3420 ((member (org-element-type element
)
3421 '(latex-fragment latex-environment
))
3422 (let* ((latex-frag (org-remove-indentation
3423 (org-element-property
3425 (formula-link (org-e-odt-format-latex
3426 latex-frag
'dvipng
)))
3428 (string-match "file:\\([^]]*\\)" formula-link
)
3429 (match-string 1 formula-link
))))
3430 (t (error "what is this?"))))
3431 (href (org-e-odt-format-tags
3432 "<draw:image xlink:href=\"%s\" xlink:type=\"simple\" xlink:show=\"embed\" xlink:actuate=\"onLoad\"/>" ""
3433 (org-e-odt-copy-image-file src
)))
3434 ;; extract attributes from #+ATTR_ODT line.
3435 (attr-from (case (org-element-type element
)
3436 (link (org-export-get-parent-paragraph element info
))
3438 ;; convert attributes to a plist.
3439 (attr-plist (org-e-odt-element-attributes attr-from info
))
3440 ;; handle `:anchor', `:style' and `:attributes' properties.
3442 (car (assoc-string (plist-get attr-plist
:anchor
)
3443 '(("as-char") ("paragraph") ("page")) t
)))
3445 (and user-frame-anchor
(plist-get attr-plist
:style
)))
3447 (and user-frame-anchor
(plist-get attr-plist
:attributes
)))
3449 (list user-frame-style user-frame-attrs user-frame-anchor
))
3450 ;; (embed-as (or embed-as user-frame-anchor "paragraph"))
3452 ;; handle `:width', `:height' and `:scale' properties.
3453 (size (org-e-odt-image-size-from-file
3454 src
(plist-get attr-plist
:width
)
3455 (plist-get attr-plist
:height
)
3456 (plist-get attr-plist
:scale
) nil
;; embed-as
3459 (width (car size
)) (height (cdr size
))
3461 (case (org-element-type element
)
3462 ((org-e-odt-standalone-image-p element info
) "paragraph")
3463 (latex-fragment "as-char")
3464 (latex-environment "paragraph")
3466 (captions (org-e-odt-format-label element info
'definition
))
3467 (caption (car captions
)) (short-caption (cdr captions
))
3468 (entity (concat (and caption
"Captioned") embed-as
"Image")))
3469 (org-e-odt-format-entity entity href width height
3470 captions user-frame-params
)))
3472 (defun org-e-odt-format-entity (entity href width height
&optional
3473 captions user-frame-params
)
3474 (let* ((caption (car captions
)) (short-caption (cdr captions
))
3475 (entity-style (assoc-string entity org-e-odt-entity-frame-styles t
))
3476 default-frame-params frame-params
)
3479 (setq default-frame-params
(nth 2 entity-style
))
3480 (setq frame-params
(org-e-odt-merge-frame-params
3481 default-frame-params user-frame-params
))
3482 (apply 'org-e-odt-format-frame href width height frame-params
))
3484 (setq default-frame-params
(nth 3 entity-style
))
3485 (setq frame-params
(org-e-odt-merge-frame-params
3486 default-frame-params user-frame-params
))
3487 (apply 'org-e-odt-format-textbox
3488 (org-e-odt-format-stylized-paragraph
3491 (apply 'org-e-odt-format-frame href width height
3492 (let ((entity-style-1 (copy-sequence
3493 (nth 2 entity-style
))))
3494 (setcar (cdr entity-style-1
)
3496 (cadr entity-style-1
)
3498 (format " draw:name=\"%s\" "
3502 width height frame-params
)))))
3504 (defvar org-e-odt-standalone-image-predicate
3505 (function (lambda (paragraph)
3506 (or (org-element-property :caption paragraph
)
3507 (org-element-property :name paragraph
)))))
3509 (defun org-e-odt-standalone-image-p (element info
&optional predicate
)
3510 "Test if ELEMENT is a standalone image for the purpose ODT export.
3511 INFO is a plist holding contextual information.
3513 Return non-nil, if ELEMENT is of type paragraph and it's sole
3514 content, save for whitespaces, is a link that qualifies as an
3517 Return non-nil, if ELEMENT is of type link and it's containing
3518 paragraph has no other content save for leading and trailing
3521 Return nil, otherwise.
3523 Bind `org-e-odt-standalone-image-predicate' to constrain
3524 paragraph further. For example, to check for only captioned
3525 standalone images, do the following.
3527 \(setq org-e-odt-standalone-image-predicate
3528 \(lambda \(paragraph\)
3529 \(org-element-property :caption paragraph\)\)\)
3531 (let ((paragraph (case (org-element-type element
)
3533 (link (and (org-export-inline-image-p
3534 element org-e-odt-inline-image-rules
)
3535 (org-export-get-parent element info
)))
3538 (assert (eq (org-element-type paragraph
) 'paragraph
))
3539 (when (or (not (and (boundp 'org-e-odt-standalone-image-predicate
)
3540 (functionp org-e-odt-standalone-image-predicate
)))
3541 (funcall org-e-odt-standalone-image-predicate paragraph
))
3542 (let ((contents (org-element-contents paragraph
)))
3543 (loop for x in contents
3544 with inline-image-count
= 0
3546 ((eq (org-element-type x
) 'plain-text
)
3547 (not (org-string-nw-p x
)))
3548 ((eq (org-element-type x
) 'link
)
3549 (when (org-export-inline-image-p
3550 x org-e-odt-inline-image-rules
)
3551 (= (incf inline-image-count
) 1)))
3554 (defun org-e-odt-link (link desc info
)
3555 "Transcode a LINK object from Org to HTML.
3557 DESC is the description part of the link, or the empty string.
3558 INFO is a plist holding contextual information. See
3560 (let* ((type (org-element-property :type link
))
3561 (raw-path (org-element-property :path link
))
3562 ;; Ensure DESC really exists, or set it to nil.
3563 (desc (and (not (string= desc
"")) desc
))
3564 (imagep (org-export-inline-image-p
3565 link org-e-odt-inline-image-rules
))
3567 ((member type
'("http" "https" "ftp" "mailto"))
3568 (concat type
":" raw-path
))
3569 ((string= type
"file")
3570 (when (string-match "\\(.+\\)::.+" raw-path
)
3571 (setq raw-path
(match-string 1 raw-path
)))
3572 (if (file-name-absolute-p raw-path
)
3573 (concat "file://" (expand-file-name raw-path
))
3574 ;; TODO: Not implemented yet. Concat also:
3575 ;; (org-export-directory :HTML info)
3576 (concat "file://" raw-path
)))
3581 ((and (not desc
) (org-export-inline-image-p
3582 link org-e-odt-inline-image-rules
))
3583 (org-e-odt-link--inline-image link info
))
3584 ;; Radioed target: Target's name is obtained from original raw
3585 ;; link. Path is parsed and transcoded in order to have a proper
3586 ;; display of the contents.
3587 ((string= type
"radio")
3588 (org-e-odt-format-internal-link
3590 (org-element-parse-secondary-string
3591 path
(org-element-restriction 'radio-target
))
3593 (org-export-solidify-link-text path
)))
3594 ;; Links pointing to an headline: Find destination and build
3595 ;; appropriate referencing command.
3596 ((member type
'("custom-id" "fuzzy" "id"))
3597 (let ((destination (if (string= type
"fuzzy")
3598 (org-export-resolve-fuzzy-link link info
)
3599 (org-export-resolve-id-link link info
))))
3600 (case (org-element-type destination
)
3601 ;; Fuzzy link points nowhere.
3603 (org-e-odt-format-fontify
3604 (or desc
(org-export-data
3605 (org-element-property :raw-link link
) info
))
3607 ;; Fuzzy link points to an invisible target.
3609 ;; LINK points to an headline. If headlines are numbered
3610 ;; and the link has no description, display headline's
3611 ;; number. Otherwise, display description or headline's
3614 (let* ((headline-no (org-export-get-headline-number destination info
))
3615 (label (format "sec-%s" (mapconcat 'number-to-string
3617 (section-no (mapconcat 'number-to-string headline-no
".")))
3621 ((plist-get info
:section-numbers
) section-no
)
3623 (org-element-property :title destination
) info
))))
3624 (org-e-odt-format-internal-link desc label
)))
3625 ;; Fuzzy link points to a target. Do as above.
3628 ;; (setq number (cond
3629 ;; ((org-e-odt-standalone-image-p destination info)
3630 ;; (org-export-get-ordinal
3631 ;; (assoc 'link (org-element-contents destination))
3632 ;; info 'link 'org-e-odt-standalone-image-p))
3633 ;; (t (org-export-get-ordinal destination info))))
3634 ;; (setq desc (when number
3635 ;; (if (atom number) (number-to-string number)
3636 ;; (mapconcat 'number-to-string number ".")))))
3638 (let ((label-reference
3639 (org-e-odt-format-label destination info
'reference
)))
3640 (assert label-reference
)
3641 label-reference
)))))
3642 ;; Coderef: replace link with the reference name or the
3643 ;; equivalent line number.
3644 ((string= type
"coderef")
3645 (let* ((fmt (org-export-get-coderef-format path desc
))
3646 (res (org-export-resolve-coderef path info
))
3647 (org-e-odt-suppress-xref nil
)
3648 (href (org-xml-format-href (concat "#coderef-" path
))))
3649 (format fmt
(org-e-odt-format-link res href
))))
3650 ;; Link type is handled by a special function.
3651 ((functionp (setq protocol
(nth 2 (assoc type org-link-protocols
))))
3652 (funcall protocol
(org-link-unescape path
) desc
'html
))
3653 ;; External link with a description part.
3654 ((and path desc
) (org-e-odt-format-link desc path
))
3655 ;; External link without a description part.
3656 (path (org-e-odt-format-link path path
))
3657 ;; No path, only description. Try to do something useful.
3658 (t (org-e-odt-format-fontify desc
'emphasis
)))))
3663 ;; Babel Calls are ignored.
3668 (defun org-e-odt-macro (macro contents info
)
3669 "Transcode a MACRO element from Org to HTML.
3670 CONTENTS is nil. INFO is a plist holding contextual information."
3671 ;; Use available tools.
3672 (org-export-expand-macro macro info
))
3677 (defun org-e-odt-paragraph (paragraph contents info
)
3678 "Transcode a PARAGRAPH element from Org to HTML.
3679 CONTENTS is the contents of the paragraph, as a string. INFO is
3680 the plist used as a communication channel."
3681 (let* ((style nil
) ; FIXME
3682 (class (cdr (assoc style
'((footnote .
"footnote")
3684 (extra (if class
(format " class=\"%s\"" class
) ""))
3685 (parent (org-export-get-parent paragraph info
))
3686 (parent-type (org-element-type parent
))
3687 (style (case parent-type
3688 (quote-block 'quote
)
3689 (center-block 'center
)
3690 (footnote-definition 'footnote
)
3692 (org-e-odt-format-stylized-paragraph style contents
)))
3697 (defun org-e-odt-plain-list (plain-list contents info
)
3698 "Transcode a PLAIN-LIST element from Org to HTML.
3699 CONTENTS is the contents of the list. INFO is a plist holding
3700 contextual information."
3701 (let* (arg1 ;; FIXME
3702 (type (org-element-property :type plain-list
))
3703 (attr (mapconcat #'identity
3704 (org-element-property :attr_odt plain-list
)
3706 (org-e-odt--wrap-label
3707 plain-list
(format "%s\n%s%s"
3708 (org-e-odt-begin-plain-list type
)
3709 contents
(org-e-odt-end-plain-list type
)))))
3713 (defun org-e-odt-convert-special-strings (string)
3714 "Convert special characters in STRING to ODT."
3715 (let ((all org-e-odt-special-string-regexps
)
3717 (while (setq a
(pop all
))
3718 (setq re
(car a
) rpl
(cdr a
) start
0)
3719 (while (string-match re string start
)
3720 (setq string
(replace-match rpl t nil string
))))
3723 ;; (defun org-e-odt-encode-plain-text (s)
3724 ;; "Convert plain text characters to HTML equivalent.
3725 ;; Possible conversions are set in `org-export-html-protect-char-alist'."
3726 ;; (let ((cl org-e-odt-protect-char-alist) c)
3727 ;; (while (setq c (pop cl))
3729 ;; (while (string-match (car c) s start)
3730 ;; (setq s (replace-match (cdr c) t t s)
3731 ;; start (1+ (match-beginning 0))))))
3734 (defun org-e-odt-plain-text (text info
)
3735 "Transcode a TEXT string from Org to HTML.
3736 TEXT is the string to transcode. INFO is a plist holding
3737 contextual information."
3738 (setq text
(org-e-odt-encode-plain-text text t
))
3739 ;; Protect %, #, &, $, ~, ^, _, { and }.
3740 ;; (while (string-match "\\([^\\]\\|^\\)\\([%$#&{}~^_]\\)" text)
3742 ;; (replace-match (format "\\%s" (match-string 2 text)) nil t text 2)))
3744 ;; (setq text (replace-regexp-in-string
3745 ;; "\\(?:[^\\]\\|^\\)\\(\\\\\\)\\(?:[^%$#&{}~^_\\]\\|$\\)"
3746 ;; "$\\backslash$" text nil t 1))
3747 ;; HTML into \HTML{} and TeX into \TeX{}.
3748 ;; (let ((case-fold-search nil)
3750 ;; (while (string-match "\\<\\(\\(?:La\\)?TeX\\)\\>" text start)
3751 ;; (setq text (replace-match
3752 ;; (format "\\%s{}" (match-string 1 text)) nil t text)
3753 ;; start (match-end 0))))
3754 ;; Handle quotation marks
3755 ;; (setq text (org-e-odt--quotation-marks text info))
3756 ;; Convert special strings.
3757 ;; (when (plist-get info :with-special-strings)
3758 ;; (while (string-match (regexp-quote "...") text)
3759 ;; (setq text (replace-match "\\ldots{}" nil t text))))
3760 (when (plist-get info
:with-special-strings
)
3761 (setq text
(org-e-odt-convert-special-strings text
)))
3762 ;; Handle break preservation if required.
3763 (when (plist-get info
:preserve-breaks
)
3764 (setq text
(replace-regexp-in-string "\\(\\\\\\\\\\)?[ \t]*\n" " \\\\\\\\\n"
3772 (defun org-e-odt-planning (planning contents info
)
3773 "Transcode a PLANNING element from Org to HTML.
3774 CONTENTS is nil. INFO is a plist used as a communication
3776 (org-e-odt-format-fontify
3778 (let ((closed (org-element-property :closed planning
)))
3780 (concat (org-e-odt-format-fontify org-closed-string
"timestamp-kwd")
3781 (org-e-odt-format-fontify (org-translate-time closed
)
3783 (let ((deadline (org-element-property :deadline planning
)))
3785 (concat (org-e-odt-format-fontify org-deadline-string
"timestamp-kwd")
3786 (org-e-odt-format-fontify (org-translate-time deadline
)
3788 (let ((scheduled (org-element-property :scheduled planning
)))
3790 (concat (org-e-odt-format-fontify org-scheduled-string
"timestamp-kwd")
3791 (org-e-odt-format-fontify (org-translate-time scheduled
)
3793 "timestamp-wrapper"))
3796 ;;;; Property Drawer
3798 (defun org-e-odt-property-drawer (property-drawer contents info
)
3799 "Transcode a PROPERTY-DRAWER element from Org to HTML.
3800 CONTENTS is nil. INFO is a plist holding contextual
3802 ;; The property drawer isn't exported but we want separating blank
3803 ;; lines nonetheless.
3809 (defun org-e-odt-quote-block (quote-block contents info
)
3810 "Transcode a QUOTE-BLOCK element from Org to HTML.
3811 CONTENTS holds the contents of the block. INFO is a plist
3812 holding contextual information."
3813 (org-e-odt--wrap-label quote-block contents
))
3818 (defun org-e-odt-quote-section (quote-section contents info
)
3819 "Transcode a QUOTE-SECTION element from Org to HTML.
3820 CONTENTS is nil. INFO is a plist holding contextual information."
3821 (let ((value (org-remove-indentation
3822 (org-element-property :value quote-section
))))
3823 (when value
(org-e-odt-format-source-code-or-example value nil
))))
3828 (defun org-e-odt-section (section contents info
) ; FIXME
3829 "Transcode a SECTION element from Org to HTML.
3830 CONTENTS holds the contents of the section. INFO is a plist
3831 holding contextual information."
3836 (defun org-e-odt-radio-target (radio-target text info
)
3837 "Transcode a RADIO-TARGET object from Org to HTML.
3838 TEXT is the text of the target. INFO is a plist holding
3839 contextual information."
3840 (org-e-odt-format-anchor
3841 text
(org-export-solidify-link-text
3842 (org-element-property :value radio-target
))))
3847 (defun org-e-odt-special-block (special-block contents info
)
3848 "Transcode a SPECIAL-BLOCK element from Org to HTML.
3849 CONTENTS holds the contents of the block. INFO is a plist
3850 holding contextual information."
3851 (let ((type (downcase (org-element-property :type special-block
))))
3852 (org-e-odt--wrap-label
3854 (format "\\begin{%s}\n%s\\end{%s}" type contents type
))))
3859 (defun org-e-odt-src-block (src-block contents info
)
3860 "Transcode a SRC-BLOCK element from Org to HTML.
3861 CONTENTS holds the contents of the item. INFO is a plist holding
3862 contextual information."
3863 (let* ((lang (org-element-property :language src-block
))
3864 (caption (org-element-property :caption src-block
))
3865 (short-caption (and (cdr caption
)
3866 (org-export-data (cdr caption
) info
)))
3867 (caption (and (car caption
) (org-export-data (car caption
) info
)))
3868 (label (org-element-property :name src-block
)))
3869 ;; FIXME: Handle caption
3870 ;; caption-str (when caption)
3871 ;; (main (org-export-data (car caption) info))
3872 ;; (secondary (org-export-data (cdr caption) info))
3873 ;; (caption-str (org-e-odt--caption/label-string caption label info))
3874 (let* ((captions (org-e-odt-format-label src-block info
'definition
))
3875 (caption (car captions
)) (short-caption (cdr captions
)))
3877 (and caption
(org-e-odt-format-stylized-paragraph 'listing caption
))
3878 (org-e-odt-format-code src-block info
)))))
3881 ;;;; Statistics Cookie
3883 (defun org-e-odt-statistics-cookie (statistics-cookie contents info
)
3884 "Transcode a STATISTICS-COOKIE object from Org to HTML.
3885 CONTENTS is nil. INFO is a plist holding contextual information."
3886 (let ((cookie-value (org-element-property :value statistics-cookie
)))
3887 (org-e-odt-format-fontify cookie-value
'code
)))
3892 (defun org-e-odt-strike-through (strike-through contents info
)
3893 "Transcode STRIKE-THROUGH from Org to HTML.
3894 CONTENTS is the text with strike-through markup. INFO is a plist
3895 holding contextual information."
3896 (org-e-odt-format-fontify contents
'strike
))
3901 (defun org-e-odt-subscript (subscript contents info
)
3902 "Transcode a SUBSCRIPT object from Org to HTML.
3903 CONTENTS is the contents of the object. INFO is a plist holding
3904 contextual information."
3905 ;; (format (if (= (length contents) 1) "$_%s$" "$_{\\mathrm{%s}}$") contents)
3906 (org-e-odt-format-fontify contents
'subscript
))
3911 (defun org-e-odt-superscript (superscript contents info
)
3912 "Transcode a SUPERSCRIPT object from Org to HTML.
3913 CONTENTS is the contents of the object. INFO is a plist holding
3914 contextual information."
3915 ;; (format (if (= (length contents) 1) "$^%s$" "$^{\\mathrm{%s}}$") contents)
3916 (org-e-odt-format-fontify contents
'superscript
))
3921 (defun org-e-odt-table-style-spec (element info
)
3922 (let* ((table (org-export-get-parent-table element info
))
3923 (table-attributes (org-e-odt-element-attributes table info
))
3924 (table-style (plist-get table-attributes
:style
)))
3925 (assoc table-style org-e-odt-table-styles
)))
3927 (defun org-e-odt-get-table-cell-styles (table-cell info
)
3928 "Retrieve styles applicable to a table cell.
3929 R and C are (zero-based) row and column numbers of the table
3930 cell. STYLE-SPEC is an entry in `org-e-odt-table-styles'
3931 applicable to the current table. It is `nil' if the table is not
3932 associated with any style attributes.
3934 Return a cons of (TABLE-CELL-STYLE-NAME . PARAGRAPH-STYLE-NAME).
3936 When STYLE-SPEC is nil, style the table cell the conventional way
3937 - choose cell borders based on row and column groupings and
3938 choose paragraph alignment based on `org-col-cookies' text
3940 `org-e-odt-get-paragraph-style-cookie-for-table-cell'.
3942 When STYLE-SPEC is non-nil, ignore the above cookie and return
3943 styles congruent with the ODF-1.2 specification."
3944 (let* ((table-cell-address (org-export-table-cell-address table-cell info
))
3945 (r (car table-cell-address
)) (c (cdr table-cell-address
))
3946 (style-spec (org-e-odt-table-style-spec table-cell info
))
3947 (table-dimensions (org-export-table-dimensions
3948 (org-export-get-parent-table table-cell info
)
3951 ;; LibreOffice - particularly the Writer - honors neither table
3952 ;; templates nor custom table-cell styles. Inorder to retain
3953 ;; inter-operability with LibreOffice, only automatic styles are
3954 ;; used for styling of table-cells. The current implementation is
3955 ;; congruent with ODF-1.2 specification and hence is
3956 ;; future-compatible.
3958 ;; Additional Note: LibreOffice's AutoFormat facility for tables -
3959 ;; which recognizes as many as 16 different cell types - is much
3960 ;; richer. Unfortunately it is NOT amenable to easy configuration
3962 (let* ((template-name (nth 1 style-spec
))
3963 (cell-style-selectors (nth 2 style-spec
))
3966 ((and (cdr (assoc 'use-first-column-styles cell-style-selectors
))
3967 (= c
0)) "FirstColumn")
3968 ((and (cdr (assoc 'use-last-column-styles cell-style-selectors
))
3969 (= (1+ c
) (cdr table-dimensions
)))
3971 ((and (cdr (assoc 'use-first-row-styles cell-style-selectors
))
3972 (= r
0)) "FirstRow")
3973 ((and (cdr (assoc 'use-last-row-styles cell-style-selectors
))
3974 (= (1+ r
) (car table-dimensions
)))
3976 ((and (cdr (assoc 'use-banding-rows-styles cell-style-selectors
))
3977 (= (% r
2) 1)) "EvenRow")
3978 ((and (cdr (assoc 'use-banding-rows-styles cell-style-selectors
))
3979 (= (% r
2) 0)) "OddRow")
3980 ((and (cdr (assoc 'use-banding-columns-styles cell-style-selectors
))
3981 (= (% c
2) 1)) "EvenColumn")
3982 ((and (cdr (assoc 'use-banding-columns-styles cell-style-selectors
))
3983 (= (% c
2) 0)) "OddColumn")
3985 (concat template-name cell-type
)))))
3987 (defun org-e-odt-table-cell (table-cell contents info
)
3988 "Transcode a TABLE-CELL element from Org to ODT.
3989 CONTENTS is nil. INFO is a plist used as a communication
3991 (let* ((table-cell-address (org-export-table-cell-address table-cell info
))
3992 (r (car table-cell-address
))
3993 (c (cdr table-cell-address
))
3994 (horiz-span (or (org-export-table-cell-width table-cell info
) 0))
3995 (table-row (org-export-get-parent table-cell info
))
3996 (custom-style-prefix (org-e-odt-get-table-cell-styles
4000 (and custom-style-prefix
4001 (format "%sTableParagraph" custom-style-prefix
))
4004 ((and (= 1 (org-export-table-row-group table-row info
))
4005 (org-export-table-has-header-p
4006 (org-export-get-parent-table table-row info
) info
))
4008 ((and (zerop c
) t
;; (org-lparse-get 'TABLE-FIRST-COLUMN-AS-LABELS)
4011 (t "OrgTableContents"))
4012 (capitalize (symbol-name (org-export-table-cell-alignment
4013 table-cell info
))))))
4016 (and custom-style-prefix
(format "%sTableCell"
4017 custom-style-prefix
))
4020 (when (or (org-export-table-row-starts-rowgroup-p table-row info
)
4022 (when (org-export-table-row-ends-rowgroup-p table-row info
) "B")
4023 (when (and (org-export-table-cell-starts-colgroup-p table-cell info
)
4024 (not (zerop c
)) ) "L"))))
4027 (format " table:style-name=\"%s\"" cell-style-name
)
4028 (and (> horiz-span
0)
4029 (format " table:number-columns-spanned=\"%d\""
4030 (1+ horiz-span
))))))
4031 (unless contents
(setq contents
""))
4033 (org-e-odt-format-tags
4034 '("<table:table-cell%s>" .
"</table:table-cell>")
4035 (org-e-odt-format-stylized-paragraph paragraph-style contents
)
4038 (dotimes (i horiz-span s
)
4039 (setq s
(concat s
"\n<table:covered-table-cell/>"))))
4045 (defun org-e-odt-table-row (table-row contents info
)
4046 "Transcode a TABLE-ROW element from Org to ODT.
4047 CONTENTS is the contents of the row. INFO is a plist used as a
4048 communication channel."
4049 ;; Rules are ignored since table separators are deduced from
4050 ;; borders of the current row.
4051 (when (eq (org-element-property :type table-row
) 'standard
)
4052 (let* ((rowgroup-tags
4053 (if (and (= 1 (org-export-table-row-group table-row info
))
4054 (org-export-table-has-header-p
4055 (org-export-get-parent-table table-row info
) info
))
4056 ;; If the row belongs to the first rowgroup and the
4057 ;; table has more than one row groups, then this row
4058 ;; belongs to the header row group.
4059 '("\n<table:table-header-rows>" .
"\n</table:table-header-rows>")
4060 ;; Otherwise, it belongs to non-header row group.
4061 '("\n<table:table-rows>" .
"\n</table:table-rows>"))))
4063 ;; Does this row begin a rowgroup?
4064 (when (org-export-table-row-starts-rowgroup-p table-row info
)
4065 (car rowgroup-tags
))
4067 (org-e-odt-format-tags
4068 '("<table:table-row>" .
"</table:table-row>") contents
)
4069 ;; Does this row end a rowgroup?
4070 (when (org-export-table-row-ends-rowgroup-p table-row info
)
4071 (cdr rowgroup-tags
))))))
4076 (defun org-e-odt-table-first-row-data-cells (table info
)
4081 (unless (eq (org-element-property :type row
) 'rule
) row
))
4083 (special-column-p (org-export-table-has-special-column-p table
)))
4084 (if (not special-column-p
) (org-element-contents table-row
)
4085 (cdr (org-element-contents table-row
)))))
4087 (defun org-e-odt-table (table contents info
)
4088 "Transcode a TABLE element from Org to HTML.
4089 CONTENTS is nil. INFO is a plist holding contextual information."
4090 (case (org-element-property :type table
)
4093 (let* ((captions (org-e-odt-format-label table info
'definition
))
4094 (caption (car captions
)) (short-caption (cdr captions
))
4095 (attributes (org-e-odt-element-attributes table info
))
4096 (custom-table-style (nth 1 (org-e-odt-table-style-spec table info
)))
4099 (lambda (table info
)
4100 (let* ((table-style (or custom-table-style
"OrgTable"))
4101 (column-style (format "%sColumn" table-style
)))
4103 (lambda (table-cell)
4104 (let ((width (1+ (or (org-export-table-cell-width
4105 table-cell info
) 0))))
4106 (org-e-odt-make-string
4108 (org-e-odt-format-tags
4109 "<table:table-column table:style-name=\"%s\"/>"
4111 (org-e-odt-table-first-row-data-cells table info
) "\n"))))))
4114 (when caption
(org-e-odt-format-stylized-paragraph 'table caption
))
4116 (let* ((automatic-name
4117 (org-e-odt-add-automatic-style "Table" attributes
)))
4119 "\n<table:table table:name=\"%s\" table:style-name=\"%s\">\n"
4120 (or short-caption
(car automatic-name
))
4121 (or custom-table-style
(cdr automatic-name
) "OrgTable")))
4122 ;; column specification.
4123 (funcall table-column-specs table info
)
4127 "</table:table>")))))
4132 (defun org-e-odt-target (target contents info
)
4133 "Transcode a TARGET object from Org to HTML.
4134 CONTENTS is nil. INFO is a plist holding contextual
4136 (org-e-odt-format-anchor
4137 "" (org-export-solidify-link-text (org-element-property :value target
))))
4142 (defun org-e-odt-timestamp (timestamp contents info
)
4143 "Transcode a TIMESTAMP object from Org to HTML.
4144 CONTENTS is nil. INFO is a plist used as a communication
4146 (org-e-odt-format-fontify
4147 (org-e-odt-format-fontify
4148 (org-translate-time (org-element-property :value timestamp
))
4150 "timestamp-wrapper"))
4155 (defun org-e-odt-underline (underline contents info
)
4156 "Transcode UNDERLINE from Org to HTML.
4157 CONTENTS is the text with underline markup. INFO is a plist
4158 holding contextual information."
4159 (org-e-odt-format-fontify contents
'underline
))
4164 (defun org-e-odt-verbatim (verbatim contents info
)
4165 "Transcode a VERBATIM object from Org to HTML.
4166 CONTENTS is nil. INFO is a plist used as a communication
4168 (org-e-odt-format-fontify (org-element-property :value verbatim
) 'verbatim
))
4173 (defun org-e-odt-verse-block (verse-block contents info
)
4174 "Transcode a VERSE-BLOCK element from Org to HTML.
4175 CONTENTS is verse block contents. INFO is a plist holding
4176 contextual information."
4177 ;; Replace each newline character with line break. Also replace
4178 ;; each blank line with a line break.
4179 (setq contents
(replace-regexp-in-string
4180 "^ *\\\\\\\\$" "<br/>\n"
4181 (replace-regexp-in-string
4182 "\\(\\\\\\\\\\)?[ \t]*\n" " <br/>\n" contents
)))
4184 ;; Replace each white space at beginning of a line with a
4185 ;; non-breaking space.
4186 (while (string-match "^[ \t]+" contents
)
4187 (let ((new-str (org-e-odt-format-spaces
4188 (length (match-string 0 contents
)))))
4189 (setq contents
(replace-match new-str nil t contents
))))
4191 (org-e-odt--wrap-label
4192 verse-block
(format "<p class=\"verse\">\n%s</p>" contents
)))
4197 ;;; Filter Functions
4199 ;;;; Filter Settings
4202 ;;; Interactive functions
4204 (defun org-e-odt-export-to-odt
4205 (&optional subtreep visible-only body-only ext-plist pub-dir
)
4206 "Export current buffer to a HTML file.
4208 If narrowing is active in the current buffer, only export its
4211 If a region is active, export that region.
4213 When optional argument SUBTREEP is non-nil, export the sub-tree
4214 at point, extracting information from the headline properties
4217 When optional argument VISIBLE-ONLY is non-nil, don't export
4218 contents of hidden elements.
4220 When optional argument BODY-ONLY is non-nil, only write code
4221 between \"\\begin{document}\" and \"\\end{document}\".
4223 EXT-PLIST, when provided, is a property list with external
4224 parameters overriding Org default settings, but still inferior to
4225 file-local settings.
4227 When optional argument PUB-DIR is set, use it as the publishing
4230 Return output file's name."
4232 (setq debug-on-error t
)
4234 ;; (let* ((outfile (org-export-output-file-name ".html" subtreep pub-dir))
4235 ;; (outfile "content.xml"))
4236 ;; (org-export-to-file
4237 ;; 'e-odt outfile subtreep visible-only body-only ext-plist))
4239 (let* ((outbuf (org-e-odt-init-outfile))
4240 (target (org-export-output-file-name ".odt" subtreep pub-dir
))
4241 (outdir (file-name-directory (buffer-file-name outbuf
)))
4242 (default-directory outdir
))
4244 ;; FIXME: for copying embedded images
4245 (setq org-current-export-file
4246 (file-name-directory
4247 (org-export-output-file-name ".odt" subtreep nil
)))
4249 (org-export-to-buffer
4251 (memq 'subtree optns
) (memq 'visible optns
) (memq 'body optns
))
4253 (setq org-lparse-opt-plist nil
) ; FIXME
4254 (org-e-odt-save-as-outfile target
;; info
4259 (if (not org-e-odt-preferred-output-format
) target
4260 (or (org-e-odt-convert target org-e-odt-preferred-output-format
)
4267 (defun org-e-odt-reachable-p (in-fmt out-fmt
)
4268 "Return non-nil if IN-FMT can be converted to OUT-FMT."
4270 (let ((reachable-formats (org-e-odt-do-reachable-formats in-fmt
)))
4271 (dolist (e reachable-formats
)
4272 (let ((out-fmt-spec (assoc out-fmt
(cdr e
))))
4274 (throw 'done
(cons (car e
) out-fmt-spec
))))))))
4276 (defun org-e-odt-do-convert (in-file out-fmt
&optional prefix-arg
)
4277 "Workhorse routine for `org-e-odt-convert'."
4278 (require 'browse-url
)
4279 (let* ((in-file (expand-file-name (or in-file buffer-file-name
)))
4280 (dummy (or (file-readable-p in-file
)
4281 (error "Cannot read %s" in-file
)))
4282 (in-fmt (file-name-extension in-file
))
4283 (out-fmt (or out-fmt
(error "Output format unspecified")))
4284 (how (or (org-e-odt-reachable-p in-fmt out-fmt
)
4285 (error "Cannot convert from %s format to %s format?"
4287 (convert-process (car how
))
4288 (out-file (concat (file-name-sans-extension in-file
) "."
4289 (nth 1 (or (cdr how
) out-fmt
))))
4290 (extra-options (or (nth 2 (cdr how
)) ""))
4291 (out-dir (file-name-directory in-file
))
4292 (cmd (format-spec convert-process
4293 `((?i .
,(shell-quote-argument in-file
))
4294 (?I .
,(browse-url-file-url in-file
))
4297 (?O .
,(browse-url-file-url out-file
))
4298 (?d .
, (shell-quote-argument out-dir
))
4299 (?D .
,(browse-url-file-url out-dir
))
4300 (?x .
,extra-options
)))))
4301 (when (file-exists-p out-file
)
4302 (delete-file out-file
))
4304 (message "Executing %s" cmd
)
4305 (let ((cmd-output (shell-command-to-string cmd
)))
4306 (message "%s" cmd-output
))
4309 ((file-exists-p out-file
)
4310 (message "Exported to %s" out-file
)
4312 (message "Opening %s..." out-file
)
4313 (org-open-file out-file
))
4316 (message "Export to %s failed" out-file
)
4319 (defun org-e-odt-do-reachable-formats (in-fmt)
4320 "Return verbose info about formats to which IN-FMT can be converted.
4321 Return a list where each element is of the
4322 form (CONVERTER-PROCESS . OUTPUT-FMT-ALIST). See
4323 `org-e-odt-convert-processes' for CONVERTER-PROCESS and see
4324 `org-e-odt-convert-capabilities' for OUTPUT-FMT-ALIST."
4326 (and org-e-odt-convert-process
4327 (cadr (assoc-string org-e-odt-convert-process
4328 org-e-odt-convert-processes t
))))
4330 (and org-e-odt-convert-process
4331 (cadr (assoc-string org-e-odt-convert-process
4332 org-e-odt-convert-processes t
))
4333 org-e-odt-convert-capabilities
))
4336 (dolist (c capabilities
)
4337 (when (member in-fmt
(nth 1 c
))
4338 (push (cons converter
(nth 2 c
)) reachable-formats
))))
4341 (defun org-e-odt-reachable-formats (in-fmt)
4342 "Return list of formats to which IN-FMT can be converted.
4343 The list of the form (OUTPUT-FMT-1 OUTPUT-FMT-2 ...)."
4345 (mapc (lambda (e) (add-to-list 'l e
))
4346 (apply 'append
(mapcar
4347 (lambda (e) (mapcar 'car
(cdr e
)))
4348 (org-e-odt-do-reachable-formats in-fmt
))))
4351 (defun org-e-odt-convert-read-params ()
4352 "Return IN-FILE and OUT-FMT params for `org-e-odt-do-convert'.
4353 This is a helper routine for interactive use."
4354 (let* ((input (if (featurep 'ido
) 'ido-completing-read
'completing-read
))
4355 (in-file (read-file-name "File to be converted: "
4356 nil buffer-file-name t
))
4357 (in-fmt (file-name-extension in-file
))
4358 (out-fmt-choices (org-e-odt-reachable-formats in-fmt
))
4360 (or (and out-fmt-choices
4361 (funcall input
"Output format: "
4362 out-fmt-choices nil nil nil
))
4364 "No known converter or no known output formats for %s files"
4366 (list in-file out-fmt
)))
4369 (defun org-e-odt-convert (&optional in-file out-fmt prefix-arg
)
4370 "Convert IN-FILE to format OUT-FMT using a command line converter.
4371 IN-FILE is the file to be converted. If unspecified, it defaults
4372 to variable `buffer-file-name'. OUT-FMT is the desired output
4373 format. Use `org-e-odt-convert-process' as the converter.
4374 If PREFIX-ARG is non-nil then the newly converted file is opened
4375 using `org-open-file'."
4377 (append (org-e-odt-convert-read-params) current-prefix-arg
))
4378 (org-e-odt-do-convert in-file out-fmt prefix-arg
))
4380 ;;; FIXMES, TODOS, FOR REVIEW etc
4382 ;; (defun org-e-odt-discontinue-list ()
4383 ;; (let ((stashed-stack org-lparse-list-stack))
4384 ;; (loop for list-type in stashed-stack
4385 ;; do (org-lparse-end-list-item-1 list-type)
4386 ;; (org-lparse-end-list list-type))
4387 ;; (setq org-e-odt-list-stack-stashed stashed-stack)))
4389 ;; (defun org-e-odt-continue-list ()
4390 ;; (setq org-e-odt-list-stack-stashed (nreverse org-e-odt-list-stack-stashed))
4391 ;; (loop for list-type in org-e-odt-list-stack-stashed
4392 ;; do (org-lparse-begin-list list-type)
4393 ;; (org-lparse-begin-list-item list-type)))
4395 ;; FIXME: Begin indented table
4396 ;; (setq org-e-odt-table-indentedp (not (null org-lparse-list-stack)))
4397 ;; (setq org-e-odt-table-indentedp nil) ; FIXME
4398 ;; (when org-e-odt-table-indentedp
4399 ;; ;; Within the Org file, the table is appearing within a list item.
4400 ;; ;; OpenDocument doesn't allow table to appear within list items.
4401 ;; ;; Temporarily terminate the list, emit the table and then
4402 ;; ;; re-continue the list.
4403 ;; (org-e-odt-discontinue-list)
4404 ;; ;; Put the Table in an indented section.
4405 ;; (let ((level (length org-e-odt-list-stack-stashed)))
4406 ;; (org-e-odt-begin-section (format "OrgIndentedSection-Level-%d" level))))
4408 ;; FIXME: End indented table
4409 ;; (when org-e-odt-table-indentedp
4410 ;; (org-e-odt-end-section)
4411 ;; (org-e-odt-continue-list))
4414 ;;;; org-format-table-html
4415 ;;;; org-format-org-table-html
4416 ;;;; org-format-table-table-html
4417 ;;;; org-table-number-fraction
4418 ;;;; org-table-number-regexp
4419 ;;;; org-e-odt-table-caption-above
4422 ;;;; "<span style=\"visibility:hidden;\">%s</span>"
4423 ;;;; Remove display properties
4425 ;;;; org-e-odt-with-timestamp
4426 ;;;; org-e-odt-html-helper-timestamp
4428 ;;;; org-export-as-html-and-open
4429 ;;;; org-export-as-html-batch
4430 ;;;; org-export-as-html-to-buffer
4431 ;;;; org-replace-region-by-html
4432 ;;;; org-export-region-as-html
4433 ;;;; org-export-as-html
4435 ;;;; (org-export-directory :html opt-plist)
4436 ;;;; (plist-get opt-plist :html-extension)
4437 ;;;; org-e-odt-toplevel-hlevel
4438 ;;;; org-e-odt-inline-image-extensions
4439 ;;;; org-e-odt-protect-char-alist
4440 ;;;; org-e-odt-table-use-header-tags-for-first-column
4441 ;;;; org-e-odt-todo-kwd-class-prefix
4442 ;;;; org-e-odt-tag-class-prefix
4443 ;;;; org-e-odt-footnote-separator
4446 ;;; Library Initializations
4450 ;; Let Org open all OpenDocument files using system-registered app
4451 (add-to-list 'org-file-apps
4452 (cons (concat "\\." (car desc
) "\\'") 'system
))
4453 ;; Let Emacs open all OpenDocument files in archive mode
4454 (add-to-list 'auto-mode-alist
4455 (cons (concat "\\." (car desc
) "\\'") 'archive-mode
)))
4456 org-e-odt-file-extensions
)
4458 (defvar org-e-odt-display-outline-level
2)
4459 (defun org-e-odt-enumerate-element (element info
&optional predicate n
)
4460 (let* ((numbered-parent-headline-at-<=-n
4462 (lambda (element n info
)
4463 (loop for x in
(org-export-get-genealogy element info
)
4464 thereis
(and (eq (org-element-type x
) 'headline
)
4465 (<= (org-export-get-relative-level x info
) n
)
4466 (org-export-numbered-headline-p x info
)
4470 (lambda (element scope info
&optional predicate
)
4473 (or scope
(plist-get info
:parse-tree
))
4474 (org-element-type element
)
4476 (and (or (not predicate
) (funcall predicate el info
))
4480 info
'first-match
)))))
4481 (scope (funcall numbered-parent-headline-at-
<=-n
4482 element
(or n org-e-odt-display-outline-level
) info
))
4483 (ordinal (funcall enumerate element scope info predicate
))
4488 (mapconcat 'number-to-string
4489 (org-export-get-headline-number scope info
) "."))
4493 (number-to-string ordinal
))))
4494 ;; (message "%s:\t%s" (org-element-property :name element) tag)
4497 (provide 'org-e-odt
)
4499 ;;; org-e-odt.el ends here