adding function for batch test evaluation
[org-mode.git] / contrib / lisp / org-lparse.el
blob6e391c88f51081c9cb5a72b44d57f1a0501d9f65
1 ;;; org-lparse.el --- Line-oriented parser-exporter for Org-mode
3 ;; Copyright (C) 2010-2011 Jambunathan <kjambunathan at gmail dot com>
5 ;; Author: Jambunathan K <kjambunathan at gmail dot com>
6 ;; Keywords: outlines, hypermedia, calendar, wp
7 ;; Homepage: http://orgmode.org
8 ;; Version: 0.8
10 ;; This file is not (yet) part of GNU Emacs.
11 ;; However, it is distributed under the same license.
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 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
27 ;;; Commentary:
29 ;; `org-lparse' is the entry point for the generic line-oriented
30 ;; exporter. `org-do-lparse' is the genericized version of the
31 ;; original `org-export-as-html' routine.
33 ;; `org-lparse-native-backends' is a good starting point for
34 ;; exploring the generic exporter.
36 ;; Following new interactive commands are provided by this library.
37 ;; `org-lparse', `org-lparse-and-open', `org-lparse-to-buffer'
38 ;; `org-replace-region-by', `org-lparse-region'.
40 ;; Note that the above routines correspond to the following routines
41 ;; in the html exporter `org-export-as-html',
42 ;; `org-export-as-html-and-open', `org-export-as-html-to-buffer',
43 ;; `org-replace-region-by-html' and `org-export-region-as-html'.
45 ;; The new interactive command `org-lparse-convert' can be used to
46 ;; convert documents between various formats. Use this to command,
47 ;; for example, to convert odt file to doc or pdf format.
49 ;; See README.org file that comes with this library for answers to
50 ;; FAQs and more information on using this library.
52 ;;; Code:
54 (require 'org-exp)
55 (require 'org-list)
57 ;;;###autoload
58 (defun org-lparse-and-open (target-backend native-backend arg)
59 "Export outline to TARGET-BACKEND via NATIVE-BACKEND and open exported file.
60 If there is an active region, export only the region. The prefix
61 ARG specifies how many levels of the outline should become
62 headlines. The default is 3. Lower levels will become bulleted
63 lists."
64 ;; (interactive "Mbackend: \nP")
65 (interactive
66 (let* ((input (if (featurep 'ido) 'ido-completing-read 'completing-read))
67 (all-backends (org-lparse-all-backends))
68 (target-backend
69 (funcall input "Export to: " all-backends nil t nil))
70 (native-backend
71 (or
72 ;; (and (org-lparse-backend-is-native-p target-backend)
73 ;; target-backend)
74 (funcall input "Use Native backend: "
75 (cdr (assoc target-backend all-backends)) nil t nil))))
76 (list target-backend native-backend current-prefix-arg)))
77 (let (f (file-or-buf (org-lparse target-backend native-backend
78 arg 'hidden)))
79 (when file-or-buf
80 (setq f (cond
81 ((bufferp file-or-buf) buffer-file-name)
82 ((file-exists-p file-or-buf) file-or-buf)
83 (t (error "org-lparse-and-open: This shouldn't happen"))))
84 (message "Opening file %s" f)
85 (org-open-file f)
86 (when org-export-kill-product-buffer-when-displayed
87 (kill-buffer (current-buffer))))))
89 ;;;###autoload
90 (defun org-lparse-batch (target-backend &optional native-backend)
91 "Call the function `org-lparse'.
92 This function can be used in batch processing as:
93 emacs --batch
94 --load=$HOME/lib/emacs/org.el
95 --eval \"(setq org-export-headline-levels 2)\"
96 --visit=MyFile --funcall org-lparse-batch"
97 (setq native-backend (or native-backend target-backend))
98 (org-lparse target-backend native-backend
99 org-export-headline-levels 'hidden))
101 ;;;###autoload
102 (defun org-lparse-to-buffer (backend arg)
103 "Call `org-lparse' with output to a temporary buffer.
104 No file is created. The prefix ARG is passed through to
105 `org-lparse'."
106 (interactive "Mbackend: \nP")
107 (let ((tempbuf (format "*Org %s Export*" (upcase backend))))
108 (org-lparse backend backend arg nil nil tempbuf)
109 (when org-export-show-temporary-export-buffer
110 (switch-to-buffer-other-window tempbuf))))
112 ;;;###autoload
113 (defun org-replace-region-by (backend beg end)
114 "Assume the current region has org-mode syntax, and convert it to HTML.
115 This can be used in any buffer. For example, you could write an
116 itemized list in org-mode syntax in an HTML buffer and then use
117 this command to convert it."
118 (interactive "Mbackend: \nr")
119 (let (reg backend-string buf pop-up-frames)
120 (save-window-excursion
121 (if (org-mode-p)
122 (setq backend-string (org-lparse-region backend beg end t 'string))
123 (setq reg (buffer-substring beg end)
124 buf (get-buffer-create "*Org tmp*"))
125 (with-current-buffer buf
126 (erase-buffer)
127 (insert reg)
128 (org-mode)
129 (setq backend-string (org-lparse-region backend (point-min)
130 (point-max) t 'string)))
131 (kill-buffer buf)))
132 (delete-region beg end)
133 (insert backend-string)))
135 ;;;###autoload
136 (defun org-lparse-region (backend beg end &optional body-only buffer)
137 "Convert region from BEG to END in org-mode buffer to HTML.
138 If prefix arg BODY-ONLY is set, omit file header, footer, and table of
139 contents, and only produce the region of converted text, useful for
140 cut-and-paste operations.
141 If BUFFER is a buffer or a string, use/create that buffer as a target
142 of the converted HTML. If BUFFER is the symbol `string', return the
143 produced HTML as a string and leave not buffer behind. For example,
144 a Lisp program could call this function in the following way:
146 (setq html (org-lparse-region \"html\" beg end t 'string))
148 When called interactively, the output buffer is selected, and shown
149 in a window. A non-interactive call will only return the buffer."
150 (interactive "Mbackend: \nr\nP")
151 (when (org-called-interactively-p 'any)
152 (setq buffer (format "*Org %s Export*" (upcase backend))))
153 (let ((transient-mark-mode t) (zmacs-regions t)
154 ext-plist rtn)
155 (setq ext-plist (plist-put ext-plist :ignore-subtree-p t))
156 (goto-char end)
157 (set-mark (point)) ;; to activate the region
158 (goto-char beg)
159 (setq rtn (org-lparse backend backend nil nil ext-plist buffer body-only))
160 (if (fboundp 'deactivate-mark) (deactivate-mark))
161 (if (and (org-called-interactively-p 'any) (bufferp rtn))
162 (switch-to-buffer-other-window rtn)
163 rtn)))
165 (defvar org-lparse-par-open nil)
167 (defun org-lparse-should-inline-p (filename descp)
168 "Return non-nil if link FILENAME should be inlined.
169 The decision to inline the FILENAME link is based on the current
170 settings. DESCP is the boolean of whether there was a link
171 description. See variables `org-export-html-inline-images' and
172 `org-export-html-inline-image-extensions'."
173 (let ((inline-images (org-lparse-get 'INLINE-IMAGES))
174 (inline-image-extensions
175 (org-lparse-get 'INLINE-IMAGE-EXTENSIONS)))
176 (and (or (eq t inline-images) (and inline-images (not descp)))
177 (org-file-image-p filename inline-image-extensions))))
179 (defun org-lparse-format-org-link (line opt-plist)
180 "Return LINE with markup of Org mode links.
181 OPT-PLIST is the export options list."
182 (let ((start 0)
183 (current-dir (if buffer-file-name
184 (file-name-directory buffer-file-name)
185 default-directory))
186 (link-validate (plist-get opt-plist :link-validation-function))
187 type id-file fnc
188 rpl path attr desc descp desc1 desc2 link
189 org-lparse-link-description-is-image)
190 (while (string-match org-bracket-link-analytic-regexp++ line start)
191 (setq org-lparse-link-description-is-image nil)
192 (setq start (match-beginning 0))
193 (setq path (save-match-data (org-link-unescape
194 (match-string 3 line))))
195 (setq type (cond
196 ((match-end 2) (match-string 2 line))
197 ((save-match-data
198 (or (file-name-absolute-p path)
199 (string-match "^\\.\\.?/" path)))
200 "file")
201 (t "internal")))
202 (setq path (org-extract-attributes (org-link-unescape path)))
203 (setq attr (get-text-property 0 'org-attributes path))
204 (setq desc1 (if (match-end 5) (match-string 5 line))
205 desc2 (if (match-end 2) (concat type ":" path) path)
206 descp (and desc1 (not (equal desc1 desc2)))
207 desc (or desc1 desc2))
208 ;; Make an image out of the description if that is so wanted
209 (when (and descp (org-file-image-p
210 desc (org-lparse-get 'INLINE-IMAGE-EXTENSIONS)))
211 (setq org-lparse-link-description-is-image t)
212 (save-match-data
213 (if (string-match "^file:" desc)
214 (setq desc (substring desc (match-end 0)))))
215 (save-match-data
216 (setq desc (org-add-props
217 (org-lparse-format 'INLINE-IMAGE desc)
218 '(org-protected t)))))
219 (cond
220 ((equal type "internal")
221 (let
222 ((frag-0
223 (if (= (string-to-char path) ?#)
224 (substring path 1)
225 path)))
226 (setq rpl
227 (org-lparse-format
228 'ORG-LINK opt-plist "" "" (org-solidify-link-text
229 (save-match-data
230 (org-link-unescape frag-0))
231 nil) desc attr descp))))
232 ((and (equal type "id")
233 (setq id-file (org-id-find-id-file path)))
234 ;; This is an id: link to another file (if it was the same file,
235 ;; it would have become an internal link...)
236 (save-match-data
237 (setq id-file (file-relative-name
238 id-file
239 (file-name-directory org-current-export-file)))
240 (setq rpl
241 (org-lparse-format
242 'ORG-LINK opt-plist type id-file
243 (concat (if (org-uuidgen-p path) "ID-") path)
244 desc attr descp))))
245 ((member type '("http" "https"))
246 ;; standard URL, can inline as image
247 (setq rpl
248 (org-lparse-format
249 'ORG-LINK opt-plist type path nil desc attr descp)))
250 ((member type '("ftp" "mailto" "news"))
251 ;; standard URL, can't inline as image
252 (setq rpl
253 (org-lparse-format
254 'ORG-LINK opt-plist type path nil desc attr descp)))
256 ((string= type "coderef")
257 (setq rpl
258 (org-lparse-format
259 'ORG-LINK opt-plist type "" (format "coderef-%s" path)
260 (format
261 (org-export-get-coderef-format
262 path
263 (and descp desc))
264 (cdr (assoc path org-export-code-refs))) nil descp)))
266 ((functionp (setq fnc (nth 2 (assoc type org-link-protocols))))
267 ;; The link protocol has a function for format the link
268 (setq rpl
269 (save-match-data
270 (funcall fnc (org-link-unescape path) desc1 'html))))
272 ((string= type "file")
273 ;; FILE link
274 (save-match-data
275 (let*
276 ((components
278 (string-match "::\\(.*\\)" path)
279 (list
280 (replace-match "" t nil path)
281 (match-string 1 path))
282 (list path nil)))
284 ;;The proper path, without a fragment
285 (path-1
286 (first components))
288 ;;The raw fragment
289 (fragment-0
290 (second components))
292 ;;Check the fragment. If it can't be used as
293 ;;target fragment we'll pass nil instead.
294 (fragment-1
296 (and fragment-0
297 (not (string-match "^[0-9]*$" fragment-0))
298 (not (string-match "^\\*" fragment-0))
299 (not (string-match "^/.*/$" fragment-0)))
300 (org-solidify-link-text
301 (org-link-unescape fragment-0))
302 nil))
303 (desc-2
304 ;;Description minus "file:" and ".org"
305 (if (string-match "^file:" desc)
306 (let
307 ((desc-1 (replace-match "" t t desc)))
308 (if (string-match "\\.org$" desc-1)
309 (replace-match "" t t desc-1)
310 desc-1))
311 desc)))
313 (setq rpl
315 (and
316 (functionp link-validate)
317 (not (funcall link-validate path-1 current-dir)))
318 desc
319 (org-lparse-format
320 'ORG-LINK opt-plist "file" path-1 fragment-1
321 desc-2 attr descp))))))
324 ;; just publish the path, as default
325 (setq rpl (concat "<i>&lt;" type ":"
326 (save-match-data (org-link-unescape path))
327 "&gt;</i>"))))
328 (setq line (replace-match rpl t t line)
329 start (+ start (length rpl))))
330 line))
332 (defmacro with-org-lparse-preserve-paragraph-state (&rest body)
333 `(let ((org-lparse-do-open-par org-lparse-par-open))
334 (org-lparse-end-paragraph)
335 ,@body
336 (when org-lparse-do-open-par
337 (org-lparse-begin-paragraph))))
338 (def-edebug-spec with-org-lparse-preserve-paragraph-state (body))
340 (defvar org-lparse-native-backends nil
341 "List of native backends registered with `org-lparse'.
342 A backend can use `org-lparse-register-backend' to add itself to
343 this list.
345 All native backends must implement a get routine and a mandatory
346 set of callback routines.
348 The get routine must be named as org-<backend>-get where backend
349 is the name of the backend. The exporter uses `org-lparse-get'
350 and retrieves the backend-specific callback by querying for
351 ENTITY-CONTROL and ENTITY-FORMAT variables.
353 For the sake of illustration, the html backend implements
354 `org-xhtml-get'. It returns
355 `org-xhtml-entity-control-callbacks-alist' and
356 `org-xhtml-entity-format-callbacks-alist' as the values of
357 ENTITY-CONTROL and ENTITY-FORMAT settings.")
359 (defun org-lparse-register-backend (backend)
360 "Make BACKEND known to `org-lparse' library.
361 Add BACKEND to `org-lparse-native-backends'."
362 (when backend
363 (setq backend (cond
364 ((symbolp backend) (symbol-name backend))
365 ((stringp backend) backend)
366 (t (error "Error while registering backend: %S" backend))))
367 (add-to-list 'org-lparse-native-backends backend)))
369 (defun org-lparse-unregister-backend (backend)
370 (setq org-lparse-native-backends
371 (remove (cond
372 ((symbolp backend) (symbol-name backend))
373 ((stringp backend) backend))
374 org-lparse-native-backends))
375 (message "Unregistered backend %S" backend))
377 (defun org-lparse-get-other-backends (in-fmt)
378 "Return OUTPUT-FMT-ALIST corresponding to IN-FMT.
379 See `org-lparse-convert-capabilities' for definition of
380 OUTPUT-FMT-ALIST."
381 (when (org-lparse-get-converter in-fmt)
382 (or (ignore-errors (org-lparse-backend-get in-fmt 'OTHER-BACKENDS) )
383 (catch 'out-fmts
384 (dolist (c org-lparse-convert-capabilities)
385 (when (member in-fmt (nth 1 c))
386 (throw 'out-fmts (nth 2 c))))))))
388 (defun org-lparse-get-converter (in-fmt)
389 "Return converter associated with IN-FMT.
390 See `org-lparse-convert-capabilities' for further information."
391 (or (ignore-errors (org-lparse-backend-get in-fmt 'CONVERT-METHOD))
392 org-lparse-convert-process))
394 (defun org-lparse-all-backends ()
395 "Return all formats to which `org-lparse' could export to.
396 The return value is an alist of the form (TARGET-BACKEND
397 NATIVE-BACKEND-1 NATIVE-BACKEND-2 ...) with the condition that
398 the org file can be exported to TARGET-BACKEND via any one of
399 NATIVE-BACKEND-1, NATIVE-BACKEND-2 etc.
401 For example, an entry of the form \"(\"pdf\" \"odt\" \"xhtml\")\"
402 would mean that the org file could be exported to \"pdf\" format
403 by exporting natively either to \"xhtml\" or \"odt\" backends."
404 (let (all-backends)
405 (flet ((add (other native)
406 (let ((val (assoc-string other all-backends t)))
407 (if val (setcdr val (nconc (list native) (cdr val)))
408 (push (cons other (list native)) all-backends)))))
409 (loop for backend in org-lparse-native-backends
410 do (loop for other in
411 (mapcar #'car (org-lparse-get-other-backends backend))
412 do (add other backend))))
413 all-backends))
415 (defun org-lparse-backend-is-native-p (backend)
416 (member backend org-lparse-native-backends))
418 (defun org-lparse (target-backend native-backend arg
419 &optional hidden ext-plist
420 to-buffer body-only pub-dir)
421 "Export the outline to various formats.
422 If there is an active region, export only the region. The
423 outline is first exported to NATIVE-BACKEND and optionally
424 converted to TARGET-BACKEND. See `org-lparse-native-backends'
425 for list of known native backends. Each native backend can
426 specify a converter and list of target backends it exports to
427 using the CONVERT-PROCESS and OTHER-BACKENDS settings of it's get
428 method. See `org-xhtml-get' for an illustrative example.
430 ARG is a prefix argument that specifies how many levels of
431 outline should become headlines. The default is 3. Lower levels
432 will become bulleted lists.
434 HIDDEN is obsolete and does nothing.
436 EXT-PLIST is a property list that controls various aspects of
437 export. The settings here override org-mode's default settings
438 and but are inferior to file-local settings.
440 TO-BUFFER dumps the exported lines to a buffer or a string
441 instead of a file. If TO-BUFFER is the symbol `string' return the
442 exported lines as a string. If TO-BUFFER is non-nil, create a
443 buffer with that name and export to that buffer.
445 BODY-ONLY controls the presence of header and footer lines in
446 exported text. If BODY-ONLY is non-nil, don't produce the file
447 header and footer, simply return the content of <body>...</body>,
448 without even the body tags themselves.
450 PUB-DIR specifies the publishing directory."
451 (interactive
452 (let* ((input (if (featurep 'ido) 'ido-completing-read 'completing-read))
453 (all-backends (org-lparse-all-backends))
454 (target-backend
455 (and all-backends
456 (funcall input "Export to: " all-backends nil t nil)))
457 (native-backend
458 (let ((choices (if target-backend
459 (cdr (assoc target-backend all-backends))
460 (or org-lparse-native-backends
461 (error "No registered backends")))))
462 (funcall input "Use Native backend: " choices nil t nil))))
463 (list target-backend native-backend current-prefix-arg)))
464 (let* ((org-lparse-backend (intern native-backend))
465 (org-lparse-other-backend (and target-backend
466 (intern target-backend))))
467 (unless (org-lparse-backend-is-native-p native-backend)
468 (error "Don't know how to export natively to backend %s" native-backend))
469 (unless (or (not target-backend)
470 (equal target-backend native-backend)
471 (assoc target-backend (org-lparse-get-other-backends
472 native-backend)))
473 (error "Don't know how to export to backend %s %s" target-backend
474 (format "via %s" native-backend)))
475 (run-hooks 'org-export-first-hook)
476 (org-do-lparse arg hidden ext-plist to-buffer body-only pub-dir)))
478 (defcustom org-lparse-convert-processes
479 '(("BasicODConverter"
480 ("soffice" "-norestore" "-invisible" "-headless"
481 "\"macro:///BasicODConverter.Main.Convert(%I,%f,%O)\""))
482 ("unoconv"
483 ("unoconv" "-f" "%f" "-o" "%d" "%i")))
484 "Specify a list of document converters and their usage.
485 The converters in this list are offered as choices while
486 customizing `org-lparse-convert-process'.
488 This variable is an alist where each element is of the
489 form (CONVERTER-NAME (CONVERTER-PROGRAM ARG1 ARG2 ...)).
490 CONVERTER-NAME is name of the converter. CONVERTER-PROGRAM is
491 the name of the executable. ARG1, ARG2 etc are command line
492 options that are passed to CONVERTER-PROGRAM. Format specifiers
493 can be used in the ARGs and they are interpreted as below:
495 %i input file name in full
496 %I input file name as a URL
497 %f format of the output file
498 %o output file name in full
499 %O output file name as a URL
500 %d output dir in full
501 %D output dir as a URL."
502 :group 'org-lparse
503 :type
504 '(choice
505 (const :tag "None" nil)
506 (alist :tag "Converters"
507 :key-type (string :tag "Converter Name")
508 :value-type (group (cons (string :tag "Executable")
509 (repeat (string :tag "Command line args")))))))
510 (defcustom org-lparse-convert-process nil
511 "Command to convert from an Org exported format to other formats.
512 During customization, the list of choices are populated from
513 `org-lparse-convert-processes'. Refer afore-mentioned variable
514 for further information."
515 :group 'org-lparse
516 :type '(choice :convert-widget
517 (lambda (w)
518 (apply 'widget-convert (widget-type w)
519 (eval (car (widget-get w :args)))))
520 `((const :tag "None" nil)
521 ,@(mapcar (lambda (c)
522 `(const :tag ,(car c) ,(cadr c)))
523 org-lparse-convert-processes))))
525 (defcustom org-lparse-convert-capabilities
526 '(("Text"
527 ("odt" "ott" "doc" "rtf")
528 (("pdf" "pdf") ("odt" "odt") ("xhtml" "html") ("rtf" "rtf")
529 ("ott" "ott") ("doc" "doc") ("ooxml" "xml") ("html" "html")))
530 ("Web"
531 ("html" "xhtml") (("pdf" "pdf") ("odt" "txt") ("html" "html")))
532 ("Spreadsheet"
533 ("ods" "ots" "xls" "csv")
534 (("pdf" "pdf") ("ots" "ots") ("html" "html") ("csv" "csv")
535 ("ods" "ods") ("xls" "xls") ("xhtml" "xhtml") ("ooxml" "xml")))
536 ("Presentation"
537 ("odp" "otp" "ppt")
538 (("pdf" "pdf") ("swf" "swf") ("odp" "odp") ("xhtml" "xml")
539 ("otp" "otp") ("ppt" "ppt") ("odg" "odg") ("html" "html"))))
540 "Specify input and output formats of `org-lparse-convert-process'.
541 More correctly, specify the set of input and output formats that
542 the user is actually interested in.
544 This variable is an alist where each element is of the
545 form (DOCUMENT-CLASS INPUT-FMT-LIST OUTPUT-FMT-ALIST).
546 INPUT-FMT-LIST is a list of INPUT-FMTs. OUTPUT-FMT-ALIST is an
547 alist where each element is of the form (OUTPUT-FMT
548 OUTPUT-FILE-EXTENSION).
550 The variable is interpreted as follows:
551 `org-lparse-convert-process' can take any document that is in
552 INPUT-FMT-LIST and produce any document that is in the
553 OUTPUT-FMT-LIST. A document converted to OUTPUT-FMT will have
554 OUTPUT-FILE-EXTENSION as the file name extension. OUTPUT-FMT
555 serves dual purposes:
556 - It is used for populating completion candidates during
557 `org-lparse' and `org-lparse-convert' commands.
559 - It is used as the value of \"%f\" specifier in
560 `org-lparse-convert-process'.
562 DOCUMENT-CLASS is used to group a set of file formats in
563 INPUT-FMT-LIST in to a single class.
565 Note that this variable inherently captures how LibreOffice based
566 converters work. LibreOffice maps documents of various formats
567 to classes like Text, Web, Spreadsheet, Presentation etc and
568 allow document of a given class (irrespective of it's source
569 format) to be converted to any of the export formats associated
570 with that class.
572 See default setting of this variable for an typical
573 configuration."
574 :group 'org-lparse
575 :type
576 '(choice
577 (const :tag "None" nil)
578 (alist :key-type (string :tag "Document Class")
579 :value-type
580 (group (repeat :tag "Input formats" (string :tag "Input format"))
581 (alist :tag "Output formats"
582 :key-type (string :tag "Output format")
583 :value-type
584 (group (string :tag "Output file extension")))))))
586 (defcustom org-lparse-use-flashy-warning nil
587 "Control flashing of messages logged with `org-lparse-warn'.
588 When non-nil, messages are fontified with warning face and the
589 exporter lingers for a while to catch user's attention."
590 :type 'boolean
591 :group 'org-lparse)
593 (defun org-lparse-convert (&optional in-file out-fmt prefix-arg)
594 "Convert IN-FILE to format OUT-FMT using a command line converter.
595 IN-FILE is the file to be converted. If unspecified, it defaults
596 to variable `buffer-file-name'. OUT-FMT is the desired output
597 format. If the backend has registered a CONVERT-METHOD as part
598 of it's get function then that converter is used. Otherwise
599 `org-lparse-convert-process' is used. If PREFIX-ARG is non-nil
600 then the newly converted file is opened using `org-open-file'."
601 (interactive
602 (let* ((input (if (featurep 'ido) 'ido-completing-read 'completing-read))
603 (in-file (read-file-name "File to be converted: "
604 nil buffer-file-name t))
605 (in-fmt (file-name-extension in-file))
606 (out-fmt-choices (org-lparse-get-other-backends in-fmt))
607 (out-fmt
608 (or (and out-fmt-choices
609 (funcall input "Output format: "
610 out-fmt-choices nil nil nil))
611 (error
612 "No known converter or no known output formats for %s files"
613 in-fmt))))
614 (list in-file out-fmt current-prefix-arg)))
615 (require 'browse-url)
616 (let* ((in-file (expand-file-name (or in-file buffer-file-name)))
617 (dummy (or (file-readable-p in-file)
618 (error "Cannot read %s" in-file)))
619 (in-fmt (file-name-extension in-file))
620 (out-fmt (or out-fmt (error "Output format unspecified")))
621 (convert-process (org-lparse-get-converter in-fmt))
622 (program (car convert-process))
623 (dummy (and (or program (error "Converter not configured"))
624 (or (executable-find program)
625 (error "Cannot find converter %s" program))))
626 (out-fmt-alist
627 (or (assoc out-fmt (org-lparse-get-other-backends in-fmt))
628 (error "Cannot convert from %s to %s format" in-fmt out-fmt)))
629 (out-file (concat (file-name-sans-extension in-file) "."
630 (nth 1 out-fmt-alist)))
631 (out-dir (file-name-directory in-file))
632 (arglist (mapcar (lambda (arg)
633 (format-spec
634 arg `((?i . ,in-file)
635 (?I . ,(browse-url-file-url in-file))
636 (?f . ,out-fmt)
637 (?o . ,out-file)
638 (?O . ,(browse-url-file-url out-file))
639 (?d . ,out-dir)
640 (?D . ,(browse-url-file-url out-dir)))))
641 (cdr convert-process))))
642 (when (file-exists-p out-file)
643 (delete-file out-file))
645 (message "Executing %s %s" program (mapconcat 'identity arglist " "))
646 (apply 'call-process program nil nil nil arglist)
647 (cond
648 ((file-exists-p out-file)
649 (message "Exported to %s using %s" out-file program)
650 (when prefix-arg
651 (message "Opening %s..." out-file)
652 (org-open-file out-file))
653 out-file
654 ;; (set-buffer (find-file-noselect out-file))
657 (message "Export to %s failed" out-file)
658 nil))))
660 (defvar org-lparse-insert-tag-with-newlines 'both)
662 ;; Following variables are let-bound during `org-lparse'
663 (defvar org-lparse-dyn-first-heading-pos)
664 (defvar org-lparse-toc)
665 (defvar org-lparse-entity-control-callbacks-alist)
666 (defvar org-lparse-entity-format-callbacks-alist)
667 (defvar org-lparse-backend nil
668 "The native backend to which the document is currently exported.
669 This variable is let bound during `org-lparse'. Valid values are
670 one of the symbols corresponding to `org-lparse-native-backends'.
672 Compare this variable with `org-export-current-backend' which is
673 bound only during `org-export-preprocess-string' stage of the
674 export process.
676 See also `org-lparse-other-backend'.")
678 (defvar org-lparse-other-backend nil
679 "The target backend to which the document is currently exported.
680 This variable is let bound during `org-lparse'. This variable is
681 set to either `org-lparse-backend' or one of the symbols
682 corresponding to OTHER-BACKENDS specification of the
683 org-lparse-backend.
685 For example, if a document is exported to \"odt\" then both
686 org-lparse-backend and org-lparse-other-backend are bound to
687 'odt. On the other hand, if a document is exported to \"odt\"
688 and then converted to \"doc\" then org-lparse-backend is set to
689 'odt and org-lparse-other-backend is set to 'doc.")
691 (defvar org-lparse-body-only nil
692 "Bind this to BODY-ONLY arg of `org-lparse'.")
694 (defvar org-lparse-to-buffer nil
695 "Bind this to TO-BUFFER arg of `org-lparse'.")
697 (defun org-do-lparse (arg &optional hidden ext-plist
698 to-buffer body-only pub-dir)
699 "Export the outline to various formats.
700 See `org-lparse' for more information. This function is a
701 html-agnostic version of the `org-export-as-html' function in 7.5
702 version."
703 ;; Make sure we have a file name when we need it.
704 (when (and (not (or to-buffer body-only))
705 (not buffer-file-name))
706 (if (buffer-base-buffer)
707 (org-set-local 'buffer-file-name
708 (with-current-buffer (buffer-base-buffer)
709 buffer-file-name))
710 (error "Need a file name to be able to export")))
712 (org-lparse-warn
713 (format "Exporting to %s using org-lparse..."
714 (upcase (symbol-name
715 (or org-lparse-backend org-lparse-other-backend)))))
717 (setq-default org-todo-line-regexp org-todo-line-regexp)
718 (setq-default org-deadline-line-regexp org-deadline-line-regexp)
719 (setq-default org-done-keywords org-done-keywords)
720 (setq-default org-maybe-keyword-time-regexp org-maybe-keyword-time-regexp)
721 (let* (hfy-user-sheet-assoc ; let `htmlfontify' know that
722 ; we are interested in
723 ; collecting styles
724 org-lparse-encode-pending
725 org-lparse-par-open
727 ;; list related vars
728 (org-lparse-list-level 0) ; list level starts at 1. A
729 ; value of 0 implies we are
730 ; outside of any list
731 (org-lparse-list-item-count 0)
732 org-lparse-list-stack
734 ;; list-table related vars
735 org-lparse-list-table-p
736 org-lparse-list-table:table-cell-open
737 org-lparse-list-table:table-row
738 org-lparse-list-table:lines
740 org-lparse-outline-text-open
741 (org-lparse-latex-fragment-fallback ; currently used only by
742 ; odt exporter
743 (or (ignore-errors (org-lparse-get 'LATEX-FRAGMENT-FALLBACK))
744 (if (and (org-check-external-command "latex" "" t)
745 (org-check-external-command "dvipng" "" t))
746 'dvipng
747 'verbatim)))
748 (org-lparse-insert-tag-with-newlines 'both)
749 (org-lparse-to-buffer to-buffer)
750 (org-lparse-body-only body-only)
751 (org-lparse-entity-control-callbacks-alist
752 (org-lparse-get 'ENTITY-CONTROL))
753 (org-lparse-entity-format-callbacks-alist
754 (org-lparse-get 'ENTITY-FORMAT))
755 (opt-plist
756 (org-export-process-option-filters
757 (org-combine-plists (org-default-export-plist)
758 ext-plist
759 (org-infile-export-plist))))
760 (body-only (or body-only (plist-get opt-plist :body-only)))
761 valid org-lparse-dyn-first-heading-pos
762 (odd org-odd-levels-only)
763 (region-p (org-region-active-p))
764 (rbeg (and region-p (region-beginning)))
765 (rend (and region-p (region-end)))
766 (subtree-p
767 (if (plist-get opt-plist :ignore-subtree-p)
769 (when region-p
770 (save-excursion
771 (goto-char rbeg)
772 (and (org-at-heading-p)
773 (>= (org-end-of-subtree t t) rend))))))
774 (level-offset (if subtree-p
775 (save-excursion
776 (goto-char rbeg)
777 (+ (funcall outline-level)
778 (if org-odd-levels-only 1 0)))
780 (opt-plist (setq org-export-opt-plist
781 (if subtree-p
782 (org-export-add-subtree-options opt-plist rbeg)
783 opt-plist)))
784 ;; The following two are dynamically scoped into other
785 ;; routines below.
786 (org-current-export-dir
787 (or pub-dir (org-lparse-get 'EXPORT-DIR opt-plist)))
788 (org-current-export-file buffer-file-name)
789 (level 0) (line "") (origline "") txt todo
790 (umax nil)
791 (umax-toc nil)
792 (filename (if to-buffer nil
793 (expand-file-name
794 (concat
795 (file-name-sans-extension
796 (or (and subtree-p
797 (org-entry-get (region-beginning)
798 "EXPORT_FILE_NAME" t))
799 (file-name-nondirectory buffer-file-name)))
800 "." (org-lparse-get 'FILE-NAME-EXTENSION opt-plist))
801 (file-name-as-directory
802 (or pub-dir (org-lparse-get 'EXPORT-DIR opt-plist))))))
803 (current-dir (if buffer-file-name
804 (file-name-directory buffer-file-name)
805 default-directory))
806 (buffer (if to-buffer
807 (cond
808 ((eq to-buffer 'string)
809 (get-buffer-create (org-lparse-get 'EXPORT-BUFFER-NAME)))
810 (t (get-buffer-create to-buffer)))
811 (find-file-noselect
812 (or (let ((f (org-lparse-get 'INIT-METHOD)))
813 (and f (functionp f) (funcall f filename)))
814 filename))))
815 (org-levels-open (make-vector org-level-max nil))
816 (date (plist-get opt-plist :date))
817 (date (cond
818 ((and date (string-match "%" date))
819 (format-time-string date))
820 (date date)
821 (t (format-time-string "%Y-%m-%d %T %Z"))))
822 (dummy (setq opt-plist (plist-put opt-plist :effective-date date)))
823 (title (org-xml-encode-org-text-skip-links
824 (or (and subtree-p (org-export-get-title-from-subtree))
825 (plist-get opt-plist :title)
826 (and (not body-only)
827 (not
828 (plist-get opt-plist :skip-before-1st-heading))
829 (org-export-grab-title-from-buffer))
830 (and buffer-file-name
831 (file-name-sans-extension
832 (file-name-nondirectory buffer-file-name)))
833 "UNTITLED")))
834 (dummy (setq opt-plist (plist-put opt-plist :title title)))
835 (html-table-tag (plist-get opt-plist :html-table-tag))
836 (quote-re0 (concat "^[ \t]*" org-quote-string "\\>"))
837 (quote-re (concat "^\\(\\*+\\)\\([ \t]+" org-quote-string "\\>\\)"))
838 (org-lparse-dyn-current-environment nil)
839 ;; Get the language-dependent settings
840 (lang-words (or (assoc (plist-get opt-plist :language)
841 org-export-language-setup)
842 (assoc "en" org-export-language-setup)))
843 (dummy (setq opt-plist (plist-put opt-plist :lang-words lang-words)))
844 (head-count 0) cnt
845 (start 0)
846 (coding-system-for-write
847 (or (ignore-errors (org-lparse-get 'CODING-SYSTEM-FOR-WRITE))
848 (and (boundp 'buffer-file-coding-system)
849 buffer-file-coding-system)))
850 (save-buffer-coding-system
851 (or (ignore-errors (org-lparse-get 'CODING-SYSTEM-FOR-SAVE))
852 (and (boundp 'buffer-file-coding-system)
853 buffer-file-coding-system)))
854 (region
855 (buffer-substring
856 (if region-p (region-beginning) (point-min))
857 (if region-p (region-end) (point-max))))
858 (org-export-have-math nil)
859 (org-export-footnotes-seen nil)
860 (org-export-footnotes-data (org-footnote-all-labels 'with-defs))
861 (org-footnote-insert-pos-for-preprocessor 'point-min)
862 (org-lparse-opt-plist opt-plist)
863 (lines
864 (org-split-string
865 (org-export-preprocess-string
866 region
867 :emph-multiline t
868 :for-backend (if (equal org-lparse-backend 'xhtml) ; hack
869 'html
870 org-lparse-backend)
871 :skip-before-1st-heading
872 (plist-get opt-plist :skip-before-1st-heading)
873 :drawers (plist-get opt-plist :drawers)
874 :todo-keywords (plist-get opt-plist :todo-keywords)
875 :tasks (plist-get opt-plist :tasks)
876 :tags (plist-get opt-plist :tags)
877 :priority (plist-get opt-plist :priority)
878 :footnotes (plist-get opt-plist :footnotes)
879 :timestamps (plist-get opt-plist :timestamps)
880 :archived-trees
881 (plist-get opt-plist :archived-trees)
882 :select-tags (plist-get opt-plist :select-tags)
883 :exclude-tags (plist-get opt-plist :exclude-tags)
884 :add-text
885 (plist-get opt-plist :text)
886 :LaTeX-fragments
887 (plist-get opt-plist :LaTeX-fragments))
888 "[\r\n]"))
889 table-open
890 table-buffer table-orig-buffer
892 rpl path attr desc descp desc1 desc2 link
893 snumber fnc
894 footnotes footref-seen
895 org-lparse-output-buffer
896 org-lparse-footnote-definitions
897 org-lparse-footnote-number
898 ;; collection
899 org-lparse-collect-buffer
900 (org-lparse-collect-count 0) ; things will get haywire if
901 ; collections are chained. Use
902 ; this variable to assert this
903 ; pre-requisite
904 org-lparse-toc
905 href
908 (let ((inhibit-read-only t))
909 (org-unmodified
910 (remove-text-properties (point-min) (point-max)
911 '(:org-license-to-kill t))))
913 (message "Exporting...")
914 (org-init-section-numbers)
916 ;; Switch to the output buffer
917 (setq org-lparse-output-buffer buffer)
918 (set-buffer org-lparse-output-buffer)
919 (let ((inhibit-read-only t)) (erase-buffer))
920 (fundamental-mode)
921 (org-install-letbind)
923 (and (fboundp 'set-buffer-file-coding-system)
924 (set-buffer-file-coding-system coding-system-for-write))
926 (let ((case-fold-search nil)
927 (org-odd-levels-only odd))
928 ;; create local variables for all options, to make sure all called
929 ;; functions get the correct information
930 (mapc (lambda (x)
931 (set (make-local-variable (nth 2 x))
932 (plist-get opt-plist (car x))))
933 org-export-plist-vars)
934 (setq umax (if arg (prefix-numeric-value arg)
935 org-export-headline-levels))
936 (setq umax-toc (if (integerp org-export-with-toc)
937 (min org-export-with-toc umax)
938 umax))
940 (when (and org-export-with-toc (not body-only))
941 (setq lines (org-lparse-prepare-toc
942 lines level-offset opt-plist umax-toc)))
944 (unless body-only
945 (org-lparse-begin 'DOCUMENT-CONTENT opt-plist)
946 (org-lparse-begin 'DOCUMENT-BODY opt-plist))
948 (setq head-count 0)
949 (org-init-section-numbers)
951 (org-lparse-begin-paragraph)
953 (while (setq line (pop lines) origline line)
954 (catch 'nextline
955 (when (and (org-lparse-current-environment-p 'quote)
956 (string-match org-outline-regexp-bol line))
957 (org-lparse-end-environment 'quote))
959 (when (org-lparse-current-environment-p 'quote)
960 (org-lparse-insert 'LINE line)
961 (throw 'nextline nil))
963 ;; Fixed-width, verbatim lines (examples)
964 (when (and org-export-with-fixed-width
965 (string-match "^[ \t]*:\\(\\([ \t]\\|$\\)\\(.*\\)\\)" line))
966 (when (not (org-lparse-current-environment-p 'fixedwidth))
967 (org-lparse-begin-environment 'fixedwidth))
968 (org-lparse-insert 'LINE (match-string 3 line))
969 (when (or (not lines)
970 (not (string-match "^[ \t]*:\\(\\([ \t]\\|$\\)\\(.*\\)\\)"
971 (car lines))))
972 (org-lparse-end-environment 'fixedwidth))
973 (throw 'nextline nil))
975 ;; Notes: The baseline version of org-html.el (git commit
976 ;; 3d802e), while encoutering a *line-long* protected text,
977 ;; does one of the following two things based on the state
978 ;; of the export buffer.
980 ;; 1. If a paragraph element has just been opened and
981 ;; contains only whitespace as content, insert the
982 ;; protected text as part of the previous paragraph.
984 ;; 2. If the paragraph element has already been opened and
985 ;; contains some valid content insert the protected text
986 ;; as part of the current paragraph.
988 ;; I think --->
990 ;; Scenario 1 mentioned above kicks in when a block of
991 ;; protected text has to be inserted enbloc. For example,
992 ;; this happens, when inserting an source or example block
993 ;; or preformatted content enclosed in #+backend,
994 ;; #+begin_bakend ... #+end_backend)
996 ;; Scenario 2 mentioned above kicks in when the protected
997 ;; text is part of a running sentence. For example this
998 ;; happens in the case of an *multiline* LaTeX equation that
999 ;; needs to be inserted verbatim.
1001 ;; org-html.el in the master branch seems to do some
1002 ;; jugglery by moving paragraphs around. Inorder to make
1003 ;; these changes backend-agnostic introduce a new text
1004 ;; property org-native-text and impose the added semantics
1005 ;; that these protected blocks appear outside of a
1006 ;; conventional paragraph element.
1008 ;; Extra Note: Check whether org-example and org-native-text
1009 ;; are entirely equivalent.
1011 ;; Fixes bug reported by Christian Moe concerning verbatim
1012 ;; LaTeX fragments.
1013 ;; on git commit 533ba3f90250a1f25f494c390d639ea6274f235c
1014 ;; http://repo.or.cz/w/org-mode/org-jambu.git/shortlog/refs/heads/staging
1015 ;; See http://lists.gnu.org/archive/html/emacs-orgmode/2011-03/msg01379.html
1017 ;; Native Text
1018 (when (and (get-text-property 0 'org-native-text line)
1019 ;; Make sure it is the entire line that is protected
1020 (not (< (or (next-single-property-change
1021 0 'org-native-text line) 10000)
1022 (length line))))
1023 (let ((ind (get-text-property 0 'original-indentation line)))
1024 (org-lparse-begin-environment 'native)
1025 (org-lparse-insert 'LINE line)
1026 (while (and lines
1027 (or (= (length (car lines)) 0)
1028 (not ind)
1029 (equal ind (get-text-property
1030 0 'original-indentation (car lines))))
1031 (or (= (length (car lines)) 0)
1032 (get-text-property 0 'org-native-text (car lines))))
1033 (org-lparse-insert 'LINE (pop lines)))
1034 (org-lparse-end-environment 'native))
1035 (throw 'nextline nil))
1037 ;; Protected HTML
1038 (when (and (get-text-property 0 'org-protected line)
1039 ;; Make sure it is the entire line that is protected
1040 (not (< (or (next-single-property-change
1041 0 'org-protected line) 10000)
1042 (length line))))
1043 (let ((ind (get-text-property 0 'original-indentation line)))
1044 (org-lparse-insert 'LINE line)
1045 (while (and lines
1046 (or (= (length (car lines)) 0)
1047 (not ind)
1048 (equal ind (get-text-property
1049 0 'original-indentation (car lines))))
1050 (or (= (length (car lines)) 0)
1051 (get-text-property 0 'org-protected (car lines))))
1052 (org-lparse-insert 'LINE (pop lines))))
1053 (throw 'nextline nil))
1055 ;; Blockquotes, verse, and center
1056 (when (string-match "^ORG-\\(.+\\)-\\(START\\|END\\)$" line)
1057 (let* ((style (intern (downcase (match-string 1 line))))
1058 (f (cdr (assoc (match-string 2 line)
1059 '(("START" . org-lparse-begin-environment)
1060 ("END" . org-lparse-end-environment))))))
1061 (when (memq style '(blockquote verse center list-table))
1062 (funcall f style)
1063 (throw 'nextline nil))))
1065 (run-hooks 'org-export-html-after-blockquotes-hook)
1066 (when (org-lparse-current-environment-p 'verse)
1067 (let ((i (org-get-string-indentation line)))
1068 (if (> i 0)
1069 (setq line (concat
1070 (let ((org-lparse-encode-pending t))
1071 (org-lparse-format 'SPACES (* 2 i)))
1072 " " (org-trim line))))
1073 (unless (string-match "\\\\\\\\[ \t]*$" line)
1074 (setq line (concat line "\\\\")))))
1076 ;; make targets to anchors
1077 (setq start 0)
1078 (while (string-match
1079 "<<<?\\([^<>]*\\)>>>?\\((INVISIBLE)\\)?[ \t]*\n?" line start)
1080 (cond
1081 ((get-text-property (match-beginning 1) 'org-protected line)
1082 (setq start (match-end 1)))
1083 ((match-end 2)
1084 (setq line (replace-match
1085 (let ((org-lparse-encode-pending t))
1086 (org-lparse-format
1087 'ANCHOR "" (org-solidify-link-text
1088 (match-string 1 line))))
1089 t t line)))
1090 ((and org-export-with-toc (equal (string-to-char line) ?*))
1091 ;; FIXME: NOT DEPENDENT on TOC?????????????????????
1092 (setq line (replace-match
1093 (let ((org-lparse-encode-pending t))
1094 (org-lparse-format
1095 'FONTIFY (match-string 1 line) "target"))
1096 ;; (concat "@<i>" (match-string 1 line) "@</i> ")
1097 t t line)))
1099 (setq line (replace-match
1100 (concat
1101 (let ((org-lparse-encode-pending t))
1102 (org-lparse-format
1103 'ANCHOR (match-string 1 line)
1104 (org-solidify-link-text (match-string 1 line))
1105 "target")) " ")
1106 t t line)))))
1108 (let ((org-lparse-encode-pending t))
1109 (setq line (org-lparse-handle-time-stamps line)))
1111 ;; replace "&" by "&amp;", "<" and ">" by "&lt;" and "&gt;"
1112 ;; handle @<..> HTML tags (replace "@&gt;..&lt;" by "<..>")
1113 ;; Also handle sub_superscripts and checkboxes
1114 (or (string-match org-table-hline-regexp line)
1115 (string-match "^[ \t]*\\([+]-\\||[ ]\\)[-+ |]*[+|][ \t]*$" line)
1116 (setq line (org-xml-encode-org-text-skip-links line)))
1118 (setq line (org-lparse-format-org-link line opt-plist))
1120 ;; TODO items
1121 (if (and (string-match org-todo-line-regexp line)
1122 (match-beginning 2))
1123 (setq line (concat
1124 (substring line 0 (match-beginning 2))
1125 (org-lparse-format 'TODO (match-string 2 line))
1126 (substring line (match-end 2)))))
1128 ;; Does this contain a reference to a footnote?
1129 (when org-export-with-footnotes
1130 (setq start 0)
1131 (while (string-match "\\([^* \t].*?\\)[ \t]*\\[\\([0-9]+\\)\\]" line start)
1132 ;; Discard protected matches not clearly identified as
1133 ;; footnote markers.
1134 (if (or (get-text-property (match-beginning 2) 'org-protected line)
1135 (not (get-text-property (match-beginning 2) 'org-footnote line)))
1136 (setq start (match-end 2))
1137 (let ((n (match-string 2 line)) refcnt a)
1138 (if (setq a (assoc n footref-seen))
1139 (progn
1140 (setcdr a (1+ (cdr a)))
1141 (setq refcnt (cdr a)))
1142 (setq refcnt 1)
1143 (push (cons n 1) footref-seen))
1144 (setq line
1145 (replace-match
1146 (concat
1147 (or (match-string 1 line) "")
1148 (org-lparse-format
1149 'FOOTNOTE-REFERENCE
1150 n (cdr (assoc n org-lparse-footnote-definitions))
1151 refcnt)
1152 ;; If another footnote is following the
1153 ;; current one, add a separator.
1154 (if (save-match-data
1155 (string-match "\\`\\[[0-9]+\\]"
1156 (substring line (match-end 0))))
1157 (ignore-errors
1158 (org-lparse-get 'FOOTNOTE-SEPARATOR))
1159 ""))
1160 t t line))))))
1162 (cond
1163 ((string-match "^\\(\\*+\\)[ \t]+\\(.*\\)" line)
1164 ;; This is a headline
1165 (setq level (org-tr-level (- (match-end 1) (match-beginning 1)
1166 level-offset))
1167 txt (match-string 2 line))
1168 (if (string-match quote-re0 txt)
1169 (setq txt (replace-match "" t t txt)))
1170 (if (<= level (max umax umax-toc))
1171 (setq head-count (+ head-count 1)))
1172 (unless org-lparse-dyn-first-heading-pos
1173 (setq org-lparse-dyn-first-heading-pos (point)))
1174 (org-lparse-begin-level level txt umax head-count)
1176 ;; QUOTES
1177 (when (string-match quote-re line)
1178 (org-lparse-begin-environment 'quote)))
1180 ((and org-export-with-tables
1181 (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)" line))
1182 (when (not table-open)
1183 ;; New table starts
1184 (setq table-open t table-buffer nil table-orig-buffer nil))
1186 ;; Accumulate lines
1187 (setq table-buffer (cons line table-buffer)
1188 table-orig-buffer (cons origline table-orig-buffer))
1189 (when (or (not lines)
1190 (not (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)"
1191 (car lines))))
1192 (setq table-open nil
1193 table-buffer (nreverse table-buffer)
1194 table-orig-buffer (nreverse table-orig-buffer))
1195 (org-lparse-end-paragraph)
1196 (org-lparse-insert 'TABLE table-buffer table-orig-buffer)))
1198 ;; Normal lines
1201 ;; This line either is list item or end a list.
1202 (when (get-text-property 0 'list-item line)
1203 (setq line (org-lparse-export-list-line
1204 line
1205 (get-text-property 0 'list-item line)
1206 (get-text-property 0 'list-struct line)
1207 (get-text-property 0 'list-prevs line))))
1209 ;; Horizontal line
1210 (when (string-match "^[ \t]*-\\{5,\\}[ \t]*$" line)
1211 (with-org-lparse-preserve-paragraph-state
1212 (org-lparse-insert 'HORIZONTAL-LINE))
1213 (throw 'nextline nil))
1215 ;; Empty lines start a new paragraph. If hand-formatted lists
1216 ;; are not fully interpreted, lines starting with "-", "+", "*"
1217 ;; also start a new paragraph.
1218 (when (string-match "^ [-+*]-\\|^[ \t]*$" line)
1219 (when org-lparse-footnote-number
1220 (org-lparse-end-footnote-definition org-lparse-footnote-number)
1221 (setq org-lparse-footnote-number nil))
1222 (org-lparse-begin-paragraph))
1224 ;; Is this the start of a footnote?
1225 (when org-export-with-footnotes
1226 (when (and (boundp 'footnote-section-tag-regexp)
1227 (string-match (concat "^" footnote-section-tag-regexp)
1228 line))
1229 ;; ignore this line
1230 (throw 'nextline nil))
1231 (when (string-match "^[ \t]*\\[\\([0-9]+\\)\\]" line)
1232 (org-lparse-end-paragraph)
1233 (setq org-lparse-footnote-number (match-string 1 line))
1234 (setq line (replace-match "" t t line))
1235 (org-lparse-begin-footnote-definition org-lparse-footnote-number)))
1236 ;; Check if the line break needs to be conserved
1237 (cond
1238 ((string-match "\\\\\\\\[ \t]*$" line)
1239 (setq line (replace-match
1240 (org-lparse-format 'LINE-BREAK)
1241 t t line)))
1242 (org-export-preserve-breaks
1243 (setq line (concat line (org-lparse-format 'LINE-BREAK)))))
1245 ;; Check if a paragraph should be started
1246 (let ((start 0))
1247 (while (and org-lparse-par-open
1248 (string-match "\\\\par\\>" line start))
1249 (error "FIXME")
1250 ;; Leave a space in the </p> so that the footnote matcher
1251 ;; does not see this.
1252 (if (not (get-text-property (match-beginning 0)
1253 'org-protected line))
1254 (setq line (replace-match "</p ><p >" t t line)))
1255 (setq start (match-end 0))))
1257 (org-lparse-insert 'LINE line)))))
1259 ;; Properly close all local lists and other lists
1260 (when (org-lparse-current-environment-p 'quote)
1261 (org-lparse-end-environment 'quote))
1263 (org-lparse-end-level 1 umax)
1265 ;; the </div> to close the last text-... div.
1266 (when (and (> umax 0) org-lparse-dyn-first-heading-pos)
1267 (org-lparse-end-outline-text-or-outline))
1269 (org-lparse-end 'DOCUMENT-BODY opt-plist)
1270 (unless body-only
1271 (org-lparse-end 'DOCUMENT-CONTENT))
1273 (unless (plist-get opt-plist :buffer-will-be-killed)
1274 (set-auto-mode t))
1276 (org-lparse-end 'EXPORT)
1278 ;; kill collection buffer
1279 (when org-lparse-collect-buffer
1280 (kill-buffer org-lparse-collect-buffer))
1282 (goto-char (point-min))
1283 (or (org-export-push-to-kill-ring
1284 (upcase (symbol-name org-lparse-backend)))
1285 (message "Exporting... done"))
1287 (cond
1288 ((not to-buffer)
1289 (let ((f (org-lparse-get 'SAVE-METHOD)))
1290 (or (and f (functionp f) (funcall f filename opt-plist))
1291 (save-buffer)))
1292 (or (when (and (boundp 'org-lparse-other-backend)
1293 org-lparse-other-backend
1294 (not (equal org-lparse-backend org-lparse-other-backend)))
1295 (let ((org-lparse-convert-process
1296 (org-lparse-get-converter org-lparse-backend)))
1297 (when org-lparse-convert-process
1298 (org-lparse-convert buffer-file-name
1299 (symbol-name org-lparse-other-backend)))))
1300 (current-buffer)))
1301 ((eq to-buffer 'string)
1302 (prog1 (buffer-substring (point-min) (point-max))
1303 (kill-buffer (current-buffer))))
1304 (t (current-buffer))))))
1306 (defun org-lparse-format-table (lines olines)
1307 "Retuns backend-specific code for org-type and table-type tables."
1308 (if (stringp lines)
1309 (setq lines (org-split-string lines "\n")))
1310 (if (string-match "^[ \t]*|" (car lines))
1311 ;; A normal org table
1312 (org-lparse-format-org-table lines nil)
1313 ;; Table made by table.el
1314 (or (org-lparse-format-table-table-using-table-generate-source
1315 ;; FIXME: Need to take care of this during merge
1316 (if (eq org-lparse-backend 'xhtml) 'html org-lparse-backend)
1317 olines
1318 (not org-export-prefer-native-exporter-for-tables))
1319 ;; We are here only when table.el table has NO col or row
1320 ;; spanning and the user prefers using org's own converter for
1321 ;; exporting of such simple table.el tables.
1322 (org-lparse-format-table-table lines))))
1324 (defun org-lparse-table-get-colalign-info (lines)
1325 (let ((forced-aligns (org-find-text-property-in-string
1326 'org-forced-aligns (car lines))))
1327 (when (and forced-aligns org-table-clean-did-remove-column)
1328 (setq forced-aligns
1329 (mapcar (lambda (x) (cons (1- (car x)) (cdr x))) forced-aligns)))
1331 forced-aligns))
1333 (defvar org-lparse-table-style)
1334 (defvar org-lparse-table-ncols)
1335 (defvar org-lparse-table-rownum)
1336 (defvar org-lparse-table-is-styled)
1337 (defvar org-lparse-table-begin-marker)
1338 (defvar org-lparse-table-num-numeric-items-per-column)
1339 (defvar org-lparse-table-colalign-info)
1340 (defvar org-lparse-table-colalign-vector)
1342 ;; Following variables are defined in org-table.el
1343 (defvar org-table-number-fraction)
1344 (defvar org-table-number-regexp)
1345 (defun org-lparse-org-table-to-list-table (lines &optional splice)
1346 "Convert org-table to list-table.
1347 LINES is a list of the form (ROW1 ROW2 ROW3 ...) where each
1348 element is a `string' representing a single row of org-table.
1349 Thus each ROW has vertical separators \"|\" separating the table
1350 fields. A ROW could also be a row-group separator of the form
1351 \"|---...|\". Return a list of the form (ROW1 ROW2 ROW3
1352 ...). ROW could either be symbol `:hrule' or a list of the
1353 form (FIELD1 FIELD2 FIELD3 ...) as appropriate."
1354 (let (line lines-1)
1355 (cond
1356 (splice
1357 (while (setq line (pop lines))
1358 (unless (string-match "^[ \t]*|-" line)
1359 (push (org-split-string line "[ \t]*|[ \t]*") lines-1))))
1361 (while (setq line (pop lines))
1362 (cond
1363 ((string-match "^[ \t]*|-" line)
1364 (when lines
1365 (push :hrule lines-1)))
1367 (push (org-split-string line "[ \t]*|[ \t]*") lines-1))))))
1368 (nreverse lines-1)))
1370 (defun org-lparse-do-format-org-table (lines &optional splice)
1371 "Format a org-type table into backend-specific code.
1372 LINES is a list of lines. Optional argument SPLICE means, do not
1373 insert header and surrounding <table> tags, just format the lines.
1374 Optional argument NO-CSS means use XHTML attributes instead of CSS
1375 for formatting. This is required for the DocBook exporter."
1376 (require 'org-table)
1377 ;; Get rid of hlines at beginning and end
1378 (if (string-match "^[ \t]*|-" (car lines)) (setq lines (cdr lines)))
1379 (setq lines (nreverse lines))
1380 (if (string-match "^[ \t]*|-" (car lines)) (setq lines (cdr lines)))
1381 (setq lines (nreverse lines))
1382 (when org-export-table-remove-special-lines
1383 ;; Check if the table has a marking column. If yes remove the
1384 ;; column and the special lines
1385 (setq lines (org-table-clean-before-export lines)))
1386 (let* ((caption (org-find-text-property-in-string 'org-caption (car lines)))
1387 (caption (and caption (org-xml-encode-org-text caption)))
1388 (label (org-find-text-property-in-string 'org-label (car lines)))
1389 (org-lparse-table-colalign-info (org-lparse-table-get-colalign-info lines))
1390 (attributes (org-find-text-property-in-string 'org-attributes
1391 (car lines)))
1392 (head (and org-export-highlight-first-table-line
1393 (delq nil (mapcar
1394 (lambda (x) (string-match "^[ \t]*|-" x))
1395 (cdr lines))))))
1396 (setq lines (org-lparse-org-table-to-list-table lines splice))
1397 (org-lparse-do-format-list-table
1398 lines splice caption label attributes head org-lparse-table-colalign-info)))
1400 (defun org-lparse-do-format-list-table (lines &optional splice
1401 caption label attributes head
1402 org-lparse-table-colalign-info)
1403 (or (featurep 'org-table) ; required for
1404 (require 'org-table)) ; `org-table-number-regexp'
1405 (let* ((org-lparse-table-rownum -1) org-lparse-table-ncols i (cnt 0)
1406 tbopen fields line
1407 org-lparse-table-cur-rowgrp-is-hdr
1408 org-lparse-table-rowgrp-open
1409 org-lparse-table-num-numeric-items-per-column
1410 org-lparse-table-colalign-vector n
1411 org-lparse-table-rowgrp-info
1412 org-lparse-table-begin-marker
1413 (org-lparse-table-style 'org-table)
1414 org-lparse-table-is-styled)
1415 (cond
1416 (splice
1417 (setq org-lparse-table-is-styled nil)
1418 (while (setq line (pop lines))
1419 (insert (org-lparse-format-table-row line) "\n")))
1421 (setq org-lparse-table-is-styled t)
1422 (org-lparse-begin 'TABLE caption label attributes)
1423 (setq org-lparse-table-begin-marker (point))
1424 (org-lparse-begin-table-rowgroup head)
1425 (while (setq line (pop lines))
1426 (cond
1427 ((equal line :hrule)
1428 (org-lparse-begin-table-rowgroup))
1430 (insert (org-lparse-format-table-row line) "\n"))))
1431 (org-lparse-end 'TABLE-ROWGROUP)
1432 (org-lparse-end-table)))))
1434 (defun org-lparse-format-org-table (lines &optional splice)
1435 (with-temp-buffer
1436 (org-lparse-do-format-org-table lines splice)
1437 (buffer-substring-no-properties (point-min) (point-max))))
1439 (defun org-lparse-format-list-table (lines &optional splice)
1440 (with-temp-buffer
1441 (org-lparse-do-format-list-table lines splice)
1442 (buffer-substring-no-properties (point-min) (point-max))))
1444 (defun org-lparse-do-format-table-table (lines)
1445 "Format a table generated by table.el into backend-specific code.
1446 This conversion does *not* use `table-generate-source' from table.el.
1447 This has the advantage that Org-mode's HTML conversions can be used.
1448 But it has the disadvantage, that no cell- or row-spanning is allowed."
1449 (let (line field-buffer
1450 (org-lparse-table-cur-rowgrp-is-hdr
1451 org-export-highlight-first-table-line)
1452 (caption nil)
1453 (attributes nil)
1454 (label nil)
1455 (org-lparse-table-style 'table-table)
1456 (org-lparse-table-is-styled nil)
1457 fields org-lparse-table-ncols i (org-lparse-table-rownum -1)
1458 (empty (org-lparse-format 'SPACES 1)))
1459 (org-lparse-begin 'TABLE caption label attributes)
1460 (while (setq line (pop lines))
1461 (cond
1462 ((string-match "^[ \t]*\\+-" line)
1463 (when field-buffer
1464 (let ((org-export-table-row-tags '("<tr>" . "</tr>"))
1465 ;; (org-export-html-table-use-header-tags-for-first-column nil)
1467 (insert (org-lparse-format-table-row field-buffer empty)))
1468 (setq org-lparse-table-cur-rowgrp-is-hdr nil)
1469 (setq field-buffer nil)))
1471 ;; Break the line into fields and store the fields
1472 (setq fields (org-split-string line "[ \t]*|[ \t]*"))
1473 (if field-buffer
1474 (setq field-buffer (mapcar
1475 (lambda (x)
1476 (concat x (org-lparse-format 'LINE-BREAK)
1477 (pop fields)))
1478 field-buffer))
1479 (setq field-buffer fields)))))
1480 (org-lparse-end-table)))
1482 (defun org-lparse-format-table-table (lines)
1483 (with-temp-buffer
1484 (org-lparse-do-format-table-table lines)
1485 (buffer-substring-no-properties (point-min) (point-max))))
1487 (defvar table-source-languages) ; defined in table.el
1488 (defun org-lparse-format-table-table-using-table-generate-source (backend
1489 lines
1490 &optional
1491 spanned-only)
1492 "Format a table into BACKEND, using `table-generate-source' from table.el.
1493 Use SPANNED-ONLY to suppress exporting of simple table.el tables.
1495 When SPANNED-ONLY is nil, all table.el tables are exported. When
1496 SPANNED-ONLY is non-nil, only tables with either row or column
1497 spans are exported.
1499 This routine returns the generated source or nil as appropriate.
1501 Refer docstring of `org-export-prefer-native-exporter-for-tables'
1502 for further information."
1503 (require 'table)
1504 (with-current-buffer (get-buffer-create " org-tmp1 ")
1505 (erase-buffer)
1506 (insert (mapconcat 'identity lines "\n"))
1507 (goto-char (point-min))
1508 (if (not (re-search-forward "|[^+]" nil t))
1509 (error "Error processing table"))
1510 (table-recognize-table)
1511 (when (or (not spanned-only)
1512 (let* ((dim (table-query-dimension))
1513 (c (nth 4 dim)) (r (nth 5 dim)) (cells (nth 6 dim)))
1514 (not (= (* c r) cells))))
1515 (with-current-buffer (get-buffer-create " org-tmp2 ") (erase-buffer))
1516 (cond
1517 ((member backend table-source-languages)
1518 (table-generate-source backend " org-tmp2 ")
1519 (set-buffer " org-tmp2 ")
1520 (buffer-substring (point-min) (point-max)))
1522 ;; table.el doesn't support the given backend. Currently this
1523 ;; happens in case of odt export. Strip the table from the
1524 ;; generated document. A better alternative would be to embed
1525 ;; the table as ascii text in the output document.
1526 (org-lparse-warn
1527 (concat
1528 "Found table.el-type table in the source org file. "
1529 (format "table.el doesn't support %s backend. "
1530 (upcase (symbol-name backend)))
1531 "Skipping ahead ..."))
1532 "")))))
1534 (defun org-lparse-handle-time-stamps (s)
1535 "Format time stamps in string S, or remove them."
1536 (catch 'exit
1537 (let (r b)
1538 (while (string-match org-maybe-keyword-time-regexp s)
1539 (or b (setq b (substring s 0 (match-beginning 0))))
1540 (setq r (concat
1541 r (substring s 0 (match-beginning 0)) " "
1542 (org-lparse-format
1543 'FONTIFY
1544 (concat
1545 (if (match-end 1)
1546 (org-lparse-format
1547 'FONTIFY
1548 (match-string 1 s) "timestamp-kwd"))
1550 (org-lparse-format
1551 'FONTIFY
1552 (substring (org-translate-time (match-string 3 s)) 1 -1)
1553 "timestamp"))
1554 "timestamp-wrapper"))
1555 s (substring s (match-end 0))))
1556 ;; Line break if line started and ended with time stamp stuff
1557 (if (not r)
1559 (setq r (concat r s))
1560 (unless (string-match "\\S-" (concat b s))
1561 (setq r (concat r (org-lparse-format 'LINE-BREAK))))
1562 r))))
1564 (defun org-xml-encode-plain-text (s)
1565 "Convert plain text characters to HTML equivalent.
1566 Possible conversions are set in `org-export-html-protect-char-alist'."
1567 (let ((cl (org-lparse-get 'PLAIN-TEXT-MAP)) c)
1568 (while (setq c (pop cl))
1569 (let ((start 0))
1570 (while (string-match (car c) s start)
1571 (setq s (replace-match (cdr c) t t s)
1572 start (1+ (match-beginning 0))))))
1575 (defun org-xml-encode-org-text-skip-links (string)
1576 "Prepare STRING for HTML export. Apply all active conversions.
1577 If there are links in the string, don't modify these."
1578 (let* ((re (concat org-bracket-link-regexp "\\|"
1579 (org-re "[ \t]+\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")))
1580 m s l res)
1581 (while (setq m (string-match re string))
1582 (setq s (substring string 0 m)
1583 l (match-string 0 string)
1584 string (substring string (match-end 0)))
1585 (push (org-xml-encode-org-text s) res)
1586 (push l res))
1587 (push (org-xml-encode-org-text string) res)
1588 (apply 'concat (nreverse res))))
1590 (defun org-xml-encode-org-text (s)
1591 "Apply all active conversions to translate special ASCII to HTML."
1592 (setq s (org-xml-encode-plain-text s))
1593 (if org-export-html-expand
1594 (while (string-match "@&lt;\\([^&]*\\)&gt;" s)
1595 (setq s (replace-match "<\\1>" t nil s))))
1596 (if org-export-with-emphasize
1597 (setq s (org-lparse-apply-char-styles s)))
1598 (if org-export-with-special-strings
1599 (setq s (org-lparse-convert-special-strings s)))
1600 (if org-export-with-sub-superscripts
1601 (setq s (org-lparse-apply-sub-superscript-styles s)))
1602 (if org-export-with-TeX-macros
1603 (let ((start 0) wd rep)
1604 (while (setq start (string-match "\\\\\\([a-zA-Z]+[0-9]*\\)\\({}\\)?"
1605 s start))
1606 (if (get-text-property (match-beginning 0) 'org-protected s)
1607 (setq start (match-end 0))
1608 (setq wd (match-string 1 s))
1609 (if (setq rep (org-lparse-format 'ORG-ENTITY wd))
1610 (setq s (replace-match rep t t s))
1611 (setq start (+ start (length wd))))))))
1614 (defun org-lparse-convert-special-strings (string)
1615 "Convert special characters in STRING to HTML."
1616 (let ((all (org-lparse-get 'SPECIAL-STRING-REGEXPS))
1617 e a re rpl start)
1618 (while (setq a (pop all))
1619 (setq re (car a) rpl (cdr a) start 0)
1620 (while (string-match re string start)
1621 (if (get-text-property (match-beginning 0) 'org-protected string)
1622 (setq start (match-end 0))
1623 (setq string (replace-match rpl t nil string)))))
1624 string))
1626 (defun org-lparse-apply-sub-superscript-styles (string)
1627 "Apply subscript and superscript styles to STRING.
1628 Use `org-export-with-sub-superscripts' to control application of
1629 sub and superscript styles."
1630 (let (key c (s 0) (requireb (eq org-export-with-sub-superscripts '{})))
1631 (while (string-match org-match-substring-regexp string s)
1632 (cond
1633 ((and requireb (match-end 8)) (setq s (match-end 2)))
1634 ((get-text-property (match-beginning 2) 'org-protected string)
1635 (setq s (match-end 2)))
1637 (setq s (match-end 1)
1638 key (if (string= (match-string 2 string) "_")
1639 'subscript 'superscript)
1640 c (or (match-string 8 string)
1641 (match-string 6 string)
1642 (match-string 5 string))
1643 string (replace-match
1644 (concat (match-string 1 string)
1645 (org-lparse-format 'FONTIFY c key))
1646 t t string)))))
1647 (while (string-match "\\\\\\([_^]\\)" string)
1648 (setq string (replace-match (match-string 1 string) t t string)))
1649 string))
1651 (defvar org-lparse-char-styles
1652 `(("*" bold)
1653 ("/" emphasis)
1654 ("_" underline)
1655 ("=" code)
1656 ("~" verbatim)
1657 ("+" strike))
1658 "Map Org emphasis markers to char styles.
1659 This is an alist where each element is of the
1660 form (ORG-EMPHASIS-CHAR . CHAR-STYLE).")
1662 (defun org-lparse-apply-char-styles (string)
1663 "Apply char styles to STRING.
1664 The variable `org-lparse-char-styles' controls how the Org
1665 emphasis markers are interpreted."
1666 (let ((s 0) rpl)
1667 (while (string-match org-emph-re string s)
1668 (if (not (equal
1669 (substring string (match-beginning 3) (1+ (match-beginning 3)))
1670 (substring string (match-beginning 4) (1+ (match-beginning 4)))))
1671 (setq s (match-beginning 0)
1673 (concat
1674 (match-string 1 string)
1675 (org-lparse-format
1676 'FONTIFY (match-string 4 string)
1677 (nth 1 (assoc (match-string 3 string)
1678 org-lparse-char-styles)))
1679 (match-string 5 string))
1680 string (replace-match rpl t t string)
1681 s (+ s (- (length rpl) 2)))
1682 (setq s (1+ s))))
1683 string))
1685 (defun org-lparse-export-list-line (line pos struct prevs)
1686 "Insert list syntax in export buffer. Return LINE, maybe modified.
1688 POS is the item position or line position the line had before
1689 modifications to buffer. STRUCT is the list structure. PREVS is
1690 the alist of previous items."
1691 (let* ((get-type
1692 (function
1693 ;; Translate type of list containing POS to "d", "o" or
1694 ;; "u".
1695 (lambda (pos struct prevs)
1696 (let ((type (org-list-get-list-type pos struct prevs)))
1697 (cond
1698 ((eq 'ordered type) "o")
1699 ((eq 'descriptive type) "d")
1700 (t "u"))))))
1701 (get-closings
1702 (function
1703 ;; Return list of all items and sublists ending at POS, in
1704 ;; reverse order.
1705 (lambda (pos)
1706 (let (out)
1707 (catch 'exit
1708 (mapc (lambda (e)
1709 (let ((end (nth 6 e))
1710 (item (car e)))
1711 (cond
1712 ((= end pos) (push item out))
1713 ((>= item pos) (throw 'exit nil)))))
1714 struct))
1715 out)))))
1716 ;; First close any previous item, or list, ending at POS.
1717 (mapc (lambda (e)
1718 (let* ((lastp (= (org-list-get-last-item e struct prevs) e))
1719 (first-item (org-list-get-list-begin e struct prevs))
1720 (type (funcall get-type first-item struct prevs)))
1721 (org-lparse-end-paragraph)
1722 ;; Ending for every item
1723 (org-lparse-end-list-item-1 type)
1724 ;; We're ending last item of the list: end list.
1725 (when lastp
1726 (org-lparse-end-list type)
1727 (org-lparse-begin-paragraph))))
1728 (funcall get-closings pos))
1729 (cond
1730 ;; At an item: insert appropriate tags in export buffer.
1731 ((assq pos struct)
1732 (string-match
1733 (concat "[ \t]*\\(\\S-+[ \t]*\\)"
1734 "\\(?:\\[@\\(?:start:\\)?\\([0-9]+\\|[A-Za-z]\\)\\][ \t]*\\)?"
1735 "\\(?:\\(\\[[ X-]\\]\\)[ \t]+\\)?"
1736 "\\(?:\\(.*\\)[ \t]+::\\(?:[ \t]+\\|$\\)\\)?"
1737 "\\(.*\\)") line)
1738 (let* ((checkbox (match-string 3 line))
1739 (desc-tag (or (match-string 4 line) "???"))
1740 (body (or (match-string 5 line) ""))
1741 (list-beg (org-list-get-list-begin pos struct prevs))
1742 (firstp (= list-beg pos))
1743 ;; Always refer to first item to determine list type, in
1744 ;; case list is ill-formed.
1745 (type (funcall get-type list-beg struct prevs))
1746 (counter (let ((count-tmp (org-list-get-counter pos struct)))
1747 (cond
1748 ((not count-tmp) nil)
1749 ((string-match "[A-Za-z]" count-tmp)
1750 (- (string-to-char (upcase count-tmp)) 64))
1751 ((string-match "[0-9]+" count-tmp)
1752 count-tmp)))))
1753 (when firstp
1754 (org-lparse-end-paragraph)
1755 (org-lparse-begin-list type))
1757 (let ((arg (cond ((equal type "d") desc-tag)
1758 ((equal type "o") counter))))
1759 (org-lparse-begin-list-item type arg))
1761 ;; If line had a checkbox, some additional modification is required.
1762 (when checkbox
1763 (setq body
1764 (concat
1765 (org-lparse-format
1766 'FONTIFY (concat
1768 (cond
1769 ((string-match "X" checkbox) "X")
1770 ((string-match " " checkbox)
1771 (org-lparse-format 'SPACES 1))
1772 (t "-"))
1773 "]")
1774 'code)
1776 body)))
1777 ;; Return modified line
1778 body))
1779 ;; At a list ender: go to next line (side-effects only).
1780 ((equal "ORG-LIST-END-MARKER" line) (throw 'nextline nil))
1781 ;; Not at an item: return line unchanged (side-effects only).
1782 (t line))))
1784 (defun org-lparse-bind-local-variables (opt-plist)
1785 (mapc (lambda (x)
1786 (set (make-local-variable (nth 2 x))
1787 (plist-get opt-plist (car x))))
1788 org-export-plist-vars))
1790 (defvar org-lparse-table-rowgrp-open)
1791 (defvar org-lparse-table-cur-rowgrp-is-hdr)
1792 (defvar org-lparse-footnote-number)
1793 (defvar org-lparse-footnote-definitions)
1794 (defvar org-lparse-output-buffer nil
1795 "Buffer to which `org-do-lparse' writes to.
1796 This buffer contains the contents of the to-be-created exported
1797 document.")
1799 (defcustom org-lparse-debug nil
1800 "Enable or Disable logging of `org-lparse' callbacks.
1801 The parameters passed to the backend-registered ENTITY-CONTROL
1802 and ENTITY-FORMAT callbacks are logged as comment strings in the
1803 exported buffer. (org-lparse-format 'COMMENT fmt args) is used
1804 for logging. Customize this variable only if you are an expert
1805 user. Valid values of this variable are:
1806 nil : Disable logging
1807 control : Log all invocations of `org-lparse-begin' and
1808 `org-lparse-end' callbacks.
1809 format : Log invocations of `org-lparse-format' callbacks.
1810 t : Log all invocations of `org-lparse-begin', `org-lparse-end'
1811 and `org-lparse-format' callbacks,"
1812 :group 'org-lparse
1813 :type '(choice
1814 (const :tag "Disable" nil)
1815 (const :tag "Format callbacks" format)
1816 (const :tag "Control callbacks" control)
1817 (const :tag "Format and Control callbacks" t)))
1819 (defun org-lparse-begin (entity &rest args)
1820 "Begin ENTITY in current buffer. ARGS is entity specific.
1821 ENTITY can be one of PARAGRAPH, LIST, LIST-ITEM etc.
1823 Use (org-lparse-begin 'LIST \"o\") to begin a list in current
1824 buffer.
1826 See `org-xhtml-entity-control-callbacks-alist' for more
1827 information."
1828 (when (and (member org-lparse-debug '(t control))
1829 (not (eq entity 'DOCUMENT-CONTENT)))
1830 (insert (org-lparse-format 'COMMENT "%s BEGIN %S" entity args)))
1832 (let ((f (cadr (assoc entity org-lparse-entity-control-callbacks-alist))))
1833 (unless f (error "Unknown entity: %s" entity))
1834 (apply f args)))
1836 (defun org-lparse-end (entity &rest args)
1837 "Close ENTITY in current buffer. ARGS is entity specific.
1838 ENTITY can be one of PARAGRAPH, LIST, LIST-ITEM
1839 etc.
1841 Use (org-lparse-end 'LIST \"o\") to close a list in current
1842 buffer.
1844 See `org-xhtml-entity-control-callbacks-alist' for more
1845 information."
1846 (when (and (member org-lparse-debug '(t control))
1847 (not (eq entity 'DOCUMENT-CONTENT)))
1848 (insert (org-lparse-format 'COMMENT "%s END %S" entity args)))
1850 (let ((f (caddr (assoc entity org-lparse-entity-control-callbacks-alist))))
1851 (unless f (error "Unknown entity: %s" entity))
1852 (apply f args)))
1854 (defun org-lparse-begin-paragraph (&optional style)
1855 "Insert <p>, but first close previous paragraph if any."
1856 (org-lparse-end-paragraph)
1857 (org-lparse-begin 'PARAGRAPH style)
1858 (setq org-lparse-par-open t))
1860 (defun org-lparse-end-paragraph ()
1861 "Close paragraph if there is one open."
1862 (when org-lparse-par-open
1863 (org-lparse-end 'PARAGRAPH)
1864 (setq org-lparse-par-open nil)))
1866 (defun org-lparse-end-list-item-1 (&optional type)
1867 "Close <li> if necessary."
1868 (org-lparse-end-paragraph)
1869 (org-lparse-end-list-item (or type "u")))
1871 (defcustom org-lparse-list-table-enable nil
1872 "Specify whether a list be exported as a table.
1873 When this option is enabled, lists that are enclosed in
1874 \"#+begin_list-table...#+end_list-table\" are exported as
1875 tables. Otherwise they are exported normally."
1876 :type 'boolean
1877 :group 'org-lparse)
1879 (defun org-lparse-preprocess-after-blockquote-hook ()
1880 "Treat #+begin_list-table...#+end_list-table blocks specially.
1881 When `org-lparse-list-table-enable' is non-nil, enclose these
1882 blocks within ORG-LIST-TABLE-START...ORG-LIST-TABLE-END."
1883 (when org-lparse-list-table-enable
1884 (goto-char (point-min))
1885 (while (re-search-forward "^[ \t]*#\\+\\(begin\\|end\\)_\\(.*\\)$" nil t)
1886 (when (string= (downcase (match-string 2)) "list-table")
1887 (replace-match (if (equal (downcase (match-string 1)) "begin")
1888 "ORG-LIST-TABLE-START"
1889 "ORG-LIST-TABLE-END") t t)))))
1891 (add-hook 'org-export-preprocess-after-blockquote-hook
1892 'org-lparse-preprocess-after-blockquote-hook)
1894 (defvar org-lparse-list-table-p nil
1895 "Non-nil if `org-do-lparse' is within a list-table.
1896 See `org-lparse-list-table-enable'.")
1898 (defvar org-lparse-dyn-current-environment nil)
1899 (defun org-lparse-begin-environment (style)
1900 (case style
1901 (list-table
1902 (setq org-lparse-list-table-p org-lparse-list-table-enable))
1904 (setq org-lparse-dyn-current-environment style)
1905 (org-lparse-begin 'ENVIRONMENT style))))
1907 (defun org-lparse-end-environment (style)
1908 (case style
1909 (list-table
1910 (setq org-lparse-list-table-p nil))
1912 (org-lparse-end 'ENVIRONMENT style)
1913 (setq org-lparse-dyn-current-environment nil))))
1915 (defun org-lparse-current-environment-p (style)
1916 (eq org-lparse-dyn-current-environment style))
1918 (defun org-lparse-begin-footnote-definition (n)
1919 (org-lparse-begin-collect)
1920 (setq org-lparse-insert-tag-with-newlines nil)
1921 (org-lparse-begin 'FOOTNOTE-DEFINITION n))
1923 (defun org-lparse-end-footnote-definition (n)
1924 (org-lparse-end 'FOOTNOTE-DEFINITION n)
1925 (setq org-lparse-insert-tag-with-newlines 'both)
1926 (let ((footnote-def (org-lparse-end-collect)))
1927 (push (cons n footnote-def) org-lparse-footnote-definitions)))
1929 (defvar org-lparse-collect-buffer nil
1930 "An auxiliary buffer named \"*Org Lparse Collect*\".
1931 `org-do-lparse' uses this as output buffer while collecting
1932 footnote definitions and table-cell contents of list-tables. See
1933 `org-lparse-begin-collect' and `org-lparse-end-collect'.")
1935 (defvar org-lparse-collect-count nil
1936 "Count number of calls to `org-lparse-begin-collect'.
1937 Use this counter to catch chained collections if they ever
1938 happen.")
1940 (defun org-lparse-begin-collect ()
1941 "Temporarily switch to `org-lparse-collect-buffer'.
1942 Also erase it's contents."
1943 (unless (zerop org-lparse-collect-count)
1944 (error "FIXME (org-lparse.el): Encountered chained collections"))
1945 (incf org-lparse-collect-count)
1946 (unless org-lparse-collect-buffer
1947 (setq org-lparse-collect-buffer
1948 (get-buffer-create "*Org Lparse Collect*")))
1949 (set-buffer org-lparse-collect-buffer)
1950 (erase-buffer))
1952 (defun org-lparse-end-collect ()
1953 "Switch to `org-lparse-output-buffer'.
1954 Return contents of `org-lparse-collect-buffer' as a `string'."
1955 (assert (> org-lparse-collect-count 0))
1956 (decf org-lparse-collect-count)
1957 (prog1 (buffer-string)
1958 (erase-buffer)
1959 (set-buffer org-lparse-output-buffer)))
1961 (defun org-lparse-format (entity &rest args)
1962 "Format ENTITY in backend-specific way and return it.
1963 ARGS is specific to entity being formatted.
1965 Use (org-lparse-format 'HEADING \"text\" 1) to format text as
1966 level 1 heading.
1968 See `org-xhtml-entity-format-callbacks-alist' for more information."
1969 (when (and (member org-lparse-debug '(t format))
1970 (not (equal entity 'COMMENT)))
1971 (insert (org-lparse-format 'COMMENT "%s: %S" entity args)))
1972 (cond
1973 ((consp entity)
1974 (let ((text (pop args)))
1975 (apply 'org-lparse-format 'TAGS entity text args)))
1977 (let ((f (cdr (assoc entity org-lparse-entity-format-callbacks-alist))))
1978 (unless f (error "Unknown entity: %s" entity))
1979 (apply f args)))))
1981 (defun org-lparse-insert (entity &rest args)
1982 (insert (apply 'org-lparse-format entity args)))
1984 (defun org-lparse-prepare-toc (lines level-offset opt-plist umax-toc)
1985 (let* ((quote-re0 (concat "^[ \t]*" org-quote-string "\\>"))
1986 (org-min-level (org-get-min-level lines level-offset))
1987 (org-last-level org-min-level)
1988 level)
1989 (with-temp-buffer
1990 (org-lparse-bind-local-variables opt-plist)
1991 (erase-buffer)
1992 (org-lparse-begin 'TOC (nth 3 (plist-get opt-plist :lang-words)))
1993 (setq
1994 lines
1995 (mapcar
1996 #'(lambda (line)
1997 (when (and (string-match org-todo-line-regexp line)
1998 (not (get-text-property 0 'org-protected line))
1999 (<= (setq level (org-tr-level
2000 (- (match-end 1) (match-beginning 1)
2001 level-offset)))
2002 umax-toc))
2003 (let ((txt (save-match-data
2004 (org-xml-encode-org-text-skip-links
2005 (org-export-cleanup-toc-line
2006 (match-string 3 line)))))
2007 (todo (and
2008 org-export-mark-todo-in-toc
2009 (or (and (match-beginning 2)
2010 (not (member (match-string 2 line)
2011 org-done-keywords)))
2012 (and (= level umax-toc)
2013 (org-search-todo-below
2014 line lines level)))))
2015 tags)
2016 ;; Check for targets
2017 (while (string-match org-any-target-regexp line)
2018 (setq line
2019 (replace-match
2020 (let ((org-lparse-encode-pending t))
2021 (org-lparse-format 'FONTIFY
2022 (match-string 1 line) "target"))
2023 t t line)))
2024 (when (string-match
2025 (org-re "[ \t]+:\\([[:alnum:]_@:]+\\):[ \t]*$") txt)
2026 (setq tags (match-string 1 txt)
2027 txt (replace-match "" t nil txt)))
2028 (when (string-match quote-re0 txt)
2029 (setq txt (replace-match "" t t txt)))
2030 (while (string-match "&lt;\\(&lt;\\)+\\|&gt;\\(&gt;\\)+" txt)
2031 (setq txt (replace-match "" t t txt)))
2032 (org-lparse-format
2033 'TOC-ITEM
2034 (let* ((snumber (org-section-number level))
2035 (href (replace-regexp-in-string
2036 "\\." "-" (format "sec-%s" snumber)))
2037 (href
2039 (cdr (assoc
2040 href org-export-preferred-target-alist))
2041 href))
2042 (href (org-solidify-link-text href)))
2043 (org-lparse-format 'TOC-ENTRY snumber todo txt tags href))
2044 level org-last-level)
2045 (setq org-last-level level)))
2046 line)
2047 lines))
2048 (org-lparse-end 'TOC)
2049 (setq org-lparse-toc (buffer-string))))
2050 lines)
2052 (defun org-lparse-format-table-row (fields &optional text-for-empty-fields)
2053 (if org-lparse-table-ncols
2054 ;; second and subsequent rows of the table
2055 (when (and org-lparse-list-table-p
2056 (> (length fields) org-lparse-table-ncols))
2057 (error "Table row has %d columns but header row claims %d columns"
2058 (length fields) org-lparse-table-ncols))
2059 ;; first row of the table
2060 (setq org-lparse-table-ncols (length fields))
2061 (when org-lparse-table-is-styled
2062 (setq org-lparse-table-num-numeric-items-per-column
2063 (make-vector org-lparse-table-ncols 0))
2064 (setq org-lparse-table-colalign-vector
2065 (make-vector org-lparse-table-ncols nil))
2066 (let ((c -1))
2067 (while (< (incf c) org-lparse-table-ncols)
2068 (let ((cookie (cdr (assoc (1+ c) org-lparse-table-colalign-info))))
2069 (setf (aref org-lparse-table-colalign-vector c)
2070 (cond
2071 ((string= cookie "l") "left")
2072 ((string= cookie "r") "right")
2073 ((string= cookie "c") "center")
2074 (t nil))))))))
2075 (incf org-lparse-table-rownum)
2076 (let ((i -1))
2077 (org-lparse-format
2078 'TABLE-ROW
2079 (mapconcat
2080 (lambda (x)
2081 (when (and (string= x "") text-for-empty-fields)
2082 (setq x text-for-empty-fields))
2083 (incf i)
2084 (and org-lparse-table-is-styled
2085 (< i org-lparse-table-ncols)
2086 (string-match org-table-number-regexp x)
2087 (incf (aref org-lparse-table-num-numeric-items-per-column i)))
2088 (org-lparse-format 'TABLE-CELL x org-lparse-table-rownum i))
2089 fields "\n"))))
2091 (defun org-lparse-get (what &optional opt-plist)
2092 "Query for value of WHAT for the current backend `org-lparse-backend'.
2093 See also `org-lparse-backend-get'."
2094 (if (boundp 'org-lparse-backend)
2095 (org-lparse-backend-get (symbol-name org-lparse-backend) what opt-plist)
2096 (error "org-lparse-backend is not bound yet")))
2098 (defun org-lparse-backend-get (backend what &optional opt-plist)
2099 "Query BACKEND for value of WHAT.
2100 Dispatch the call to `org-<backend>-user-get'. If that throws an
2101 error, dispatch the call to `org-<backend>-get'. See
2102 `org-xhtml-get' for all known settings queried for by
2103 `org-lparse' during the course of export."
2104 (assert (stringp backend) t)
2105 (unless (org-lparse-backend-is-native-p backend)
2106 (error "Unknown native backend %s" backend))
2107 (let ((backend-get-method (intern (format "org-%s-get" backend)))
2108 (backend-user-get-method (intern (format "org-%s-user-get" backend))))
2109 (cond
2110 ((functionp backend-get-method)
2111 (condition-case nil
2112 (funcall backend-user-get-method what opt-plist)
2113 (error (funcall backend-get-method what opt-plist))))
2115 (error "Native backend %s doesn't define %s" backend backend-get-method)))))
2117 (defun org-lparse-insert-tag (tag &rest args)
2118 (when (member org-lparse-insert-tag-with-newlines '(lead both))
2119 (insert "\n"))
2120 (insert (apply 'format tag args))
2121 (when (member org-lparse-insert-tag-with-newlines '(trail both))
2122 (insert "\n")))
2124 (defun org-lparse-get-targets-from-title (title)
2125 (let* ((target (org-get-text-property-any 0 'target title))
2126 (extra-targets (assoc target org-export-target-aliases))
2127 (target (or (cdr (assoc target org-export-preferred-target-alist))
2128 target)))
2129 (cons target (remove target extra-targets))))
2131 (defun org-lparse-suffix-from-snumber (snumber)
2132 (let* ((snu (replace-regexp-in-string "\\." "-" snumber))
2133 (href (cdr (assoc (concat "sec-" snu)
2134 org-export-preferred-target-alist))))
2135 (org-solidify-link-text (or href snu))))
2137 (defun org-lparse-begin-level (level title umax head-count)
2138 "Insert a new LEVEL in HTML export.
2139 When TITLE is nil, just close all open levels."
2140 (org-lparse-end-level level umax)
2141 (unless title (error "Why is heading nil"))
2142 (let* ((targets (org-lparse-get-targets-from-title title))
2143 (target (car targets)) (extra-targets (cdr targets))
2144 (target (and target (org-solidify-link-text target)))
2145 (extra-class (org-get-text-property-any 0 'html-container-class title))
2146 snumber tags level1 class)
2147 (when (string-match (org-re "\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$") title)
2148 (setq tags (and org-export-with-tags (match-string 1 title)))
2149 (setq title (replace-match "" t t title)))
2150 (if (> level umax)
2151 (progn
2152 (if (aref org-levels-open (1- level))
2153 (org-lparse-end-list-item-1)
2154 (aset org-levels-open (1- level) t)
2155 (org-lparse-end-paragraph)
2156 (org-lparse-begin-list 'unordered))
2157 (org-lparse-begin-list-item
2158 'unordered target (org-lparse-format
2159 'HEADLINE title extra-targets tags)))
2160 (aset org-levels-open (1- level) t)
2161 (setq snumber (org-section-number level))
2162 (setq level1 (+ level (or (org-lparse-get 'TOPLEVEL-HLEVEL) 1) -1))
2163 (unless (= head-count 1)
2164 (org-lparse-end-outline-text-or-outline))
2165 (org-lparse-begin-outline-and-outline-text
2166 level1 snumber title tags target extra-targets extra-class)
2167 (org-lparse-begin-paragraph))))
2169 (defun org-lparse-end-level (level umax)
2170 (org-lparse-end-paragraph)
2171 (loop for l from org-level-max downto level
2172 do (when (aref org-levels-open (1- l))
2173 ;; Terminate one level in HTML export
2174 (if (<= l umax)
2175 (org-lparse-end-outline-text-or-outline)
2176 (org-lparse-end-list-item-1)
2177 (org-lparse-end-list 'unordered))
2178 (aset org-levels-open (1- l) nil))))
2180 (defvar org-lparse-outline-text-open)
2181 (defun org-lparse-begin-outline-and-outline-text (level1 snumber title tags
2182 target extra-targets
2183 extra-class)
2184 (org-lparse-begin
2185 'OUTLINE level1 snumber title tags target extra-targets extra-class)
2186 (org-lparse-begin-outline-text level1 snumber extra-class))
2188 (defun org-lparse-end-outline-text-or-outline ()
2189 (cond
2190 (org-lparse-outline-text-open
2191 (org-lparse-end 'OUTLINE-TEXT)
2192 (setq org-lparse-outline-text-open nil))
2193 (t (org-lparse-end 'OUTLINE))))
2195 (defun org-lparse-begin-outline-text (level1 snumber extra-class)
2196 (assert (not org-lparse-outline-text-open) t)
2197 (setq org-lparse-outline-text-open t)
2198 (org-lparse-begin 'OUTLINE-TEXT level1 snumber extra-class))
2200 (defun org-lparse-html-list-type-to-canonical-list-type (ltype)
2201 (cdr (assoc ltype '(("o" . ordered)
2202 ("u" . unordered)
2203 ("d" . description)))))
2205 ;; following vars are bound during `org-do-lparse'
2206 (defvar org-lparse-list-level)
2207 (defvar org-lparse-list-item-count)
2208 (defvar org-lparse-list-stack)
2209 (defvar org-lparse-list-table:table-row)
2210 (defvar org-lparse-list-table:lines)
2212 ;; Notes on LIST-TABLES
2213 ;; ====================
2214 ;; When `org-lparse-list-table-enable' is non-nil, the following list
2216 ;; #+begin_list-table
2217 ;; - Row 1
2218 ;; - 1.1
2219 ;; - 1.2
2220 ;; - 1.3
2221 ;; - Row 2
2222 ;; - 2.1
2223 ;; - 2.2
2224 ;; - 2.3
2225 ;; #+end_list-table
2227 ;; will be exported as though it were a table as shown below.
2229 ;; | Row 1 | 1.1 | 1.2 | 1.3 |
2230 ;; | Row 2 | 2.1 | 2.2 | 2.3 |
2232 ;; Note that org-tables are NOT multi-line and each line is mapped to
2233 ;; a unique row in the exported document. So if an exported table
2234 ;; needs to contain a single paragraph (with copious text) it needs to
2235 ;; be typed up in a single line. Editing such long lines using the
2236 ;; table editor will be a cumbersome task. Furthermore inclusion of
2237 ;; multi-paragraph text in a table cell is well-nigh impossible.
2239 ;; LIST-TABLEs are meant to circumvent the above problems with
2240 ;; org-tables.
2242 ;; Note that in the example above the list items could be paragraphs
2243 ;; themselves and the list can be arbitrarily deep.
2245 ;; Inspired by following thread:
2246 ;; https://lists.gnu.org/archive/html/emacs-orgmode/2011-03/msg01101.html
2248 (defun org-lparse-begin-list (ltype)
2249 (incf org-lparse-list-level)
2250 (push org-lparse-list-item-count org-lparse-list-stack)
2251 (setq org-lparse-list-item-count 0)
2252 (cond
2253 ((not org-lparse-list-table-p)
2254 (org-lparse-begin 'LIST ltype))
2255 ;; process LIST-TABLE
2256 ((= 1 org-lparse-list-level)
2257 ;; begin LIST-TABLE
2258 (setq org-lparse-list-table:lines nil)
2259 (setq org-lparse-list-table:table-row nil))
2260 ((= 2 org-lparse-list-level)
2261 (ignore))
2263 (org-lparse-begin 'LIST ltype))))
2265 (defun org-lparse-end-list (ltype)
2266 (setq org-lparse-list-item-count (pop org-lparse-list-stack))
2267 (decf org-lparse-list-level)
2268 (cond
2269 ((not org-lparse-list-table-p)
2270 (org-lparse-end 'LIST ltype))
2271 ;; process LIST-TABLE
2272 ((= 0 org-lparse-list-level)
2273 ;; end LIST-TABLE
2274 (insert (org-lparse-format-list-table
2275 (nreverse org-lparse-list-table:lines))))
2276 ((= 1 org-lparse-list-level)
2277 (ignore))
2279 (org-lparse-end 'LIST ltype))))
2281 (defun org-lparse-begin-list-item (ltype &optional arg headline)
2282 (incf org-lparse-list-item-count)
2283 (cond
2284 ((not org-lparse-list-table-p)
2285 (org-lparse-begin 'LIST-ITEM ltype arg headline))
2286 ;; process LIST-TABLE
2287 ((and (= 1 org-lparse-list-level)
2288 (= 1 org-lparse-list-item-count))
2289 ;; begin TABLE-ROW for LIST-TABLE
2290 (setq org-lparse-list-table:table-row nil)
2291 (org-lparse-begin-list-table:table-cell))
2292 ((and (= 2 org-lparse-list-level)
2293 (= 1 org-lparse-list-item-count))
2294 ;; begin TABLE-CELL for LIST-TABLE
2295 (org-lparse-begin-list-table:table-cell))
2297 (org-lparse-begin 'LIST-ITEM ltype arg headline))))
2299 (defun org-lparse-end-list-item (ltype)
2300 (decf org-lparse-list-item-count)
2301 (cond
2302 ((not org-lparse-list-table-p)
2303 (org-lparse-end 'LIST-ITEM ltype))
2304 ;; process LIST-TABLE
2305 ((and (= 1 org-lparse-list-level)
2306 (= 0 org-lparse-list-item-count))
2307 ;; end TABLE-ROW for LIST-TABLE
2308 (org-lparse-end-list-table:table-cell)
2309 (push (nreverse org-lparse-list-table:table-row)
2310 org-lparse-list-table:lines))
2311 ((= 2 org-lparse-list-level)
2312 ;; end TABLE-CELL for LIST-TABLE
2313 (org-lparse-end-list-table:table-cell))
2315 (org-lparse-end 'LIST-ITEM ltype))))
2317 (defvar org-lparse-list-table:table-cell-open)
2318 (defun org-lparse-begin-list-table:table-cell ()
2319 (org-lparse-end-list-table:table-cell)
2320 (setq org-lparse-list-table:table-cell-open t)
2321 (org-lparse-begin-collect)
2322 (org-lparse-begin-paragraph))
2324 (defun org-lparse-end-list-table:table-cell ()
2325 (when org-lparse-list-table:table-cell-open
2326 (setq org-lparse-list-table:table-cell-open nil)
2327 (org-lparse-end-paragraph)
2328 (push (org-lparse-end-collect)
2329 org-lparse-list-table:table-row)))
2331 (defvar org-lparse-table-rowgrp-info)
2332 (defun org-lparse-begin-table-rowgroup (&optional is-header-row)
2333 (push (cons (1+ org-lparse-table-rownum) :start) org-lparse-table-rowgrp-info)
2334 (org-lparse-begin 'TABLE-ROWGROUP is-header-row))
2336 (defun org-lparse-end-table ()
2337 (when org-lparse-table-is-styled
2338 ;; column groups
2339 (unless (car org-table-colgroup-info)
2340 (setq org-table-colgroup-info
2341 (cons :start (cdr org-table-colgroup-info))))
2343 ;; column alignment
2344 (let ((c -1))
2345 (mapc
2346 (lambda (x)
2347 (incf c)
2348 (setf (aref org-lparse-table-colalign-vector c)
2349 (or (aref org-lparse-table-colalign-vector c)
2350 (if (> (/ (float x) (1+ org-lparse-table-rownum))
2351 org-table-number-fraction)
2352 "right" "left"))))
2353 org-lparse-table-num-numeric-items-per-column)))
2354 (org-lparse-end 'TABLE))
2356 (defvar org-lparse-encode-pending nil)
2358 (defun org-lparse-format-tags (tag text prefix suffix &rest args)
2359 (cond
2360 ((consp tag)
2361 (concat prefix (apply 'format (car tag) args) text suffix
2362 (format (cdr tag))))
2363 ((stringp tag) ; singleton tag
2364 (concat prefix (apply 'format tag args) text))))
2366 (defun org-xml-fix-class-name (kwd) ; audit callers of this function
2367 "Turn todo keyword into a valid class name.
2368 Replaces invalid characters with \"_\"."
2369 (save-match-data
2370 (while (string-match "[^a-zA-Z0-9_]" kwd)
2371 (setq kwd (replace-match "_" t t kwd))))
2372 kwd)
2374 (defun org-lparse-format-todo (todo)
2375 (org-lparse-format 'FONTIFY
2376 (concat
2377 (ignore-errors (org-lparse-get 'TODO-KWD-CLASS-PREFIX))
2378 (org-xml-fix-class-name todo))
2379 (list (if (member todo org-done-keywords) "done" "todo")
2380 todo)))
2382 (defun org-lparse-format-extra-targets (extra-targets)
2383 (if (not extra-targets) ""
2384 (mapconcat (lambda (x)
2385 (setq x (org-solidify-link-text
2386 (if (org-uuidgen-p x) (concat "ID-" x) x)))
2387 (org-lparse-format 'ANCHOR "" x))
2388 extra-targets "")))
2390 (defun org-lparse-format-org-tags (tags)
2391 (if (not tags) ""
2392 (org-lparse-format
2393 'FONTIFY (mapconcat
2394 (lambda (x)
2395 (org-lparse-format
2396 'FONTIFY x
2397 (concat
2398 (ignore-errors (org-lparse-get 'TAG-CLASS-PREFIX))
2399 (org-xml-fix-class-name x))))
2400 (org-split-string tags ":")
2401 (org-lparse-format 'SPACES 1)) "tag")))
2403 (defun org-lparse-format-section-number (&optional snumber level)
2404 (and org-export-with-section-numbers
2405 (not org-lparse-body-only) snumber level
2406 (org-lparse-format 'FONTIFY snumber (format "section-number-%d" level))))
2408 (defun org-lparse-warn (msg)
2409 (if (not org-lparse-use-flashy-warning)
2410 (message msg)
2411 (put-text-property 0 (length msg) 'face 'font-lock-warning-face msg)
2412 (message msg)
2413 (sleep-for 3)))
2415 (defun org-xml-format-href (s)
2416 "Make sure the S is valid as a href reference in an XHTML document."
2417 (save-match-data
2418 (let ((start 0))
2419 (while (string-match "&" s start)
2420 (setq start (+ (match-beginning 0) 3)
2421 s (replace-match "&amp;" t t s)))))
2424 (defun org-xml-format-desc (s)
2425 "Make sure the S is valid as a description in a link."
2426 (if (and s (not (get-text-property 1 'org-protected s)))
2427 (save-match-data
2428 (org-xml-encode-org-text s))
2431 (provide 'org-lparse)
2433 ;;; org-lparse.el ends here