1 ;;; org-odt.el --- OpenDocumentText export for Org-mode
3 ;; Copyright (C) 2010-2011
4 ;; Free Software Foundation, Inc.
6 ;; Author: Jambunathan K <kjambunathan at gmail dot com>
7 ;; Keywords: outlines, hypermedia, calendar, wp
8 ;; Homepage: http://orgmode.org
11 ;; This file is part of GNU Emacs.
13 ;; GNU Emacs is free software: you can redistribute it and/or modify
14 ;; it under the terms of the GNU General Public License as published by
15 ;; the Free Software Foundation, either version 3 of the License, or
16 ;; (at your option) any later version.
18 ;; GNU Emacs is distributed in the hope that it will be useful,
19 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 ;; GNU General Public License for more details.
23 ;; You should have received a copy of the GNU General Public License
24 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
25 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
32 (eval-when-compile (require 'cl
))
37 (defun org-odt-end-export ()
38 ;; remove empty paragraphs
39 (goto-char (point-min))
40 (while (re-search-forward
41 "<text:p\\( text:style-name=\"Text_20_body\"\\)?>[ \r\n\t]*</text:p>"
44 (goto-char (point-min))
46 ;; Convert whitespace place holders
47 (goto-char (point-min))
49 (while (setq beg
(next-single-property-change (point) 'org-whitespace
))
50 (setq n
(get-text-property beg
'org-whitespace
)
51 end
(next-single-property-change beg
'org-whitespace
))
53 (delete-region beg end
)
54 (insert (format "<span style=\"visibility:hidden;\">%s</span>"
55 (make-string n ?x
)))))
57 ;; Remove empty lines at the beginning of the file.
58 (goto-char (point-min))
59 (when (looking-at "\\s-+\n") (replace-match ""))
61 ;; Remove display properties
62 (remove-text-properties (point-min) (point-max) '(display t
)))
64 ;; Refer comments in org-newhtml.el
65 (defvar org-basehtml-special-paragraph-styles
)
67 (defvar org-odt-suppress-xref nil
)
69 ;;;_ hacks (to be documented)
71 (defconst org-export-odt-special-string-regexps
72 '(("\\\\-" .
"­\\1")
73 ("---\\([^-]\\)" .
"—\\1")
74 ("--\\([^-]\\)" .
"–\\1")
75 ("\\.\\.\\." .
"…"))
76 "Regular expressions for special string conversion.")
81 (defcustom org-export-odt-automatic-styles-file nil
82 "Default style file for use with ODT exporter."
83 :group
'org-export-odt
86 ;; TODO: Make configuration user-friendly.
87 (defcustom org-export-odt-styles-file nil
88 "Default style file for use with ODT exporter.
89 Valid values are path to an styles.xml file or a path to a valid
90 *.odt or a *.ott file or a list of the form (FILE (MEMBER1
91 MEMBER2 ...)). In the last case, the specified FILE is unzipped
92 and MEMBER1, MEMBER2 etc are copied in to the generated odt
93 file. The last form is particularly useful if the styles.xml has
94 reference to additional files like header and footer images.
96 :group
'org-export-odt
)
97 (defconst org-export-odt-tmpdir-prefix
"odt-")
98 (defconst org-export-odt-bookmark-prefix
".OrgXref.")
99 (defcustom org-export-odt-use-bookmarks-for-internal-links t
100 "Export Internal links as bookmarks?."
101 :group
'org-export-odt
104 (defcustom org-export-odt-embed-images t
105 "Should the images be copied in to the odt file or just linked?"
106 :group
'org-export-odt
109 (defcustom org-odt-export-inline-images
'maybe
110 "Non-nil means inline images into exported HTML pages.
111 This is done using an <img> tag. When nil, an anchor with href is used to
112 link to the image. If this option is `maybe', then images in links with
113 an empty description will be inlined, while images with a description will
115 :group
'org-odt-export
116 :type
'(choice (const :tag
"Never" nil
)
117 (const :tag
"Always" t
)
118 (const :tag
"When there is no description" maybe
)))
121 (defcustom org-odt-export-inline-image-extensions
122 '("png" "jpeg" "jpg" "gif")
123 "Extensions of image files that can be inlined into HTML."
124 :group
'org-odt-export
125 :type
'(repeat (string :tag
"Extension")))
128 (defcustom org-export-odt-pixels-per-inch display-pixels-per-inch
130 :group
'org-export-odt
135 ;;;_ , potential custom settings
136 (defvar org-export-odt-default-org-styles-alist
137 '((paragraph .
((default .
"Text_20_body")
138 (fixedwidth .
"OrgSourceBlock")
140 (quote .
"Quotations")
141 (blockquote .
"Quotations")
142 (center .
"OrgCenter")
145 (title .
"Heading_20_1.title")
146 (footnote .
"Footnote")
147 (src .
"OrgSourceBlock")
148 (illustration .
"Illustration")
150 (definition-term .
"Text_20_body_20_bold")
151 (horizontal-line .
"Horizontal_20_Line")))
152 (character .
((bold .
"Bold")
153 (emphasis .
"Emphasis")
155 (verbatim .
"OrgCode")
156 (strike .
"Strikethrough")
157 (underline .
"Underline")
158 (subscript .
"OrgSubscript")
159 (superscript .
"OrgSuperscript")))
160 (list .
((ordered .
"OrgNumberedList")
161 (unordered .
"OrgBulletedList")
162 (description .
"OrgDescriptionList"))))
163 "Default styles for various entities.")
165 (defvar org-export-odt-org-styles-alist org-export-odt-default-org-styles-alist
)
166 (defun org-odt-get-style-name-for-entity (category &optional entity
)
167 (let ((entity (or entity
'default
)))
169 (cdr (assoc entity
(cdr (assoc category
170 org-export-odt-org-styles-alist
))))
171 (cdr (assoc entity
(cdr (assoc category
172 org-export-odt-default-org-styles-alist
))))
173 (error "Cannot determine style name for entity %s of type %s"
177 ;;;_. interactive commands
180 (defun org-export-as-odt-and-open (arg)
181 "Export the outline as ODT and immediately open it with a browser.
182 If there is an active region, export only the region.
183 The prefix ARG specifies how many levels of the outline should become
184 headlines. The default is 3. Lower levels will become bulleted lists."
186 (org-export-as-odt arg
'hidden
)
187 (org-open-file buffer-file-name
)
188 (when org-export-kill-product-buffer-when-displayed
189 (kill-buffer (current-buffer))))
192 (defun org-export-as-odt-batch ()
193 "Call the function `org-export-as-odt'.
194 This function can be used in batch processing as:
196 --load=$HOME/lib/emacs/org.el
197 --eval \"(setq org-export-headline-levels 2)\"
198 --visit=MyFile --funcall org-export-as-odt-batch"
199 (org-export-as-odt org-export-headline-levels
'hidden
))
202 (defun org-export-as-odt-to-buffer (arg)
203 "Call `org-export-as-odt` with output to a temporary buffer.
204 No file is created. The prefix ARG is passed through to `org-export-as-odt'."
206 (org-export-as-odt arg nil nil
"*Org ODT Export*")
207 (when org-export-show-temporary-export-buffer
208 (switch-to-buffer-other-window "*Org ODT Export*")))
211 (defun org-replace-region-by-odt (beg end
)
212 "Assume the current region has org-mode syntax, and convert it to ODT.
213 This can be used in any buffer. For example, you could write an
214 itemized list in org-mode syntax in an ODT buffer and then use this
215 command to convert it."
217 (let (reg odt buf pop-up-frames
)
218 (save-window-excursion
220 (setq odt
(org-export-region-as-odt
222 (setq reg
(buffer-substring beg end
)
223 buf
(get-buffer-create "*Org tmp*"))
224 (with-current-buffer buf
228 (setq odt
(org-export-region-as-odt
229 (point-min) (point-max) t
'string
)))
231 (delete-region beg end
)
235 (defun org-export-region-as-odt (beg end
&optional body-only buffer
)
236 "Convert region from BEG to END in org-mode buffer to ODT.
237 If prefix arg BODY-ONLY is set, omit file header, footer, and table of
238 contents, and only produce the region of converted text, useful for
239 cut-and-paste operations.
240 If BUFFER is a buffer or a string, use/create that buffer as a target
241 of the converted ODT. If BUFFER is the symbol `string', return the
242 produced ODT as a string and leave not buffer behind. For example,
243 a Lisp program could call this function in the following way:
245 (setq odt (org-export-region-as-odt beg end t 'string))
247 When called interactively, the output buffer is selected, and shown
248 in a window. A non-interactive call will only return the buffer."
250 (when (interactive-p)
251 (setq buffer
"*Org ODT Export*"))
252 (let ((transient-mark-mode t
) (zmacs-regions t
)
254 (setq ext-plist
(plist-put ext-plist
:ignore-subtree-p t
))
256 (set-mark (point)) ;; to activate the region
258 (setq rtn
(org-export-as-odt
261 (if (fboundp 'deactivate-mark
) (deactivate-mark))
262 (if (and (interactive-p) (bufferp rtn
))
263 (switch-to-buffer-other-window rtn
)
266 ;;; org-export-as-odt
268 (defun org-export-as-odt (arg &optional hidden ext-plist
269 to-buffer body-only pub-dir
)
270 "Export the outline as a OpenDocumentText file.
271 If there is an active region, export only the region. The prefix
272 ARG specifies how many levels of the outline should become
273 headlines. The default is 3. Lower levels will become bulleted
274 lists. HIDDEN is obsolete and does nothing.
275 EXT-PLIST is a property list with external parameters overriding
276 org-mode's default settings, but still inferior to file-local
277 settings. When TO-BUFFER is non-nil, create a buffer with that
278 name and export to that buffer. If TO-BUFFER is the symbol
279 `string', don't leave any buffer behind but just return the
280 resulting XML as a string. When BODY-ONLY is set, don't produce
281 the file header and footer, simply return the content of
282 <body>...</body>, without even the body tags themselves. When
283 PUB-DIR is set, use this as the publishing directory."
285 (run-hooks 'org-export-first-hook
)
286 (let* ((org-parse-get-callback 'org-odt-get
)
287 (org-export-html-special-string-regexps
288 org-export-odt-special-string-regexps
))
289 (org-do-export arg hidden ext-plist to-buffer body-only pub-dir
)))
294 (defvar org-odt-entity-control-callbacks-alist
296 .
(org-odt-begin-export org-odt-end-export
))
298 .
(org-odt-begin-document-content org-odt-end-document-content
))
300 .
(org-odt-begin-document-body org-odt-end-document-body
))
302 .
(org-odt-begin-environment org-odt-end-environment
))
304 .
(org-html-begin-level org-html-end-level
))
306 .
(org-odt-begin-footnote-definition org-odt-end-footnote-definition
))
308 .
(org-odt-begin-table org-odt-end-table
))
310 .
(org-odt-begin-table-rowgroup org-odt-end-table-rowgroup
))
312 .
(org-odt-begin-list org-odt-end-list
))
314 .
(org-odt-begin-list-item org-odt-end-list-item
))
316 .
(org-odt-begin-section org-odt-end-section
))
318 .
(org-odt-begin-paragraph org-odt-end-paragraph
)))
321 (defvar org-odt-entity-format-callbacks-alist
322 `((EXTRA-TARGETS . org-html-format-extra-targets
)
323 (ORG-TAGS . org-html-format-org-tags
)
324 (SECTION-NUMBER . org-html-format-section-number
)
325 (HEADLINE . org-html-format-headline
)
326 (TOC-ENTRY . org-html-format-toc-entry
)
327 (TOC-ITEM . org-html-format-toc-item
)
328 (TAGS . org-odt-format-tags
)
329 (SPACES . org-odt-format-spaces
)
330 (TABS . org-odt-format-tabs
)
331 (LINE-BREAK . org-odt-format-line-break
)
332 (FONTIFY . org-odt-format-fontify
)
333 (TODO . org-html-format-todo
)
334 (LINK . org-odt-format-link
)
335 (INLINE-IMAGE . org-odt-format-inline-image
)
336 (ORG-LINK . org-odt-format-org-link
)
337 (HEADING . org-odt-format-heading
)
338 (ANCHOR . org-odt-format-anchor
)
339 (TABLE-ROW . org-odt-format-table-row
)
340 (TABLE-CELL . org-odt-format-table-cell
)
341 (FOOTNOTES-SECTION . ignore
)
342 (FOOTNOTE-REFERENCE . org-odt-format-footnote-reference
)
343 (HORIZONTAL-LINE . org-odt-format-horizontal-line
)
344 (COMMENT . org-html-format-comment
)
345 (PLAIN . org-odt-format-plain
))
349 ;;;_. control callbacks
351 (defun org-odt-begin-office-body ()
355 <text:sequence-decls>
356 <text:sequence-decl text:display-outline-level=\"0\" text:name=\"Illustration\"/>
357 <text:sequence-decl text:display-outline-level=\"0\" text:name=\"Table\"/>
358 <text:sequence-decl text:display-outline-level=\"0\" text:name=\"Text\"/>
359 <text:sequence-decl text:display-outline-level=\"0\" text:name=\"Drawing\"/>
360 </text:sequence-decls>"))
363 ;; Following variable is let bound when `org-do-export' is in
364 ;; progress. See org-html.el.
365 (defvar org-parse-table-of-contents
)
366 (defun org-odt-begin-document-body (opt-plist)
367 (org-odt-begin-office-body)
368 (let ((title (plist-get opt-plist
:title
)))
371 (org-odt-format-stylized-paragraph 'title title
))))
374 (when org-parse-table-of-contents
375 (insert "\n" org-parse-table-of-contents
"\n")))
377 (defun org-odt-end-document-body (opt-plist)
378 (org-html-insert-tag "</office:text>")
379 (org-html-insert-tag "</office:body>"))
381 (defconst org-odt-document-content-header
382 "<?xml version=\"1.0\" encoding=\"UTF-8\"?>
383 <office:document-content
384 xmlns:office=\"urn:oasis:names:tc:opendocument:xmlns:office:1.0\"
385 xmlns:style=\"urn:oasis:names:tc:opendocument:xmlns:style:1.0\"
386 xmlns:text=\"urn:oasis:names:tc:opendocument:xmlns:text:1.0\"
387 xmlns:table=\"urn:oasis:names:tc:opendocument:xmlns:table:1.0\"
388 xmlns:draw=\"urn:oasis:names:tc:opendocument:xmlns:drawing:1.0\"
389 xmlns:fo=\"urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0\"
390 xmlns:xlink=\"http://www.w3.org/1999/xlink\"
391 xmlns:dc=\"http://purl.org/dc/elements/1.1/\"
392 xmlns:meta=\"urn:oasis:names:tc:opendocument:xmlns:meta:1.0\"
393 xmlns:number=\"urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0\"
394 xmlns:svg=\"urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0\"
395 xmlns:chart=\"urn:oasis:names:tc:opendocument:xmlns:chart:1.0\"
396 xmlns:dr3d=\"urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0\"
397 xmlns:math=\"http://www.w3.org/1998/Math/MathML\"
398 xmlns:form=\"urn:oasis:names:tc:opendocument:xmlns:form:1.0\"
399 xmlns:script=\"urn:oasis:names:tc:opendocument:xmlns:script:1.0\"
400 xmlns:ooo=\"http://openoffice.org/2004/office\"
401 xmlns:ooow=\"http://openoffice.org/2004/writer\"
402 xmlns:oooc=\"http://openoffice.org/2004/calc\"
403 xmlns:dom=\"http://www.w3.org/2001/xml-events\"
404 xmlns:xforms=\"http://www.w3.org/2002/xforms\"
405 xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"
406 xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"
407 xmlns:rpt=\"http://openoffice.org/2005/report\"
408 xmlns:of=\"urn:oasis:names:tc:opendocument:xmlns:of:1.2\"
409 xmlns:xodt=\"http://www.w3.org/1999/xodt\"
410 xmlns:field=\"urn:openoffice:names:experimental:ooo-ms-interop:xmlns:field:1.0\" office:version=\"1.2\">
415 ;;;_ , document content
416 (defun org-odt-begin-document-content (opt-plist)
418 (org-odt-update-meta-file opt-plist
)
421 (insert org-odt-document-content-header
)
424 (insert-file-contents org-export-odt-automatic-styles-file
)
425 (goto-char (point-max)))
427 (defun org-odt-end-document-content ()
428 (org-html-insert-tag "</office:document-content>"))
433 (defun org-odt-begin-section (&optional id class
)
436 (when id
(format " text:name=\"%s\"" id
))
438 (format " text:style-name=\"%s\"" class
)))))
439 (org-html-insert-tag "<text:section%s>" extra
)))
441 (defun org-odt-end-section ()
442 (org-html-insert-tag "</text:section>"))
447 (defun org-odt-begin-paragraph (&optional style
)
449 "<text:p%s>" (org-odt-get-extra-attrs-for-paragraph-style style
)))
451 (defun org-odt-end-paragraph ()
452 (org-html-insert-tag "</text:p>"))
455 (defun org-odt-get-extra-attrs-for-paragraph-style (style)
459 ((stringp style
) style
)
460 ((symbolp style
) (org-odt-get-style-name-for-entity
463 (error "Don't know how to handle paragraph style %s" style
))
464 (format " text:style-name=\"%s\"" style-name
)))
466 (defun org-odt-format-stylized-paragraph (style text
)
467 (org-html-format-tags
468 '("<text:p%s>" .
"</text:p>") text
469 (org-odt-get-extra-attrs-for-paragraph-style style
)))
473 (defun org-odt-begin-environment (style)
475 ((blockquote verse center quote
)
476 (org-parse-begin-paragraph style
)
479 (org-parse-end-paragraph)
481 (t (error "Unknown environment %s" style
))))
483 (defun org-odt-end-environment (style)
485 ((blockquote verse center quote
)
486 (org-parse-end-paragraph)
489 (org-parse-begin-paragraph)
491 (t (error "Unknown environment %s" style
))))
495 (defun org-odt-begin-list (ltype &optional arg1
)
496 (setq ltype
(or (org-html-html-list-type-to-canonical-list-type ltype
)
498 (let* ((style-name (org-odt-get-style-name-for-entity 'list ltype
))
499 (extra (if style-name
500 (format " text:style-name=\"%s\"" style-name
) "")))
502 ;; FIXME: Handle arg1 incase of ordered lists.
504 ((ordered unordered description
)
505 (org-parse-end-paragraph)
506 (org-html-insert-tag "<text:list%s>" extra
))
507 (t (error "Unknown list type: %s" ltype
)))))
509 (defun org-odt-end-list (ltype)
510 (setq ltype
(or (org-html-html-list-type-to-canonical-list-type ltype
)
513 (org-html-insert-tag "</text:list>")
514 (error "Unknown list type: %s" ltype
)))
516 (defun org-odt-begin-list-item (ltype &optional arg
)
517 (setq ltype
(or (org-html-html-list-type-to-canonical-list-type ltype
)
521 (let* ((counter arg
) (extra ""))
522 (org-html-insert-tag "<text:list-item>")
523 (org-parse-begin-paragraph)))
525 (let* ((id arg
) (extra ""))
526 (org-html-insert-tag "<text:list-item>")
527 (org-parse-begin-paragraph)))
529 (let ((term (or arg
"(no term)")))
531 (org-html-format-tags
532 '("<text:list-item>" .
"</text:list-item>")
533 (org-odt-format-stylized-paragraph 'definition-term term
)))
534 (org-parse-begin 'LIST-ITEM
'unordered
)
535 (org-parse-begin 'LIST
'description
)
536 (org-parse-begin 'LIST-ITEM
'unordered
)))
537 (t (error "Unknown list type"))))
539 (defun org-odt-end-list-item (ltype)
540 (setq ltype
(or (org-html-html-list-type-to-canonical-list-type ltype
)
544 (org-html-insert-tag "</text:list-item>"))
547 (org-parse-end 'LIST
'description
)
549 (t (error "Unknown list type"))))
553 ;; Following variables are let bound when table emission is in
554 ;; progress. See org-html.el.
555 (defvar org-table-begin-marker
)
556 (defvar org-table-ncols
)
557 (defvar org-table-rowgroup-open
)
558 (defvar org-table-rownum
)
559 (defvar org-table-current-rowgroup-is-header
)
560 (defvar org-table-is-styled
)
561 (defvar org-table-rowgroup-info
)
562 (defvar org-table-colalign-vector
)
563 (defun org-odt-begin-table (caption label attributes
)
565 (let* ((seqno label
) (id label
))
567 (org-odt-format-stylized-paragraph
568 'table
(org-odt-format-entity-caption
569 "Table" id seqno
(or caption
""))))))
572 "<table:table table:name=\"%s\" table:style-name=\"%s\">"
573 (or label
"") "OrgTable")
574 (setq org-table-begin-marker
(point)))
576 (defun org-odt-end-table ()
577 (goto-char org-table-begin-marker
)
579 (while (< (incf i
) org-table-ncols
)
581 (org-html-format-tags
582 '("<table:table-column >" .
"</table:table-column>") ""))))
584 ;; fill style attributes for table cells
585 (when org-table-is-styled
586 (while (re-search-forward "@@\\(table-cell:p\\|table-cell:style-name\\)@@\\([0-9]+\\)@@\\([0-9]+\\)@@" nil t
)
587 (let ((spec (match-string 1))
588 (r (string-to-number (match-string 2)))
589 (c (string-to-number (match-string 3))))
591 ((equal spec
"table-cell:p")
592 (let ((style-name (org-odt-get-paragraph-style-for-table-cell r c
)))
593 (replace-match style-name t t
)))
594 ((equal spec
"table-cell:style-name")
595 (let ((style-name (org-odt-get-style-name-for-table-cell r c
)))
596 (replace-match style-name t t
)))))))
598 (goto-char (point-max))
599 (org-html-insert-tag "</table:table>"))
601 (defun org-odt-begin-table-rowgroup (&optional is-header-row
)
602 (when org-table-rowgroup-open
603 (org-parse-end 'TABLE-ROWGROUP
))
604 (org-html-insert-tag (if is-header-row
605 "<table:table-header-rows>"
606 "<table:table-rows>"))
607 (setq org-table-rowgroup-open t
)
608 (setq org-table-current-rowgroup-is-header is-header-row
))
610 (defun org-odt-end-table-rowgroup ()
611 (when org-table-rowgroup-open
612 (setq org-table-rowgroup-open nil
)
614 (if org-table-current-rowgroup-is-header
615 "</table:table-header-rows>" "</table:table-rows>"))))
617 (defun org-odt-format-table-row (row)
618 (org-html-format-tags
619 '("<table:table-row>" .
"</table:table-row>") row
))
621 (defun org-odt-get-style-name-for-table-cell (r c
)
626 ((eq (cdr (assoc r org-table-rowgroup-info
)) :start
) "T")
628 (when (= r org-table-rownum
) "B")
631 ((or (memq (nth c org-table-colgroup-info
) '(:start
:startend
))
632 (memq (nth (1- c
) org-table-colgroup-info
) '(:end
:startend
))) "L")
635 (defun org-odt-get-paragraph-style-for-table-cell (r c
)
636 (capitalize (aref org-table-colalign-vector c
)))
638 (defun org-odt-format-table-cell (data r c
)
639 (if (not org-table-is-styled
)
640 (org-html-format-tags
641 '("<table:table-cell>" .
"</table:table-cell>")
642 (org-odt-format-stylized-paragraph
644 (org-table-current-rowgroup-is-header "OrgTableHeading")
645 ((and (= c
0) org-export-html-table-use-header-tags-for-first-column
)
647 (t "OrgTableContents"))
649 (let* ((style-name-cookie
650 (format "@@table-cell:style-name@@%03d@@%03d@@" r c
))
651 (paragraph-style-cookie
654 (org-table-current-rowgroup-is-header "OrgTableHeading")
655 ((and (= c
0) org-export-html-table-use-header-tags-for-first-column
)
657 (t "OrgTableContents"))
658 (format "@@table-cell:p@@%03d@@%03d@@" r c
))))
659 (org-html-format-tags
660 '("<table:table-cell table:style-name=\"%s\">" .
661 "</table:table-cell>")
662 (org-odt-format-stylized-paragraph paragraph-style-cookie data
)
663 style-name-cookie
))))
666 ;;;_ , footnote definition
667 (defun org-odt-begin-footnote-definition (n)
668 (org-parse-begin-paragraph 'footnote
))
670 (defun org-odt-end-footnote-definition (n)
671 (org-parse-end-paragraph))
674 ;;;_. format callbacks
676 ;; Following variable is let bound during 'ORG-LINK callback. See
678 (defvar org-parse-link-description-is-image
)
679 (defun org-odt-format-link (desc href
&optional attr
)
681 ((and (= (string-to-char href
) ?
#) (not org-odt-suppress-xref
))
682 (setq href
(concat org-export-odt-bookmark-prefix
(substring href
1)))
683 (org-html-format-tags
684 '("<text:bookmark-ref text:reference-format=\"text\" text:ref-name=\"%s\">" .
685 "</text:bookmark-ref>")
687 (org-parse-link-description-is-image
688 (org-html-format-tags
689 '("<draw:a xlink:type=\"simple\" xlink:href=\"%s\" %s>" .
"</draw:a>")
690 desc href
(or attr
"")))
692 (org-html-format-tags
693 '("<text:a xlink:type=\"simple\" xlink:href=\"%s\" %s>" .
"</text:a>")
694 desc href
(or attr
"")))))
697 (defun org-odt-format-spaces (n)
698 (org-html-format-tags
699 '("<text:s text:c=\"%d\">" .
"</text:s>") "" n
))
702 (defun org-odt-format-tabs (&optional n
)
703 (let ((tab "<text:tab/>")
708 (defun org-odt-format-line-break ()
709 (org-html-format-tags
710 '("<text:line-break>" .
"</text:line-break>") ""))
712 ;;;_ , horizontal line
713 (defun org-odt-format-horizontal-line ()
714 (org-odt-format-stylized-paragraph 'horizontal-line
""))
717 (defun org-odt-format-plain (line)
718 (case org-parse-dyn-current-environment
719 (fixedwidth (concat (org-odt-format-source-code-or-example-line
720 (org-html-protect line
)) "\n"))
721 (t (concat line
"\n"))))
723 (defun org-odt-fill-tabs-and-spaces (line)
724 (replace-regexp-in-string
725 "\\([\t]\\|\\([ ]+\\)\\)" (lambda (s)
727 ((string= s
"\t") (org-odt-format-tabs))
729 (org-odt-format-spaces (length s
)))
732 (defun org-odt-format-source-code-or-example-line (line)
733 (org-odt-format-stylized-paragraph 'src
(org-odt-fill-tabs-and-spaces line
)))
735 (defun org-odt-format-example (rtn)
736 (let ((lines (org-split-string rtn
"[\r\n]")) out
)
739 (concat out
(org-odt-format-source-code-or-example-line
740 (org-html-protect (pop lines
))))))
741 (concat "\n" out
"\n")))
744 ;;;_ , character styles
745 (defun org-odt-remap-stylenames (style-name)
747 (cdr (assoc style-name
'(("timestamp-wrapper" .
"OrgTimestampWrapper")
748 ("timestamp" .
"OrgTimestamp")
749 ("timestamp-kwd" .
"OrgTimestampKeyword")
753 ("target" .
"OrgTarget"))))
757 (defun org-odt-format-fontify (text style
&optional id
)
761 (org-odt-remap-stylenames style
))
763 (org-odt-get-style-name-for-entity 'character style
))
765 (assert (< 1 (length style
)))
766 (let ((parent-style (pop style
)))
767 (mapconcat (lambda (s)
768 ;; (assert (stringp s) t)
769 (org-odt-remap-stylenames s
)) style
"")
770 (org-odt-remap-stylenames parent-style
)))
771 (t (error "Don't how to handle style %s" style
)))))
772 (org-html-format-tags
773 '("<text:span text:style-name=\"%s\">" .
"</text:span>")
777 (defun org-odt-relocate-relative-path (path dir
)
778 (if (file-name-absolute-p path
) path
779 (file-relative-name (expand-file-name path dir
)
780 (expand-file-name "eyecandy" dir
))))
782 (defun org-odt-format-inline-image (thefile)
783 (let* ((thelink (if (file-name-absolute-p thefile
) thefile
784 (org-export-html-format-href
785 (org-odt-relocate-relative-path
786 thefile org-current-export-file
))))
788 (org-html-format-tags
789 '("<draw:image xlink:href=\"%s\" xlink:type=\"simple\" xlink:show=\"embed\" xlink:actuate=\"onLoad\">" .
"</draw:image>")
791 (if org-export-odt-embed-images
792 (org-odt-copy-image-file thefile
) thelink
))))
793 (org-export-odt-format-image thefile href
)))
795 (defun org-odt-format-org-link (opt-plist type-1 path fragment desc attr
798 OPT-PLIST is an options list.
799 TYPE is the device-type of the link (THIS://foo.html)
800 PATH is the path of the link (http://THIS#locationx)
801 FRAGMENT is the fragment part of the link, if any (foo.html#THIS)
802 DESC is the link description, if any.
803 ATTR is a string of other attributes of the a element.
804 MAY-INLINE-P allows inlining it as an image."
806 (declare (special org-par-open
))
809 (and (member type-1
'("http" "https" "file"))
810 (org-html-should-inline-p path descp
)
812 (type (if (equal type-1
"id") "file" type-1
))
817 ;; check for inlined images
818 ((and (member type
'("file"))
821 filename org-odt-export-inline-image-extensions
)
822 (or (eq t org-odt-export-inline-images
)
823 (and org-odt-export-inline-images
(not descp
))))
825 ;; (when (and (string= type "file") (file-name-absolute-p path))
826 ;; (setq thefile (concat "file://" (expand-file-name path))))
827 ;; (setq thefile (org-export-html-format-href thefile))
828 ;; (org-export-html-format-image thefile)
829 (org-odt-format-inline-image thefile
))
831 (when (string= type
"file")
834 ((file-name-absolute-p path
)
835 (concat "file://" (expand-file-name path
)))
836 (t (org-odt-relocate-relative-path
837 thefile org-current-export-file
)))))
839 (when (and (member type
'("" "http" "https" "file"))
841 (setq thefile
(concat thefile
"#" fragment
)))
843 (setq thefile
(org-export-html-format-href thefile
))
845 (when (not (member type
'("" "file")))
846 (setq thefile
(concat type
":" thefile
)))
849 'LINK
(org-export-html-format-desc desc
) thefile attr
))))))
853 (defun org-odt-format-heading (text level
&optional id class
)
854 (let* ((text (if id
(org-odt-format-target text id
) text
)))
855 ;; FIXME: handle class?
857 (org-html-format-tags
858 '("<text:h text:style-name=\"Heading_20_%s\" text:outline-level=\"%s\">" .
860 (org-odt-format-target text id
) level level
)))
866 (defun org-odt-format-anchor (text name
&optional class
)
867 (org-odt-format-bookmark text name
))
870 ;; ("<text:bookmark text:name=\"%s\"/>" . "")
871 (defun org-odt-format-bookmark (text id
)
873 (org-html-format-tags
874 '("<text:bookmark text:name=\"%s\">" .
"</text:bookmark>") "" id
) text
))
876 ;; ("<text:bookmark-start text:name=\"%s\"/>" .
877 ;; "<text:bookmark-end text:name=\"%s\"/>")
881 (defun org-odt-format-target (text id
)
882 (let ((name (concat org-export-odt-bookmark-prefix id
)))
884 (format "<text:bookmark-start text:name=\"%s\"/>" name
)
885 (concat (org-odt-format-bookmark "" id
) text
)
886 (format "<text:bookmark-end text:name=\"%s\"/>" name
))))
889 ;;;_ , footnote reference
890 (defun org-odt-format-footnote (n def
)
891 (let ((id (concat "fn" n
))
892 (note-class "footnote")
893 (par-style "Footnote"))
894 (org-html-format-tags
895 '("<text:note text:id=\"%s\" text:note-class=\"%s\">" .
898 (org-html-format-tags
899 '("<text:note-citation>" .
"</text:note-citation>")
901 (org-html-format-tags
902 '("<text:note-body>" .
"</text:note-body>")
907 (defun org-odt-format-footnote-reference (n def refcnt
)
909 (org-odt-format-footnote n def
)
910 (org-odt-format-footnote-ref n
)))
913 (defun org-odt-format-footnote-ref (n)
914 (let ((note-class "footnote")
916 (ref-name (concat "fn" n
)))
917 (org-html-format-tags
918 '("<text:span text:style-name=\"%s\">" .
"</text:span>")
919 (org-html-format-tags
920 '("<text:note-ref text:note-class=\"%s\" text:reference-format=\"%s\" text:ref-name=\"%s\">" .
"</text:note-ref>")
921 n note-class ref-format ref-name
)
926 (defun org-odt-get-image-name (file-name)
930 (concat (sha1 file-name
) "." (file-name-extension file-name
)) "Pictures")))
932 (defun org-export-odt-format-image (src href
935 "Create image tag with source and attributes."
938 (let (embed-as caption attr label attr-plist size width height
)
941 ((string-match "^ltxpng/" src
)
942 ;; FIXME: Anyway the latex src can be embedded as an
945 ;; (org-find-text-property-in-string 'org-latex-src src)
946 (setq caption nil attr nil label nil embed-as
'character
))
949 (setq caption
(org-find-text-property-in-string 'org-caption src
)
950 caption
(and caption
(org-export-html-format-desc caption
))
951 attr
(org-find-text-property-in-string 'org-attributes src
)
952 label
(org-find-text-property-in-string 'org-label src
)
953 embed-as
'paragraph
)))
955 (setq attr-plist
(when attr
(read attr
)))
956 (setq size
(org-odt-image-size-from-file
957 src
(plist-get attr-plist
:width
)
958 (plist-get attr-plist
:height
)
959 (plist-get attr-plist
:scale
)))
961 (org-export-odt-do-format-image embed-as caption attr label
965 (defun org-export-odt-do-format-image (embed-as caption attr label
967 "Create image tag with source and attributes."
969 (let ((width (car size
)) (height (cdr size
))
971 '("<draw:frame draw:style-name=\"%s\"
972 text:anchor-type=\"%s\"
973 draw:z-index=\"%d\" %s>" .
"</draw:frame>")))
975 ((and (not caption
) (not label
))
976 (let (style-name anchor-type
)
978 ((eq embed-as
'paragraph
)
979 (setq style-name
"OrgGraphicsParagraph" anchor-type
"paragraph"))
980 ((eq embed-as
'character
)
981 (setq style-name
"OrgGraphicsBaseline" anchor-type
"as-char")))
982 (org-html-format-tags
983 draw-frame-pair href style-name anchor-type
0
984 (org-odt-image-attrs-from-size width height
))))
988 ;; (when par-open (org-odt-close-par))
989 (org-html-format-tags
991 (org-html-format-tags
992 '("<draw:text-box fo:min-height=\"%dcm\">" .
"</draw:text-box>")
993 (org-odt-format-stylized-paragraph
996 (let ((extra " style:rel-width=\"100%\" style:rel-height=\"scale\""))
997 (org-html-format-tags
998 draw-frame-pair href
"OrgGraphicsParagraphContent" "paragraph" 2
999 (concat (org-odt-image-attrs-from-size width height
) extra
)))
1000 (let ((seqno label
))
1001 (org-odt-format-entity-caption
1002 "Illustration" label seqno caption
))))
1004 "OrgFrame" "paragraph" 1
1005 (org-odt-image-attrs-from-size width
))
1007 ;; (when par-open (org-odt-open-par))
1011 (defun org-odt-copy-image-file (path &optional target-file
)
1012 "Returns the internal name of the file"
1013 (let* ((image-type (file-name-extension path
))
1014 (media-type (format "image/%s" image-type
))
1015 (src-file (expand-file-name
1016 path
(file-name-directory org-current-export-file
)))
1017 (target-file (or target-file
(org-odt-get-image-name src-file
)))
1022 (message "Embedding %s as %s ..."
1023 (substring-no-properties path
) target-file
)
1024 (copy-file src-file target-file
'overwrite
)
1025 (org-odt-update-manifest-file media-type target-file
)
1026 (push target-file org-export-odt-file-list
)) target-file
))
1028 (defun org-odt-image-attrs-from-size (&optional width height
)
1030 (when width
(format "svg:width=\"%0.2fcm\"" width
))
1032 (when height
(format "svg:height=\"%0.2fcm\"" height
))))
1034 (defun org-odt-image-size-from-file (file &optional user-width
1035 user-height scale dpi
)
1036 (unless (file-name-absolute-p file
)
1037 (setq file
(expand-file-name
1038 file
(file-name-directory org-current-export-file
))))
1040 (setq dpi
(or dpi org-export-odt-pixels-per-inch
))
1041 (let* ((size (image-size (create-image file
) 'pixels
))
1042 (width-in-pixels (car size
)) (height-in-pixels (cdr size
))
1043 (width-in-inches (/ width-in-pixels dpi
))
1044 (height-in-inches (/ height-in-pixels dpi
))
1046 (width-in-cms (* cms-per-inch width-in-inches
))
1047 (height-in-cms (* cms-per-inch height-in-inches
))
1048 (width width-in-cms
) (height height-in-cms
))
1049 (cond (scale (setq width
(* width scale
) height
(* height scale
)))
1050 ((and user-height user-width
)
1051 (setq width user-width height user-height
))
1052 (user-height (setq width
(* user-height
(/ width height
))
1053 height user-height
))
1054 (user-width (setq height
(* user-width
(/ height width
))
1057 (cons width height
)))
1059 (defun org-odt-format-entity-caption (entity label seqno caption
)
1062 (org-html-format-tags
1063 '("<text:sequence text:ref-name=\"%s\" text:name=\"%s\" text:formula=\"ooow:%s+1\" style:num-format=\"1\">" .
"</text:sequence>")
1064 (format "%s " seqno
) label entity entity
)
1067 ;;;_. maintenance callbacks
1070 (defun org-odt-init-outfile (filename)
1071 (let* ((outdir (make-temp-file org-export-odt-tmpdir-prefix t
))
1072 (mimetype-file (expand-file-name "mimetype" outdir
))
1073 (content-file (expand-file-name "content.xml" outdir
))
1074 (manifest-file (expand-file-name "META-INF/manifest.xml" outdir
))
1075 (meta-file (expand-file-name "meta.xml" outdir
))
1076 (styles-file (expand-file-name "styles.xml" outdir
))
1077 (pictures-dir (expand-file-name "Pictures" outdir
))
1081 (with-current-buffer (find-file-noselect content-file
) (erase-buffer))
1083 ;; FIXME: How to factor in body-only here
1086 (make-directory (file-name-directory manifest-file
))
1087 (with-current-buffer (find-file-noselect manifest-file
)
1089 (insert (mapconcat 'identity
(car org-export-odt-manifest-lines
) "\n"))
1092 (insert (mapconcat 'identity
(cdr org-export-odt-manifest-lines
) "\n"))))
1095 (with-current-buffer (find-file-noselect meta-file
)
1097 (insert (mapconcat 'identity
(car org-export-odt-meta-lines
) "\n"))
1100 (insert (mapconcat 'identity
(cdr org-export-odt-meta-lines
) "\n"))))
1103 ;; (copy-file org-export-odt-styles-file styles-file t)
1106 (make-directory pictures-dir
)
1108 ;; initialize list of files that contribute to the odt file
1109 (setq org-export-odt-file-list
1110 (append org-export-odt-save-list org-export-odt-nosave-list
)))
1115 ;; xml files generated on-the-fly
1116 (defconst org-export-odt-save-list
1117 '("META-INF/manifest.xml" "content.xml" "meta.xml"))
1119 ;; xml files that are copied
1120 (defconst org-export-odt-nosave-list
'("styles.xml"))
1122 ;; xml files that contribute to the final odt file
1123 (defvar org-export-odt-file-list nil
)
1125 (defconst org-export-odt-manifest-lines
1126 '(("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
1127 "<manifest:manifest xmlns:manifest=\"urn:oasis:names:tc:opendocument:xmlns:manifest:1.0\">"
1128 "<manifest:file-entry manifest:media-type=\"application/vnd.oasis.opendocument.text\" manifest:version=\"1.2\" manifest:full-path=\"/\"/>"
1129 "<manifest:file-entry manifest:media-type=\"text/xml\" manifest:full-path=\"content.xml\"/>"
1130 "<manifest:file-entry manifest:media-type=\"text/xml\" manifest:full-path=\"styles.xml\"/>"
1131 "<manifest:file-entry manifest:media-type=\"text/xml\" manifest:full-path=\"meta.xml\"/>"
1132 "<manifest:file-entry manifest:media-type=\"\" manifest:full-path=\"Pictures/\"/>") .
("</manifest:manifest>")))
1134 (defconst org-export-odt-meta-lines
1135 '(("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
1136 "<office:document-meta"
1137 " xmlns:office=\"urn:oasis:names:tc:opendocument:xmlns:office:1.0\""
1138 " xmlns:xlink=\"http://www.w3.org/1999/xlink\""
1139 " xmlns:dc=\"http://purl.org/dc/elements/1.1/\""
1140 " xmlns:meta=\"urn:oasis:names:tc:opendocument:xmlns:meta:1.0\""
1141 " xmlns:ooo=\"http://openoffice.org/2004/office\" "
1142 " office:version=\"1.2\">"
1143 " <office:meta>") .
(" </office:meta>" "</office:document-meta>")))
1145 (defconst org-export-odt-mimetype-lines
1146 '("application/vnd.oasis.opendocument.text"))
1148 (defconst org-odt-manifest-file-entry-tag
1149 "<manifest:file-entry manifest:media-type=\"%s\" manifest:full-path=\"%s\"/>")
1151 (defun org-odt-save-as-outfile (target)
1152 (org-odt-copy-styles-file)
1153 (let ((zipdir default-directory
))
1154 (message "Switching to directory %s" (expand-file-name zipdir
))
1156 ;; save all xml files
1157 (mapc (lambda (file)
1158 (with-current-buffer (find-file-noselect (expand-file-name file
))
1160 (indent-region (point-min) (point-max)) (save-buffer)))
1161 org-export-odt-save-list
)
1163 (let* ((target-name (file-name-nondirectory target
))
1164 (target-dir (file-name-directory target
))
1165 (cmd (format "zip -rmTq %s %s" target-name
".")))
1166 (when (file-exists-p target
)
1167 ;; FIXME: If the file is locked this throws a cryptic error
1168 (delete-file target
))
1170 (let ((coding-system-for-write 'no-conversion
) exitcode
)
1171 (message "Creating odt file using \"%s\"" cmd
)
1173 (apply 'call-process
1178 (append (list "-rmTq") (list target-name
"."))))
1180 (or (zerop exitcode
)
1181 (error "Unable to create odt file (%S)" exitcode
)))
1183 ;; move the file from outdir to target-dir
1184 (rename-file target-name target-dir
)
1186 ;; kill all xml buffers
1187 (mapc (lambda (file)
1188 (kill-buffer (find-file-noselect (expand-file-name file zipdir
))))
1189 org-export-odt-save-list
)
1191 (delete-directory zipdir
)))
1193 ;; FIXME: How to open the file without visiting
1196 (defun org-odt-update-meta-file (opt-plist)
1197 (with-current-buffer
1198 (find-file-noselect "meta.xml" (file-name-directory buffer-file-name
))
1199 (let ((date (or (plist-get opt-plist
:effective-date
) ""))
1200 (author (or (plist-get opt-plist
:author
) ""))
1201 (email (plist-get opt-plist
:email
))
1202 (keywords (plist-get opt-plist
:keywords
))
1203 (description (plist-get opt-plist
:description
))
1204 (title (plist-get opt-plist
:title
)))
1208 (org-html-format-tags '("<dc:creator>" .
"</dc:creator>") author
)
1209 (org-html-format-tags
1210 '("\n<dc:initial-creator>" .
"</dc:initial-creator>") author
)
1211 (org-html-format-tags '("\n<dc:date>" .
"</dc:date>") date
)
1212 (org-html-format-tags
1213 '("\n<meta:creation-date>" .
"</meta:creation-date>") date
)
1214 (org-html-format-tags '("\n<meta:generator>" .
"</meta:generator>")
1215 (when org-export-creator-info
1216 (format "Org-%s/Emacs-%s"
1217 org-version emacs-version
)))
1218 (org-html-format-tags '("\n<meta:keyword>" .
"</meta:keyword>") keywords
)
1219 (org-html-format-tags '("\n<dc:subject>" .
"</dc:subject>") description
)
1220 (org-html-format-tags '("\n<dc:title>" .
"</dc:title>") title
)
1224 (defun org-odt-update-manifest-file (media-type full-path
)
1225 (with-current-buffer
1226 (find-file-noselect "META-INF/manifest.xml")
1227 (insert (format org-odt-manifest-file-entry-tag media-type full-path
))))
1230 ;;;_ , cleanup method
1232 (defun org-odt-finalize-outfile ()
1233 (message "org-newodt: Finalizing outfile")
1234 (org-odt-delete-empty-paragraphs))
1236 (defun org-odt-delete-empty-paragraphs ()
1237 (goto-char (point-min))
1238 (let ((open "<text:p[^>]*>")
1239 (close "</text:p>"))
1240 (while (re-search-forward (format "%s[ \r\n\t]*%s" open close
) nil t
)
1241 (replace-match ""))))
1244 (defun org-odt-get (what &optional opt-plist
)
1247 (EXPORT-DIR (org-export-directory :html opt-plist
))
1248 (FILE-NAME-EXTENSION "odt")
1249 (EXPORT-BUFFER-NAME "*Org ODT Export*")
1250 (ENTITY-CONTROL org-odt-entity-control-callbacks-alist
)
1251 (ENTITY-FORMAT org-odt-entity-format-callbacks-alist
)
1252 (INIT-METHOD 'org-odt-init-outfile
)
1253 (FINAL-METHOD 'org-odt-finalize-outfile
)
1254 (SAVE-METHOD 'org-odt-save-as-outfile
)
1255 (t (error "Unknown property: %s" what
))))
1259 (defun org-export-odt-format-source-code-or-example
1260 (lang code
&optional opts indent caption
)
1261 "Format CODE from language LANG and return it formatted for export.
1262 If LANG is nil, do not add any fontification.
1263 OPTS contains formatting options, like `-n' for triggering numbering lines,
1264 and `+n' for continuing previous numbering.
1265 Code formatting according to language currently only works for HTML.
1266 Numbering lines works for all three major backends (html, latex, and ascii).
1267 INDENT was the original indentation of the block."
1269 (let (num cont rtn rpllbl keepp textareap preserve-indentp cols rows fmt
)
1270 (setq opts
(or opts
"")
1271 num
(string-match "[-+]n\\>" opts
)
1272 cont
(string-match "\\+n\\>" opts
)
1273 rpllbl
(string-match "-r\\>" opts
)
1274 keepp
(string-match "-k\\>" opts
)
1275 textareap
(string-match "-t\\>" opts
)
1276 preserve-indentp
(or org-src-preserve-indentation
1277 (string-match "-i\\>" opts
))
1278 cols
(if (string-match "-w[ \t]+\\([0-9]+\\)" opts
)
1279 (string-to-number (match-string 1 opts
))
1281 rows
(if (string-match "-h[ \t]+\\([0-9]+\\)" opts
)
1282 (string-to-number (match-string 1 opts
))
1283 (org-count-lines code
))
1284 fmt
(if (string-match "-l[ \t]+\"\\([^\"\n]+\\)\"" opts
)
1285 (match-string 1 opts
)))
1286 (if keepp
(setq rpllbl
'keep
))
1287 (setq rtn
(if preserve-indentp code
(org-remove-indentation code
)))
1288 (when (string-match "^," rtn
)
1289 (setq rtn
(with-temp-buffer
1291 ;; Free up the protected lines
1292 (goto-char (point-min))
1293 (while (re-search-forward "^," nil t
)
1294 (if (or (equal lang
"org")
1296 (looking-at "\\([*#]\\|[ \t]*#\\+\\)")))
1302 (concat "\n#+BEGIN_ODT\n"
1304 (org-odt-format-example rtn
)
1305 '(org-protected t org-example t
))
1307 nil
'original-indentation indent
))))
1309 (defun org-export-odt-preprocess (parameters)
1310 "Convert LaTeX fragments to images."
1311 (when (and org-current-export-file
1312 (plist-get parameters
:LaTeX-fragments
))
1314 (concat "ltxpng/" (file-name-sans-extension
1315 (file-name-nondirectory
1316 org-current-export-file
)))
1317 org-current-export-dir nil
"Creating LaTeX image %s"
1320 ((eq (plist-get parameters
:LaTeX-fragments
) 'verbatim
) 'verbatim
)
1321 ((eq (plist-get parameters
:LaTeX-fragments
) 'mathjax
) 'mathjax
)
1322 ((eq (plist-get parameters
:LaTeX-fragments
) t
) 'mathjax
)
1323 ((eq (plist-get parameters
:LaTeX-fragments
) 'dvipng
) 'dvipng
)
1325 (goto-char (point-min))
1327 (while (re-search-forward "\\\\ref{\\([^{}\n]+\\)}" nil t
)
1328 (org-if-unprotected-at (match-beginning 1)
1329 (setq label
(match-string 1))
1331 (if (string-match "\\`[a-z]\\{1,10\\}:\\(.+\\)" label
)
1332 (setq l1
(substring label
(match-beginning 1)))
1335 (let ((org-html-protect t
))
1336 (org-html-format-tags
1337 '("<text:sequence-ref text:reference-format=\"value\" text:ref-name=\"%s\">"
1338 .
"</text:sequence-ref>")
1342 (defun org-odt-zip-extract-one (archive member
&optional target
)
1343 (let* ((target (or target default-directory
))
1344 (archive (expand-file-name archive
))
1345 (archive-zip-extract
1346 (list "unzip" "-qq" "-o" "-d" target
))
1347 exit-code command-output
)
1348 (setq command-output
1350 (setq exit-code
(archive-zip-extract archive member
))
1352 (unless (zerop exit-code
)
1353 (message command-output
)
1354 (error "Extraction failed"))))
1356 (defun org-odt-zip-extract (archive members
&optional target
)
1357 (when (atom members
) (setq members
(list members
)))
1358 (mapc (lambda (member)
1359 (org-odt-zip-extract-one archive member target
))
1362 (defun org-odt-copy-styles-file (&optional styles-file
)
1363 ;; Non-availability of styles.xml is not a critical error. For now
1364 ;; throw an error purely for aesthetic reasons.
1365 (setq styles-file
(or styles-file
1366 org-export-odt-styles-file
1367 (error "org-odt: Missing styles file?")))
1369 ((listp styles-file
)
1370 (let ((archive (nth 0 styles-file
))
1371 (members (nth 1 styles-file
)))
1372 (org-odt-zip-extract archive members
)
1375 (when (org-file-image-p member
)
1376 (let* ((image-type (file-name-extension member
))
1377 (media-type (format "image/%s" image-type
)))
1378 (org-odt-update-manifest-file media-type member
))))
1380 ((and (stringp styles-file
) (file-exists-p styles-file
))
1381 (setq styles-file-type
(file-name-extension styles-file
))
1383 ((string= styles-file-type
"xml")
1384 (copy-file styles-file
"styles.xml" t
))
1385 ((member styles-file-type
'("odt" "ott"))
1386 (org-odt-zip-extract styles-file
"styles.xml"))))
1388 (error (format "Invalid specification of styles.xml file: %S"
1389 org-export-odt-styles-file
)))))