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