1 ;;; org-docbook.el --- DocBook exporter for org-mode
3 ;; Copyright (C) 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
5 ;; Emacs Lisp Archive Entry
6 ;; Filename: org-docbook.el
8 ;; Author: Baoqiu Cui <cbaoqiu AT yahoo DOT com>
9 ;; Maintainer: Baoqiu Cui <cbaoqiu AT yahoo DOT com>
10 ;; Keywords: org, wp, docbook
11 ;; Description: Converts an org-mode buffer into DocBook
14 ;; This file is part of GNU Emacs.
16 ;; GNU Emacs is free software: you can redistribute it and/or modify
17 ;; it under the terms of the GNU General Public License as published by
18 ;; the Free Software Foundation, either version 3 of the License, or
19 ;; (at your option) any later version.
21 ;; GNU Emacs is distributed in the hope that it will be useful,
22 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
23 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 ;; GNU General Public License for more details.
26 ;; You should have received a copy of the GNU General Public License
27 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
31 ;; This library implements a DocBook exporter for org-mode. The basic
32 ;; idea and design is very similar to what `org-export-as-html' has.
33 ;; Code prototype was also started with `org-export-as-html'.
35 ;; Put this file into your load-path and the following line into your
38 ;; (require 'org-docbook)
40 ;; The interactive functions are similar to those of the HTML and LaTeX
43 ;; M-x `org-export-as-docbook'
44 ;; M-x `org-export-as-docbook-pdf'
45 ;; M-x `org-export-as-docbook-pdf-and-open'
46 ;; M-x `org-export-as-docbook-batch'
47 ;; M-x `org-export-as-docbook-to-buffer'
48 ;; M-x `org-export-region-as-docbook'
49 ;; M-x `org-replace-region-by-docbook'
51 ;; Note that, in order to generate PDF files using the DocBook XML files
52 ;; created by DocBook exporter, the following two variables have to be
53 ;; set based on what DocBook tools you use for XSLT processor and XSL-FO
56 ;; org-export-docbook-xslt-proc-command
57 ;; org-export-docbook-xsl-fo-proc-command
59 ;; Check the document of these two variables to see examples of how they
62 ;; If the Org file to be exported contains special characters written in
63 ;; TeX-like syntax, like \alpha and \beta, you need to include the right
64 ;; entity file(s) in the DOCTYPE declaration for the DocBook XML file.
65 ;; This is required to make the DocBook XML file valid. The DOCTYPE
66 ;; declaration string can be set using the following variable:
68 ;; org-export-docbook-doctype
79 (require 'format-spec
)
83 (defvar org-docbook-para-open nil
)
84 (defvar org-export-docbook-inline-images t
)
85 (defvar org-export-docbook-link-org-files-as-docbook nil
)
87 (declare-function org-id-find-id-file
"org-id" (id))
91 (defgroup org-export-docbook nil
92 "Options for exporting Org-mode files to DocBook."
93 :tag
"Org Export DocBook"
96 (defcustom org-export-docbook-extension
".xml"
97 "Extension of DocBook XML files."
98 :group
'org-export-docbook
101 (defcustom org-export-docbook-header
"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
102 "Header of DocBook XML files."
103 :group
'org-export-docbook
106 (defcustom org-export-docbook-doctype nil
107 "DOCTYPE declaration string for DocBook XML files.
108 This can be used to include entities that are needed to handle
109 special characters in Org files.
111 For example, if the Org file to be exported contains XHTML
112 entities, you can set this variable to:
114 \"<!DOCTYPE article [
115 <!ENTITY % xhtml1-symbol PUBLIC
116 \"-//W3C//ENTITIES Symbol for HTML//EN//XML\"
117 \"http://www.w3.org/2003/entities/2007/xhtml1-symbol.ent\"
123 If you want to process DocBook documents without an Internet
124 connection, it is suggested that you download the required entity
125 file(s) and use system identifier(s) (external files) in the
126 DOCTYPE declaration."
127 :group
'org-export-docbook
130 (defcustom org-export-docbook-article-header
"<article xmlns=\"http://docbook.org/ns/docbook\"
131 xmlns:xlink=\"http://www.w3.org/1999/xlink\" version=\"5.0\" xml:lang=\"en\">"
132 "Article header of DocBook XML files."
133 :group
'org-export-docbook
136 (defcustom org-export-docbook-section-id-prefix
"sec-"
137 "Prefix of section IDs used during exporting.
138 This can be set before exporting to avoid same set of section IDs
139 being used again and again, which can be a problem when multiple
140 people work on the same document."
141 :group
'org-export-docbook
144 (defcustom org-export-docbook-footnote-id-prefix
"fn-"
145 "The prefix of footnote IDs used during exporting.
146 Like `org-export-docbook-section-id-prefix', this variable can help
147 avoid same set of footnote IDs being used multiple times."
148 :group
'org-export-docbook
151 (defcustom org-export-docbook-emphasis-alist
152 `(("*" "<emphasis role=\"bold\">" "</emphasis>")
153 ("/" "<emphasis>" "</emphasis>")
154 ("_" "<emphasis role=\"underline\">" "</emphasis>")
155 ("=" "<code>" "</code>")
156 ("~" "<literal>" "</literal>")
157 ("+" "<emphasis role=\"strikethrough\">" "</emphasis>"))
158 "A list of DocBook expressions to convert emphasis fontifiers.
159 Each element of the list is a list of three elements.
160 The first element is the character used as a marker for fontification.
161 The second element is a formatting string to wrap fontified text with.
162 The third element decides whether to protect converted text from other
164 :group
'org-export-docbook
167 (defcustom org-export-docbook-default-image-attributes
168 `(("align" .
"\"center\"")
169 ("valign".
"\"middle\""))
170 "Alist of default DocBook image attributes.
171 These attributes will be inserted into element <imagedata> by
172 default, but users can override them using `#+ATTR_DocBook:'."
173 :group
'org-export-docbook
176 (defcustom org-export-docbook-inline-image-extensions
177 '("jpeg" "jpg" "png" "gif" "svg")
178 "Extensions of image files that can be inlined into DocBook."
179 :group
'org-export-docbook
180 :type
'(repeat (string :tag
"Extension")))
182 (defcustom org-export-docbook-coding-system nil
183 "Coding system for DocBook XML files."
184 :group
'org-export-docbook
185 :type
'coding-system
)
187 (defcustom org-export-docbook-xslt-stylesheet nil
188 "File name of the XSLT stylesheet used by DocBook exporter.
189 This XSLT stylesheet is used by
190 `org-export-docbook-xslt-proc-command' to generate the Formatting
191 Object (FO) files. You can use either `fo/docbook.xsl' that
192 comes with DocBook, or any customization layer you may have."
193 :group
'org-export-docbook
196 (defcustom org-export-docbook-xslt-proc-command nil
197 "Format of XSLT processor command used by DocBook exporter.
198 This command is used to process a DocBook XML file to generate
199 the Formatting Object (FO) file.
201 The value of this variable should be a format control string that
202 includes three arguments: `%i', `%o', and `%s'. During exporting
203 time, `%i' is replaced by the input DocBook XML file name, `%o'
204 is replaced by the output FO file name, and `%s' is replaced by
205 `org-export-docbook-xslt-stylesheet' (or the #+XSLT option if it
206 is specified in the Org file).
208 For example, if you use Saxon as the XSLT processor, you may want
209 to set the variable to
211 \"java com.icl.saxon.StyleSheet -o %o %i %s\"
213 If you use Xalan, you can set it to
215 \"java org.apache.xalan.xslt.Process -out %o -in %i -xsl %s\"
217 For xsltproc, the following string should work:
219 \"xsltproc --output %o %s %i\"
221 You can include additional stylesheet parameters in this command.
222 Just make sure that they meet the syntax requirement of each
224 :group
'org-export-docbook
227 (defcustom org-export-docbook-xsl-fo-proc-command nil
228 "Format of XSL-FO processor command used by DocBook exporter.
229 This command is used to process a Formatting Object (FO) file to
230 generate the PDF file.
232 The value of this variable should be a format control string that
233 includes two arguments: `%i' and `%o'. During exporting time,
234 `%i' is replaced by the input FO file name, and `%o' is replaced
235 by the output PDF file name.
237 For example, if you use FOP as the XSL-FO processor, you can set
241 :group
'org-export-docbook
244 (defcustom org-export-docbook-keywords-markup
"<literal>%s</literal>"
245 "A printf format string to be applied to keywords by DocBook exporter."
246 :group
'org-export-docbook
249 (defcustom org-export-docbook-timestamp-markup
"<emphasis>%s</emphasis>"
250 "A printf format string to be applied to time stamps by DocBook exporter."
251 :group
'org-export-docbook
256 (defvar org-export-docbook-final-hook nil
257 "Hook run at the end of DocBook export, in the new buffer.")
259 ;;; Autoload functions:
262 (defun org-export-as-docbook-batch ()
263 "Call `org-export-as-docbook' in batch style.
264 This function can be used in batch processing.
269 --load=$HOME/lib/emacs/org.el
270 --visit=MyOrgFile.org --funcall org-export-as-docbook-batch"
271 (org-export-as-docbook 'hidden
))
274 (defun org-export-as-docbook-to-buffer ()
275 "Call `org-export-as-docbook' with output to a temporary buffer.
278 (org-export-as-docbook nil nil
"*Org DocBook Export*")
279 (when org-export-show-temporary-export-buffer
280 (switch-to-buffer-other-window "*Org DocBook Export*")))
283 (defun org-replace-region-by-docbook (beg end
)
284 "Replace the region from BEG to END with its DocBook export.
285 It assumes the region has `org-mode' syntax, and then convert it to
286 DocBook. This can be used in any buffer. For example, you could
287 write an itemized list in `org-mode' syntax in an DocBook buffer and
288 then use this command to convert it."
290 (let (reg docbook buf
)
291 (save-window-excursion
293 (setq docbook
(org-export-region-as-docbook
295 (setq reg
(buffer-substring beg end
)
296 buf
(get-buffer-create "*Org tmp*"))
297 (with-current-buffer buf
301 (setq docbook
(org-export-region-as-docbook
302 (point-min) (point-max) t
'string
)))
304 (delete-region beg end
)
308 (defun org-export-region-as-docbook (beg end
&optional body-only buffer
)
309 "Convert region from BEG to END in `org-mode' buffer to DocBook.
310 If prefix arg BODY-ONLY is set, omit file header and footer and
311 only produce the region of converted text, useful for
312 cut-and-paste operations. If BUFFER is a buffer or a string,
313 use/create that buffer as a target of the converted DocBook. If
314 BUFFER is the symbol `string', return the produced DocBook as a
315 string and leave not buffer behind. For example, a Lisp program
316 could call this function in the following way:
318 (setq docbook (org-export-region-as-docbook beg end t 'string))
320 When called interactively, the output buffer is selected, and shown
321 in a window. A non-interactive call will only return the buffer."
323 (when (interactive-p)
324 (setq buffer
"*Org DocBook Export*"))
325 (let ((transient-mark-mode t
)
329 (set-mark (point)) ;; To activate the region
331 (setq rtn
(org-export-as-docbook
334 (if (fboundp 'deactivate-mark
) (deactivate-mark))
335 (if (and (interactive-p) (bufferp rtn
))
336 (switch-to-buffer-other-window rtn
)
340 (defun org-export-as-docbook-pdf (&optional hidden ext-plist
341 to-buffer body-only pub-dir
)
342 "Export as DocBook XML file, and generate PDF file."
344 (if (or (not org-export-docbook-xslt-proc-command
)
345 (not (string-match "%[ios].+%[ios].+%[ios]" org-export-docbook-xslt-proc-command
)))
346 (error "XSLT processor command is not set correctly"))
347 (if (or (not org-export-docbook-xsl-fo-proc-command
)
348 (not (string-match "%[io].+%[io]" org-export-docbook-xsl-fo-proc-command
)))
349 (error "XSL-FO processor command is not set correctly"))
350 (message "Exporting to PDF...")
351 (let* ((wconfig (current-window-configuration))
353 (org-export-process-option-filters
354 (org-combine-plists (org-default-export-plist)
356 (org-infile-export-plist))))
357 (docbook-buf (org-export-as-docbook hidden ext-plist
358 to-buffer body-only pub-dir
))
359 (filename (buffer-file-name docbook-buf
))
360 (base (file-name-sans-extension filename
))
361 (fofile (concat base
".fo"))
362 (pdffile (concat base
".pdf")))
363 (and (file-exists-p pdffile
) (delete-file pdffile
))
364 (message "Processing DocBook XML file...")
365 (shell-command (format-spec org-export-docbook-xslt-proc-command
367 ?i
(shell-quote-argument filename
)
368 ?o
(shell-quote-argument fofile
)
369 ?s
(shell-quote-argument
370 (or (plist-get opt-plist
:xslt
)
371 org-export-docbook-xslt-stylesheet
)))))
372 (shell-command (format-spec org-export-docbook-xsl-fo-proc-command
374 ?i
(shell-quote-argument fofile
)
375 ?o
(shell-quote-argument pdffile
))))
376 (message "Processing DocBook file...done")
377 (if (not (file-exists-p pdffile
))
378 (error "PDF file was not produced")
379 (set-window-configuration wconfig
)
380 (message "Exporting to PDF...done")
384 (defun org-export-as-docbook-pdf-and-open ()
385 "Export as DocBook XML file, generate PDF file, and open it."
387 (let ((pdffile (org-export-as-docbook-pdf)))
389 (org-open-file pdffile
)
390 (error "PDF file was not produced"))))
393 (defun org-export-as-docbook (&optional hidden ext-plist
394 to-buffer body-only pub-dir
)
395 "Export the current buffer as a DocBook file.
396 If there is an active region, export only the region. When
397 HIDDEN is obsolete and does nothing. EXT-PLIST is a
398 property list with external parameters overriding org-mode's
399 default settings, but still inferior to file-local settings.
400 When TO-BUFFER is non-nil, create a buffer with that name and
401 export to that buffer. If TO-BUFFER is the symbol `string',
402 don't leave any buffer behind but just return the resulting HTML
403 as a string. When BODY-ONLY is set, don't produce the file
404 header and footer, simply return the content of the document (all
405 top-level sections). When PUB-DIR is set, use this as the
406 publishing directory."
408 (run-hooks 'org-export-first-hook
)
410 ;; Make sure we have a file name when we need it.
411 (when (and (not (or to-buffer body-only
))
412 (not buffer-file-name
))
413 (if (buffer-base-buffer)
414 (org-set-local 'buffer-file-name
415 (with-current-buffer (buffer-base-buffer)
417 (error "Need a file name to be able to export")))
419 (message "Exporting...")
420 (setq-default org-todo-line-regexp org-todo-line-regexp
)
421 (setq-default org-deadline-line-regexp org-deadline-line-regexp
)
422 (setq-default org-done-keywords org-done-keywords
)
423 (setq-default org-maybe-keyword-time-regexp org-maybe-keyword-time-regexp
)
425 (org-export-process-option-filters
426 (org-combine-plists (org-default-export-plist)
428 (org-infile-export-plist))))
429 (link-validate (plist-get opt-plist
:link-validation-function
))
431 (odd org-odd-levels-only
)
432 (region-p (org-region-active-p))
433 (rbeg (and region-p
(region-beginning)))
434 (rend (and region-p
(region-end)))
436 (if (plist-get opt-plist
:ignore-subtree-p
)
441 (and (org-at-heading-p)
442 (>= (org-end-of-subtree t t
) rend
))))))
443 (level-offset (if subtree-p
446 (+ (funcall outline-level
)
447 (if org-odd-levels-only
1 0)))
449 (opt-plist (setq org-export-opt-plist
451 (org-export-add-subtree-options opt-plist rbeg
)
453 ;; The following two are dynamically scoped into other
455 (org-current-export-dir
456 (or pub-dir
(org-export-directory :docbook opt-plist
)))
457 (org-current-export-file buffer-file-name
)
458 (level 0) (line "") (origline "") txt todo
459 (filename (if to-buffer nil
462 (file-name-sans-extension
464 (org-entry-get (region-beginning)
465 "EXPORT_FILE_NAME" t
))
466 (file-name-nondirectory buffer-file-name
)))
467 org-export-docbook-extension
)
468 (file-name-as-directory
469 (or pub-dir
(org-export-directory :docbook opt-plist
))))))
470 (current-dir (if buffer-file-name
471 (file-name-directory buffer-file-name
)
473 (buffer (if to-buffer
475 ((eq to-buffer
'string
) (get-buffer-create "*Org DocBook Export*"))
476 (t (get-buffer-create to-buffer
)))
477 (find-file-noselect filename
)))
478 ;; org-levels-open is a global variable
479 (org-levels-open (make-vector org-level-max nil
))
480 (date (plist-get opt-plist
:date
))
481 (author (or (plist-get opt-plist
:author
)
483 (email (plist-get opt-plist
:email
))
484 firstname othername surname
485 (title (or (and subtree-p
(org-export-get-title-from-subtree))
486 (plist-get opt-plist
:title
)
488 (plist-get opt-plist
:skip-before-1st-heading
))
489 (org-export-grab-title-from-buffer))
490 (and buffer-file-name
491 (file-name-sans-extension
492 (file-name-nondirectory buffer-file-name
)))
494 ;; We will use HTML table formatter to export tables to DocBook
495 ;; format, so need to set html-table-tag here.
496 (html-table-tag (plist-get opt-plist
:html-table-tag
))
497 (quote-re0 (concat "^[ \t]*" org-quote-string
"\\>"))
498 (quote-re (concat "^\\(\\*+\\)\\([ \t]+" org-quote-string
"\\>\\)"))
502 (llt org-plain-list-ordered-item-terminator
)
503 (email (plist-get opt-plist
:email
))
504 (language (plist-get opt-plist
:language
))
508 (coding-system (and (boundp 'buffer-file-coding-system
)
509 buffer-file-coding-system
))
510 (coding-system-for-write (or org-export-docbook-coding-system
512 (save-buffer-coding-system (or org-export-docbook-coding-system
514 (charset (and coding-system-for-write
515 (fboundp 'coding-system-get
)
516 (coding-system-get coding-system-for-write
520 (if region-p
(region-beginning) (point-min))
521 (if region-p
(region-end) (point-max))))
522 (org-export-footnotes-markers nil
)
523 (org-export-footnotes-data (org-footnote-all-labels 'with-defs
))
526 (org-export-preprocess-string
529 :for-backend
'docbook
530 :skip-before-1st-heading
531 (plist-get opt-plist
:skip-before-1st-heading
)
532 :drawers
(plist-get opt-plist
:drawers
)
533 :todo-keywords
(plist-get opt-plist
:todo-keywords
)
534 :tasks
(plist-get opt-plist
:tasks
)
535 :tags
(plist-get opt-plist
:tags
)
536 :priority
(plist-get opt-plist
:priority
)
537 :footnotes
(plist-get opt-plist
:footnotes
)
538 :timestamps
(plist-get opt-plist
:timestamps
)
540 (plist-get opt-plist
:archived-trees
)
541 :select-tags
(plist-get opt-plist
:select-tags
)
542 :exclude-tags
(plist-get opt-plist
:exclude-tags
)
544 (plist-get opt-plist
:text
)
546 (plist-get opt-plist
:LaTeX-fragments
))
548 ;; Use literal output to show check boxes.
550 (nth 1 (assoc "=" org-export-docbook-emphasis-alist
)))
552 (nth 2 (assoc "=" org-export-docbook-emphasis-alist
)))
554 table-buffer table-orig-buffer
555 ind item-type starter
556 rpl path attr caption label desc descp desc1 desc2 link
557 fnc item-tag item-number
558 footref-seen footnote-list
562 ;; Fine detailed info about author name.
563 (if (string-match "\\([^ ]+\\) \\(.+ \\)?\\([^ ]+\\)" author
)
565 (setq firstname
(match-string 1 author
)
566 othername
(or (match-string 2 author
) "")
567 surname
(match-string 3 author
))))
569 ;; Get all footnote text.
571 (org-export-docbook-get-footnotes lines
))
573 (let ((inhibit-read-only t
))
575 (remove-text-properties (point-min) (point-max)
576 '(:org-license-to-kill t
))))
578 (setq org-min-level
(org-get-min-level lines level-offset
))
579 (setq org-last-level org-min-level
)
580 (org-init-section-numbers)
582 ;; Get and save the date.
584 ((and date
(string-match "%" date
))
585 (setq date
(format-time-string date
)))
587 (t (setq date
(format-time-string "%Y-%m-%d %T %Z"))))
589 ;; Get the language-dependent settings
590 (setq lang-words
(or (assoc language org-export-language-setup
)
591 (assoc "en" org-export-language-setup
)))
593 ;; Switch to the output buffer. Use fundamental-mode for now. We
594 ;; could turn on nXML mode later and do some indentation.
596 (let ((inhibit-read-only t
)) (erase-buffer))
598 (org-install-letbind)
600 (and (fboundp 'set-buffer-file-coding-system
)
601 (set-buffer-file-coding-system coding-system-for-write
))
604 (let ((case-fold-search nil
)
605 (org-odd-levels-only odd
))
607 ;; Create local variables for all options, to make sure all called
608 ;; functions get the correct information
610 (set (make-local-variable (nth 2 x
))
611 (plist-get opt-plist
(car x
))))
612 org-export-plist-vars
)
614 ;; Insert DocBook file header, title, and author info.
616 (insert org-export-docbook-header
)
617 (if org-export-docbook-doctype
618 (insert org-export-docbook-doctype
))
619 (insert "<!-- Date: " date
" -->\n")
620 (insert (format "<!-- DocBook XML file generated by Org-mode %s Emacs %s -->\n"
621 org-version emacs-major-version
))
622 (insert org-export-docbook-article-header
)
624 "\n <title>%s</title>
628 <firstname>%s</firstname> <othername>%s</othername> <surname>%s</surname>
633 (org-docbook-expand title
)
634 firstname othername surname
635 (if (and org-export-email-info
636 email
(string-match "\\S-" email
))
637 (concat "<email>" email
"</email>") "")
640 (org-init-section-numbers)
642 (org-export-docbook-open-para)
644 ;; Loop over all the lines...
645 (while (setq line
(pop lines
) origline line
)
648 ;; End of quote section?
649 (when (and inquote
(string-match "^\\*+ " line
))
650 (insert "]]></programlisting>\n")
651 (org-export-docbook-open-para)
653 ;; Inside a quote section?
655 (insert (org-docbook-protect line
) "\n")
656 (throw 'nextline nil
))
658 ;; Fixed-width, verbatim lines (examples)
659 (when (and org-export-with-fixed-width
660 (string-match "^[ \t]*:\\(\\([ \t]\\|$\\)\\(.*\\)\\)" line
))
663 (org-export-docbook-close-para-maybe)
664 (insert "<programlisting><![CDATA["))
665 (insert (match-string 3 line
) "\n")
666 (when (or (not lines
)
667 (not (string-match "^[ \t]*\\(:.*\\)"
670 (insert "]]></programlisting>\n")
671 (org-export-docbook-open-para))
672 (throw 'nextline nil
))
675 (when (get-text-property 0 'org-protected line
)
676 (let (par (ind (get-text-property 0 'original-indentation line
)))
677 (when (re-search-backward
678 "\\(<para>\\)\\([ \t\r\n]*\\)\\=" (- (point) 100) t
)
679 (setq par
(match-string 1))
680 (replace-match "\\2\n"))
683 (or (= (length (car lines
)) 0)
685 (equal ind
(get-text-property 0 'original-indentation
(car lines
))))
686 (or (= (length (car lines
)) 0)
687 (get-text-property 0 'org-protected
(car lines
))))
688 (insert (pop lines
) "\n"))
689 (and par
(insert "<para>\n")))
690 (throw 'nextline nil
))
692 ;; Start of block quotes and verses
693 (when (or (equal "ORG-BLOCKQUOTE-START" line
)
694 (and (equal "ORG-VERSE-START" line
)
696 (org-export-docbook-close-para-maybe)
697 (insert "<blockquote>")
698 ;; Check whether attribution for this blockquote exists.
701 (end (if inverse
"ORG-VERSE-END" "ORG-BLOCKQUOTE-END"))
703 (while (and (setq tmp1
(pop lines
))
704 (not (equal end tmp1
)))
705 (push tmp1 quote-lines
))
706 (push tmp1 lines
) ; Put back quote end mark
707 ;; Check the last line in the quote to see if it contains
709 (setq tmp1
(pop quote-lines
))
710 (if (string-match "\\(^.*\\)\\(--[ \t]+\\)\\(.+\\)$" tmp1
)
712 (setq attribution
(match-string 3 tmp1
))
713 (when (save-match-data
714 (string-match "[^ \t]" (match-string 1 tmp1
)))
715 (push (match-string 1 tmp1
) lines
)))
717 (while (setq tmp1
(pop quote-lines
))
720 (insert "<attribution>" attribution
"</attribution>")))
721 ;; Insert <literallayout> for verse.
723 (insert "\n<literallayout>")
724 (org-export-docbook-open-para))
725 (throw 'nextline nil
))
727 ;; End of block quotes
728 (when (equal "ORG-BLOCKQUOTE-END" line
)
729 (org-export-docbook-close-para-maybe)
730 (insert "</blockquote>\n")
731 (org-export-docbook-open-para)
732 (throw 'nextline nil
))
735 (when (equal "ORG-VERSE-END" line
)
736 (insert "</literallayout>\n</blockquote>\n")
737 (org-export-docbook-open-para)
739 (throw 'nextline nil
))
741 ;; Text centering. Element <para role="centered"> does not
742 ;; seem to work with FOP, so for now we use <informaltable> to
743 ;; center the text, which can contain multiple paragraphs.
744 (when (equal "ORG-CENTER-START" line
)
745 (org-export-docbook-close-para-maybe)
746 (insert "<informaltable frame=\"none\" colsep=\"0\" rowsep=\"0\">\n"
747 "<tgroup align=\"center\" cols=\"1\">\n"
748 "<tbody><row><entry>\n")
749 (org-export-docbook-open-para)
750 (throw 'nextline nil
))
752 (when (equal "ORG-CENTER-END" line
)
753 (org-export-docbook-close-para-maybe)
754 (insert "</entry></row></tbody>\n"
755 "</tgroup>\n</informaltable>\n")
756 (org-export-docbook-open-para)
757 (throw 'nextline nil
))
759 ;; Make targets to anchors. Note that currently FOP does not
760 ;; seem to support <anchor> tags when generating PDF output,
761 ;; but this can be used in DocBook --> HTML conversion.
764 "<<<?\\([^<>]*\\)>>>?\\((INVISIBLE)\\)?[ \t]*\n?" line start
)
766 ((get-text-property (match-beginning 1) 'org-protected line
)
767 (setq start
(match-end 1)))
769 (setq line
(replace-match
770 (format "@<anchor xml:id=\"%s\"/>"
771 (org-solidify-link-text (match-string 1 line
)))
774 (setq line
(replace-match
775 (format "@<anchor xml:id=\"%s\"/>"
776 (org-solidify-link-text (match-string 1 line
)))
779 ;; Put time stamps and related keywords into special mark-up
781 (setq line
(org-export-docbook-handle-time-stamps line
))
783 ;; Replace "&", "<" and ">" by "&", "<" and ">".
784 ;; Handle @<..> HTML tags (replace "@>..<" by "<..>").
785 ;; Also handle sub_superscripts and check boxes.
786 (or (string-match org-table-hline-regexp line
)
787 (setq line
(org-docbook-expand line
)))
791 (while (string-match org-bracket-link-analytic-regexp
++ line start
)
792 (setq start
(match-beginning 0))
793 (setq path
(save-match-data (org-link-unescape
794 (match-string 3 line
))))
796 ((match-end 2) (match-string 2 line
))
798 (or (file-name-absolute-p path
)
799 (string-match "^\\.\\.?/" path
)))
802 (setq path
(org-extract-attributes (org-link-unescape path
)))
803 (setq attr
(get-text-property 0 'org-attributes path
)
804 caption
(get-text-property 0 'org-caption path
)
805 label
(get-text-property 0 'org-label path
))
806 (setq desc1
(if (match-end 5) (match-string 5 line
))
807 desc2
(if (match-end 2) (concat type
":" path
) path
)
808 descp
(and desc1
(not (equal desc1 desc2
)))
809 desc
(or desc1 desc2
))
810 ;; Make an image out of the description if that is so wanted
811 (when (and descp
(org-file-image-p
812 desc org-export-docbook-inline-image-extensions
))
814 (if (string-match "^file:" desc
)
815 (setq desc
(substring desc
(match-end 0))))))
816 ;; FIXME: do we need to unescape here somewhere?
818 ((equal type
"internal")
819 (setq rpl
(format "<link linkend=\"%s\">%s</link>"
820 (org-solidify-link-text
821 (save-match-data (org-link-unescape path
)) nil
)
822 (org-export-docbook-format-desc desc
))))
823 ((and (equal type
"id")
824 (setq id-file
(org-id-find-id-file path
)))
825 ;; This is an id: link to another file (if it was the same file,
826 ;; it would have become an internal link...)
828 (setq id-file
(file-relative-name
829 id-file
(file-name-directory org-current-export-file
)))
830 (setq id-file
(concat (file-name-sans-extension id-file
)
831 org-export-docbook-extension
))
832 (setq rpl
(format "<link xlink:href=\"%s#%s\">%s</link>"
833 id-file path
(org-export-docbook-format-desc desc
)))))
834 ((member type
'("http" "https"))
835 ;; Standard URL, just check if we need to inline an image
836 (if (and (or (eq t org-export-docbook-inline-images
)
837 (and org-export-docbook-inline-images
(not descp
)))
839 path org-export-docbook-inline-image-extensions
))
840 (setq rpl
(org-export-docbook-format-image
841 (concat type
":" path
)))
842 (setq link
(concat type
":" path
))
843 (setq rpl
(format "<link xlink:href=\"%s\">%s</link>"
844 (org-export-html-format-href link
)
845 (org-export-docbook-format-desc desc
)))
847 ((member type
'("ftp" "mailto" "news"))
849 (setq link
(concat type
":" path
))
850 (setq rpl
(format "<link xlink:href=\"%s\">%s</link>"
851 (org-export-html-format-href link
)
852 (org-export-docbook-format-desc desc
))))
853 ((string= type
"coderef")
854 (setq rpl
(format (org-export-get-coderef-format path
(and descp desc
))
855 (cdr (assoc path org-export-code-refs
)))))
856 ((functionp (setq fnc
(nth 2 (assoc type org-link-protocols
))))
857 ;; The link protocol has a function for format the link
860 (funcall fnc
(org-link-unescape path
) desc1
'html
))))
862 ((string= type
"file")
864 (let* ((filename path
)
865 (abs-p (file-name-absolute-p filename
))
866 thefile file-is-image-p search
)
868 (if (string-match "::\\(.*\\)" filename
)
869 (setq search
(match-string 1 filename
)
870 filename
(replace-match "" t nil filename
)))
872 (if (functionp link-validate
)
873 (funcall link-validate filename current-dir
)
875 (setq file-is-image-p
877 filename org-export-docbook-inline-image-extensions
))
878 (setq thefile
(if abs-p
(expand-file-name filename
) filename
))
879 ;; Carry over the properties (expand-file-name will
880 ;; discard the properties of filename)
881 (add-text-properties 0 (1- (length thefile
))
882 (list 'org-caption caption
886 (when (and org-export-docbook-link-org-files-as-docbook
887 (string-match "\\.org$" thefile
))
888 (setq thefile
(concat (substring thefile
0
890 org-export-docbook-extension
))
892 ;; make sure this is can be used as target search
893 (not (string-match "^[0-9]*$" search
))
894 (not (string-match "^\\*" search
))
895 (not (string-match "^/.*/$" search
)))
896 (setq thefile
(concat thefile
"#"
897 (org-solidify-link-text
898 (org-link-unescape search
)))))
899 (when (string-match "^file:" desc
)
900 (setq desc
(replace-match "" t t desc
))
901 (if (string-match "\\.org$" desc
)
902 (setq desc
(replace-match "" t t desc
))))))
903 (setq rpl
(if (and file-is-image-p
904 (or (eq t org-export-docbook-inline-images
)
905 (and org-export-docbook-inline-images
908 (message "image %s %s" thefile org-docbook-para-open
)
909 (org-export-docbook-format-image thefile
))
910 (format "<link xlink:href=\"%s\">%s</link>"
911 thefile
(org-export-docbook-format-desc desc
))))
912 (if (not valid
) (setq rpl desc
))))
915 ;; Just publish the path, as default
916 (setq rpl
(concat "<" type
":"
917 (save-match-data (org-link-unescape path
))
919 (setq line
(replace-match rpl t t line
)
920 start
(+ start
(length rpl
))))
922 ;; TODO items: can we do something better?!
923 (if (and (string-match org-todo-line-regexp line
)
926 (concat (substring line
0 (match-beginning 2))
927 "[" (match-string 2 line
) "]"
928 (substring line
(match-end 2)))))
930 ;; Does this contain a reference to a footnote?
931 (when org-export-with-footnotes
933 (while (string-match "\\([^* \t].*?\\)\\[\\([0-9]+\\)\\]" line start
)
934 (if (get-text-property (match-beginning 2) 'org-protected line
)
935 (setq start
(match-end 2))
936 (let* ((num (match-string 2 line
))
937 (footnote-def (assoc num footnote-list
)))
938 (if (assoc num footref-seen
)
939 (setq line
(replace-match
940 (format "%s<footnoteref linkend=\"%s%s\"/>"
941 (match-string 1 line
)
942 org-export-docbook-footnote-id-prefix num
)
944 (setq line
(replace-match
945 (format "%s<footnote xml:id=\"%s%s\"><para>%s</para></footnote>"
946 (match-string 1 line
)
947 org-export-docbook-footnote-id-prefix
951 (org-docbook-expand (cdr footnote-def
)))
952 (format "FOOTNOTE DEFINITION NOT FOUND: %s" num
)))
954 (push (cons num
1) footref-seen
))))))
957 ((string-match "^\\(\\*+\\)[ \t]+\\(.*\\)" line
)
958 ;; This is a headline
959 (setq level
(org-tr-level (- (match-end 1) (match-beginning 1)
961 txt
(match-string 2 line
))
962 (if (string-match quote-re0 txt
)
963 (setq txt
(replace-match "" t t txt
)))
964 (org-export-docbook-level-start level txt
)
966 (when (string-match quote-re line
)
967 (org-export-docbook-close-para-maybe)
968 (insert "<programlisting><![CDATA[")
971 ;; Tables: since version 4.3 of DocBook DTD, HTML tables are
972 ;; supported. We can use existing HTML table exporter code
974 ((and org-export-with-tables
975 (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)" line
))
980 table-orig-buffer nil
))
982 (setq table-buffer
(cons line table-buffer
)
983 table-orig-buffer
(cons origline table-orig-buffer
))
984 (when (or (not lines
)
985 (not (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)"
988 table-buffer
(nreverse table-buffer
)
989 table-orig-buffer
(nreverse table-orig-buffer
))
990 (org-export-docbook-close-para-maybe)
991 (insert (org-export-docbook-finalize-table
992 (org-format-table-html table-buffer table-orig-buffer
997 ;; This line either is list item or end a list.
998 (when (when (get-text-property 0 'list-item line
)
999 (setq line
(org-export-docbook-list-line
1001 (get-text-property 0 'list-item line
)
1002 (get-text-property 0 'list-struct line
)
1003 (get-text-property 0 'list-prevs line
)))))
1005 ;; Empty lines start a new paragraph. If hand-formatted lists
1006 ;; are not fully interpreted, lines starting with "-", "+", "*"
1007 ;; also start a new paragraph.
1008 (if (and (string-match "^ [-+*]-\\|^[ \t]*$" line
)
1010 (org-export-docbook-open-para))
1012 ;; Is this the start of a footnote?
1013 (when org-export-with-footnotes
1014 (when (and (boundp 'footnote-section-tag-regexp
)
1015 (string-match (concat "^" footnote-section-tag-regexp
)
1018 (throw 'nextline nil
))
1019 ;; These footnote lines have been read and saved before,
1020 ;; ignore them at this time.
1021 (when (string-match "^[ \t]*\\[\\([0-9]+\\)\\]" line
)
1022 (org-export-docbook-close-para-maybe)
1023 (throw 'nextline nil
)))
1025 ;; FIXME: It might be a good idea to add an option to
1026 ;; support line break processing instruction <?linebreak?>.
1027 ;; Org-mode supports line break "\\" in HTML exporter, and
1028 ;; some DocBook users may also want to force line breaks
1029 ;; even though DocBook only supports that in
1032 (insert line
"\n")))))
1034 ;; Properly close all local lists and other lists
1036 (insert "]]></programlisting>\n")
1037 (org-export-docbook-open-para))
1039 ;; Close all open sections.
1040 (org-export-docbook-level-start 1 nil
)
1042 (unless (plist-get opt-plist
:buffer-will-be-killed
)
1044 (if (eq major-mode
(default-value 'major-mode
))
1047 ;; Remove empty paragraphs. Replace them with a newline.
1048 (goto-char (point-min))
1049 (while (re-search-forward
1050 "[ \r\n\t]*\\(<para>\\)[ \r\n\t]*</para>[ \r\n\t]*" nil t
)
1051 (when (not (get-text-property (match-beginning 1) 'org-protected
))
1052 (replace-match "\n")
1054 ;; Fill empty sections with <para></para>. This is to make sure
1055 ;; that the DocBook document generated is valid and well-formed.
1056 (goto-char (point-min))
1057 (while (re-search-forward
1058 "</title>\\([ \r\n\t]*\\)</section>" nil t
)
1059 (when (not (get-text-property (match-beginning 0) 'org-protected
))
1060 (replace-match "\n<para></para>\n" nil nil nil
1)))
1061 ;; Insert the last closing tag.
1062 (goto-char (point-max))
1064 (insert "</article>"))
1065 (run-hooks 'org-export-docbook-final-hook
)
1066 (or to-buffer
(save-buffer))
1067 (goto-char (point-min))
1068 (or (org-export-push-to-kill-ring "DocBook")
1069 (message "Exporting... done"))
1070 (if (eq to-buffer
'string
)
1071 (prog1 (buffer-substring (point-min) (point-max))
1072 (kill-buffer (current-buffer)))
1073 (current-buffer)))))
1075 (defun org-export-docbook-open-para ()
1076 "Insert <para>, but first close previous paragraph if any."
1077 (org-export-docbook-close-para-maybe)
1079 (setq org-docbook-para-open t
))
1081 (defun org-export-docbook-close-para-maybe ()
1082 "Close DocBook paragraph if there is one open."
1083 (when org-docbook-para-open
1084 (insert "</para>\n")
1085 (setq org-docbook-para-open nil
)))
1087 (defun org-export-docbook-close-li (&optional type
)
1088 "Close list if necessary."
1089 (org-export-docbook-close-para-maybe)
1090 (if (equal type
"d")
1091 (insert "</listitem></varlistentry>\n")
1092 (insert "</listitem>\n")))
1094 (defun org-export-docbook-level-start (level title
)
1095 "Insert a new level in DocBook export.
1096 When TITLE is nil, just close all open levels."
1097 (org-export-docbook-close-para-maybe)
1098 (let* ((target (and title
(org-get-text-property-any 0 'target title
)))
1102 (if (aref org-levels-open
(1- l
))
1104 (insert "</section>\n")
1105 (aset org-levels-open
(1- l
) nil
)))
1108 ;; If title is nil, this means this function is called to close
1109 ;; all levels, so the rest is done only if title is given.
1111 ;; Format tags: put them into a superscript like format.
1112 (when (string-match (org-re "\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$") title
)
1115 (if org-export-with-tags
1119 (match-string 1 title
)
1123 (aset org-levels-open
(1- level
) t
)
1124 (setq section-number
(org-section-number level
))
1125 (insert (format "\n<section xml:id=\"%s%s\">\n<title>%s</title>"
1126 org-export-docbook-section-id-prefix
1127 (replace-regexp-in-string "\\." "_" section-number
)
1129 (org-export-docbook-open-para))))
1131 (defun org-docbook-expand (string)
1132 "Prepare STRING for DocBook export.
1133 Applies all active conversions. If there are links in the
1134 string, don't modify these."
1135 (let* ((re (concat org-bracket-link-regexp
"\\|"
1136 (org-re "[ \t]+\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")))
1138 (while (setq m
(string-match re string
))
1139 (setq s
(substring string
0 m
)
1140 l
(match-string 0 string
)
1141 string
(substring string
(match-end 0)))
1142 (push (org-docbook-do-expand s
) res
)
1144 (push (org-docbook-do-expand string
) res
)
1145 (apply 'concat
(nreverse res
))))
1147 (defun org-docbook-do-expand (s)
1148 "Apply all active conversions to translate special ASCII to DocBook."
1149 (setq s
(org-html-protect s
))
1150 (while (string-match "@<\\([^&]*\\)>" s
)
1151 (setq s
(replace-match "<\\1>" t nil s
)))
1152 (if org-export-with-emphasize
1153 (setq s
(org-export-docbook-convert-emphasize s
)))
1154 (if org-export-with-special-strings
1155 (setq s
(org-export-docbook-convert-special-strings s
)))
1156 (if org-export-with-sub-superscripts
1157 (setq s
(org-export-docbook-convert-sub-super s
)))
1158 (if org-export-with-TeX-macros
1159 (let ((start 0) wd rep
)
1160 (while (setq start
(string-match "\\\\\\([a-zA-Z]+\\)\\({}\\)?"
1162 (if (get-text-property (match-beginning 0) 'org-protected s
)
1163 (setq start
(match-end 0))
1164 (setq wd
(match-string 1 s
))
1165 (if (setq rep
(org-entity-get-representation wd
'html
))
1166 (setq s
(replace-match rep t t s
))
1167 (setq start
(+ start
(length wd
))))))))
1170 (defun org-export-docbook-format-desc (desc)
1171 "Make sure DESC is valid as a description in a link."
1173 (org-docbook-do-expand desc
)))
1175 (defun org-export-docbook-convert-emphasize (string)
1176 "Apply emphasis for DocBook exporting."
1178 (while (string-match org-emph-re string s
)
1180 (substring string
(match-beginning 3) (1+ (match-beginning 3)))
1181 (substring string
(match-beginning 4) (1+ (match-beginning 4)))))
1182 (setq s
(match-beginning 0)
1185 (match-string 1 string
)
1186 (nth 1 (assoc (match-string 3 string
)
1187 org-export-docbook-emphasis-alist
))
1188 (match-string 4 string
)
1189 (nth 2 (assoc (match-string 3 string
)
1190 org-export-docbook-emphasis-alist
))
1191 (match-string 5 string
))
1192 string
(replace-match rpl t t string
)
1193 s
(+ s
(- (length rpl
) 2)))
1197 (defun org-docbook-protect (string)
1198 (org-html-protect string
))
1200 ;; For now, simply return string as it is.
1201 (defun org-export-docbook-convert-special-strings (string)
1202 "Convert special characters in STRING to DocBook."
1205 (defun org-export-docbook-get-footnotes (lines)
1206 "Given a list of LINES, return a list of alist footnotes."
1207 (let ((list nil
) line
)
1208 (while (setq line
(pop lines
))
1209 (if (string-match "^[ \t]*\\[\\([0-9]+\\)\\] \\(.+\\)" line
)
1210 (push (cons (match-string 1 line
) (match-string 2 line
))
1214 (defun org-export-docbook-format-image (src)
1215 "Create image element in DocBook."
1217 (let* ((caption (org-find-text-property-in-string 'org-caption src
))
1218 (attr (or (org-find-text-property-in-string 'org-attributes src
)
1220 (label (org-find-text-property-in-string 'org-label src
))
1221 (default-attr org-export-docbook-default-image-attributes
)
1223 (setq caption
(and caption
(org-html-do-expand caption
)))
1224 (while (setq tmp
(pop default-attr
))
1225 (if (not (string-match (concat (car tmp
) "=") attr
))
1226 (setq attr
(concat attr
" " (car tmp
) "=" (cdr tmp
)))))
1227 (format "<mediaobject%s>
1228 <imageobject>\n<imagedata fileref=\"%s\" %s/>\n</imageobject>
1230 (if label
(concat " xml:id=\"" label
"\"") "")
1233 (concat "<caption>\n<para>"
1235 "</para>\n</caption>\n")
1239 (defun org-export-docbook-preprocess (parameters)
1240 "Extra preprocessing work for DocBook export."
1241 ;; Merge lines starting with "\par" to one line. Such lines are
1242 ;; regarded as the continuation of a long footnote.
1243 (goto-char (point-min))
1244 (while (re-search-forward "\n\\(\\\\par\\>\\)" nil t
)
1245 (if (not (get-text-property (match-beginning 1) 'org-protected
))
1246 (replace-match ""))))
1248 (defun org-export-docbook-finalize-table (table)
1249 "Clean up TABLE and turn it into DocBook format.
1250 This function adds a label to the table if it is available, and
1251 also changes TABLE to informaltable if caption does not exist.
1252 TABLE is a string containing the HTML code generated by
1253 `org-format-table-html' for a table in Org-mode buffer."
1254 (let (table-with-label)
1255 ;; Get the label if it exists, and move it into the <table> element.
1256 (setq table-with-label
1258 "^<table \\(\\(.\\|\n\\)+\\)<a name=\"\\(.+\\)\" id=\".+\"></a>\n\\(\\(.\\|\n\\)+\\)</table>"
1260 (replace-match (concat "<table xml:id=\"" (match-string 3 table
) "\" "
1261 (match-string 1 table
)
1262 (match-string 4 table
)
1266 ;; Change <table> into <informaltable> if caption does not exist.
1268 "^<table \\(\\(.\\|\n\\)+\\)<caption></caption>\n\\(\\(.\\|\n\\)+\\)</table>"
1270 (replace-match (concat "<informaltable "
1271 (match-string 1 table-with-label
)
1272 (match-string 3 table-with-label
)
1274 nil t table-with-label
)
1277 ;; Note: This function is very similar to
1278 ;; org-export-html-convert-sub-super. They can be merged in the future.
1279 (defun org-export-docbook-convert-sub-super (string)
1280 "Convert sub- and superscripts in STRING for DocBook."
1281 (let (key c
(s 0) (requireb (eq org-export-with-sub-superscripts
'{})))
1282 (while (string-match org-match-substring-regexp string s
)
1284 ((and requireb
(match-end 8)) (setq s
(match-end 2)))
1285 ((get-text-property (match-beginning 2) 'org-protected string
)
1286 (setq s
(match-end 2)))
1288 (setq s
(match-end 1)
1289 key
(if (string= (match-string 2 string
) "_")
1292 c
(or (match-string 8 string
)
1293 (match-string 6 string
)
1294 (match-string 5 string
))
1295 string
(replace-match
1296 (concat (match-string 1 string
)
1297 "<" key
">" c
"</" key
">")
1299 (while (string-match "\\\\\\([_^]\\)" string
)
1300 (setq string
(replace-match (match-string 1 string
) t t string
)))
1303 (defun org-export-docbook-protect-tags (string)
1304 "Change ``<...>'' in string STRING into ``@<...>''.
1305 This is normally needed when STRING contains DocBook elements
1306 that need to be preserved in later phase of DocBook exporting."
1308 (while (string-match "<\\([^>]*\\)>" string start
)
1309 (setq string
(replace-match
1310 "@<\\1>" t nil string
)
1311 start
(match-end 0)))
1314 (defun org-export-docbook-handle-time-stamps (line)
1315 "Format time stamps in string LINE."
1317 (kw-markup (org-export-docbook-protect-tags
1318 org-export-docbook-keywords-markup
))
1319 (ts-markup (org-export-docbook-protect-tags
1320 org-export-docbook-timestamp-markup
)))
1321 (while (string-match org-maybe-keyword-time-regexp line
)
1324 (substring line
0 (match-beginning 0))
1327 (match-string 1 line
)))
1330 (substring (org-translate-time
1331 (match-string 3 line
)) 1 -
1)))
1332 line
(substring line
(match-end 0))))
1333 (concat replaced line
)))
1335 (defun org-export-docbook-list-line (line pos struct prevs
)
1336 "Insert list syntax in export buffer. Return LINE, maybe modified.
1338 POS is the item position or line position the line had before
1339 modifications to buffer. STRUCT is the list structure. PREVS is
1340 the alist of previous items."
1343 ;; Translate type of list containing POS to "ordered",
1344 ;; "variable" or "itemized".
1345 (lambda (pos struct prevs
)
1346 (let ((type (org-list-get-list-type pos struct prevs
)))
1348 ((eq 'ordered type
) "ordered")
1349 ((eq 'descriptive type
) "variable")
1353 ;; Return list of all items and sublists ending at POS, in
1359 (let ((end (nth 6 e
))
1362 ((= end pos
) (push item out
))
1363 ((>= item pos
) (throw 'exit nil
)))))
1366 ;; First close any previous item, or list, ending at POS.
1368 (let* ((lastp (= (org-list-get-last-item e struct prevs
) e
))
1369 (first-item (org-list-get-list-begin e struct prevs
))
1370 (type (funcall get-type first-item struct prevs
)))
1371 ;; Ending for every item
1372 (org-export-docbook-close-para-maybe)
1373 (insert (if (equal type
"variable")
1374 "</listitem></varlistentry>\n"
1376 ;; We're ending last item of the list: end list.
1378 (insert (format "</%slist>\n" type
))
1379 (org-export-docbook-open-para))))
1380 (funcall get-closings pos
))
1382 ;; At an item: insert appropriate tags in export buffer.
1384 (string-match (concat "[ \t]*\\(\\S-+[ \t]*\\)"
1385 "\\(?:\\[@\\(?:start:\\)?\\([0-9]+\\|[a-zA-Z]\\)\\]\\)?"
1386 "\\(?:\\(\\[[ X-]\\]\\)[ \t]+\\)?"
1387 "\\(?:\\(.*\\)[ \t]+::\\(?:[ \t]+\\|$\\)\\)?"
1390 (let* ((checkbox (match-string 3 line
))
1391 (desc-tag (or (match-string 4 line
) "???"))
1392 (body (match-string 5 line
))
1393 (list-beg (org-list-get-list-begin pos struct prevs
))
1394 (firstp (= list-beg pos
))
1395 ;; Always refer to first item to determine list type, in
1396 ;; case list is ill-formed.
1397 (type (funcall get-type list-beg struct prevs
))
1398 ;; Special variables for ordered lists.
1399 (counter (let ((count-tmp (org-list-get-counter pos struct
)))
1401 ((not count-tmp
) nil
)
1402 ((string-match "[A-Za-z]" count-tmp
)
1403 (- (string-to-char (upcase count-tmp
)) 64))
1404 ((string-match "[0-9]+" count-tmp
)
1406 ;; When FIRSTP, a new list or sub-list is starting.
1408 (org-export-docbook-close-para-maybe)
1409 (insert (format "<%slist>\n" type
)))
1411 ((equal type
"variable")
1412 (format "<varlistentry><term>%s</term><listitem>" desc-tag
))
1413 ((and (equal type
"ordered") counter
)
1414 (format "<listitem override=\"%s\">" counter
))
1416 ;; For DocBook, we need to open a para right after tag
1418 (org-export-docbook-open-para)
1419 ;; If line had a checkbox, some additional modification is required.
1420 (when checkbox
(setq body
(concat checkbox
" " body
)))
1421 ;; Return modified line
1423 ;; At a list ender: normal text follows: need <para>.
1424 ((equal "ORG-LIST-END-MARKER" line
)
1425 (org-export-docbook-open-para)
1426 (throw 'nextline nil
))
1427 ;; Not at an item: return line unchanged (side-effects only).
1430 (provide 'org-docbook
)
1432 ;; arch-tag: a24a127c-d365-4c2a-9e9b-f7dcb0ebfdc3
1433 ;;; org-docbook.el ends here