1 ;;; org-docbook.el --- DocBook exporter for org-mode
3 ;; Copyright (C) 2007, 2008, 2009 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
12 ;; $Id: org-docbook.el 35 2009-03-23 01:03:21Z baoqiu $
15 ;; This file is NOT part of GNU Emacs.
17 ;; GNU Emacs is free software: you can redistribute it and/or modify
18 ;; it under the terms of the GNU General Public License as published by
19 ;; the Free Software Foundation, either version 3 of the License, or
20 ;; (at your option) any later version.
22 ;; GNU Emacs is distributed in the hope that it will be useful,
23 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
24 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 ;; GNU General Public License for more details.
27 ;; You should have received a copy of the GNU General Public License
28 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
32 ;; This library implements a DocBook exporter for org-mode. The basic
33 ;; idea and design is very similar to what `org-export-as-html' has.
34 ;; Code prototype was also started with `org-export-as-html'.
36 ;; Put this file into your load-path and the following line into your
39 ;; (require 'org-docbook)
41 ;; The interactive functions are similar to those of the HTML and LaTeX
44 ;; M-x `org-export-as-docbook'
45 ;; M-x `org-export-as-docbook-pdf'
46 ;; M-x `org-export-as-docbook-pdf-and-open'
47 ;; M-x `org-export-as-docbook-batch'
48 ;; M-x `org-export-as-docbook-to-buffer'
49 ;; M-x `org-export-region-as-docbook'
50 ;; M-x `org-replace-region-by-docbook'
52 ;; Note that, in order to generate PDF files using the DocBook XML files
53 ;; created by DocBook exporter, the following two variables have to be
54 ;; set based on what DocBook tools you use for XSLT processor and XSL-FO
57 ;; org-export-docbook-xslt-proc-command
58 ;; org-export-docbook-xsl-fo-proc-command
60 ;; Check the document of these two variables to see examples of how they
63 ;; If the Org file to be exported contains special characters written in
64 ;; TeX-like syntax, like \alpha and \beta, you need to include the right
65 ;; entity file(s) in the DOCTYPE declaration for the DocBook XML file.
66 ;; This is required to make the DocBook XML file valid. The DOCTYPE
67 ;; declaration string can be set using the following variable:
69 ;; org-export-docbook-doctype
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 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. Like
146 `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 "Alist 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-proc-command nil
188 "XSLT processor command used by DocBook exporter.
189 This is the command used to process a DocBook XML file to
190 generate the formatting object (FO) file.
192 The value of this variable should be a format control string that
193 includes two `%s' arguments: the first one is for the output FO
194 file name, and the second one is for the input DocBook XML file
197 For example, if you use Saxon as the XSLT processor, you may want
198 to set the variable to
200 \"java com.icl.saxon.StyleSheet -o %s %s /path/to/docbook.xsl\"
202 If you use Xalan, you can set it to
204 \"java org.apache.xalan.xslt.Process -out %s -in %s -xsl /path/to/docbook.xsl\"
206 For xsltproc, the following string should work:
208 \"xsltproc --output %s /path/to/docbook.xsl %s\"
210 You need to replace \"/path/to/docbook.xsl\" with the actual path
211 to the DocBook stylesheet file on your machine. You can also
212 replace it with your own customization layer if you have one.
214 You can include additional stylesheet parameters in this command.
215 Just make sure that they meet the syntax requirement of each
217 :group
'org-export-docbook
220 (defcustom org-export-docbook-xsl-fo-proc-command nil
221 "XSL-FO processor command used by DocBook exporter.
222 This is the command used to process a formatting object (FO) file
223 to generate the PDF file.
225 The value of this variable should be a format control string that
226 includes two `%s' arguments: the first one is for the input FO
227 file name, and the second one is for the output PDF file name.
229 For example, if you use FOP as the XSL-FO processor, you can set
233 :group
'org-export-docbook
236 (defcustom org-export-docbook-keywords-markup
"<literal>%s</literal>"
237 "A printf format string to be applied to keywords by DocBook exporter."
238 :group
'org-export-docbook
241 (defcustom org-export-docbook-timestamp-markup
"<emphasis>%s</emphasis>"
242 "A printf format string to be applied to time stamps by DocBook exporter."
243 :group
'org-export-docbook
246 ;;; Autoload functions:
249 (defun org-export-as-docbook-batch ()
250 "Call `org-export-as-docbook' in batch style.
251 This function can be used in batch processing.
256 --load=$HOME/lib/emacs/org.el
257 --visit=MyOrgFile.org --funcall org-export-as-docbook-batch"
258 (org-export-as-docbook 'hidden
))
261 (defun org-export-as-docbook-to-buffer ()
262 "Call `org-export-as-docbook' with output to a temporary buffer.
265 (org-export-as-docbook nil nil
"*Org DocBook Export*")
266 (when org-export-show-temporary-export-buffer
267 (switch-to-buffer-other-window "*Org DocBook Export*")))
270 (defun org-replace-region-by-docbook (beg end
)
271 "Replace the region from BEG to END with its DocBook export.
272 It assumes the region has `org-mode' syntax, and then convert it to
273 DocBook. This can be used in any buffer. For example, you could
274 write an itemized list in `org-mode' syntax in an DocBook buffer and
275 then use this command to convert it."
277 (let (reg docbook buf
)
278 (save-window-excursion
280 (setq docbook
(org-export-region-as-docbook
282 (setq reg
(buffer-substring beg end
)
283 buf
(get-buffer-create "*Org tmp*"))
289 (setq docbook
(org-export-region-as-docbook
290 (point-min) (point-max) t
'string
)))
292 (delete-region beg end
)
296 (defun org-export-region-as-docbook (beg end
&optional body-only buffer
)
297 "Convert region from BEG to END in `org-mode' buffer to DocBook.
298 If prefix arg BODY-ONLY is set, omit file header and footer and
299 only produce the region of converted text, useful for
300 cut-and-paste operations. If BUFFER is a buffer or a string,
301 use/create that buffer as a target of the converted DocBook. If
302 BUFFER is the symbol `string', return the produced DocBook as a
303 string and leave not buffer behind. For example, a Lisp program
304 could call this function in the following way:
306 (setq docbook (org-export-region-as-docbook beg end t 'string))
308 When called interactively, the output buffer is selected, and shown
309 in a window. A non-interactive call will only return the buffer."
311 (when (interactive-p)
312 (setq buffer
"*Org DocBook Export*"))
313 (let ((transient-mark-mode t
)
317 (set-mark (point)) ;; To activate the region
319 (setq rtn
(org-export-as-docbook
322 (if (fboundp 'deactivate-mark
) (deactivate-mark))
323 (if (and (interactive-p) (bufferp rtn
))
324 (switch-to-buffer-other-window rtn
)
328 (defun org-export-as-docbook-pdf (&optional hidden ext-plist
329 to-buffer body-only pub-dir
)
330 "Export as DocBook XML file, and generate PDF file."
332 (if (or (not org-export-docbook-xslt-proc-command
)
333 (not (string-match "%s.+%s" org-export-docbook-xslt-proc-command
)))
334 (error "XSLT processor command is not set correctly"))
335 (if (or (not org-export-docbook-xsl-fo-proc-command
)
336 (not (string-match "%s.+%s" org-export-docbook-xsl-fo-proc-command
)))
337 (error "XSL-FO processor command is not set correctly"))
338 (message "Exporting to PDF...")
339 (let* ((wconfig (current-window-configuration))
340 (docbook-buf (org-export-as-docbook hidden ext-plist
341 to-buffer body-only pub-dir
))
342 (filename (buffer-file-name docbook-buf
))
343 (base (file-name-sans-extension filename
))
344 (fofile (concat base
".fo"))
345 (pdffile (concat base
".pdf")))
346 (and (file-exists-p pdffile
) (delete-file pdffile
))
347 (message "Processing DocBook XML file...")
348 (shell-command (format org-export-docbook-xslt-proc-command
349 fofile
(shell-quote-argument filename
)))
350 (shell-command (format org-export-docbook-xsl-fo-proc-command
352 (message "Processing DocBook file...done")
353 (if (not (file-exists-p pdffile
))
354 (error "PDF file was not produced")
355 (set-window-configuration wconfig
)
356 (message "Exporting to PDF...done")
360 (defun org-export-as-docbook-pdf-and-open ()
361 "Export as DocBook XML file, generate PDF file, and open it."
363 (let ((pdffile (org-export-as-docbook-pdf)))
365 (org-open-file pdffile
)
366 (error "PDF file was not produced"))))
369 (defun org-export-as-docbook (&optional hidden ext-plist
370 to-buffer body-only pub-dir
)
371 "Export the current buffer as a DocBook file.
372 If there is an active region, export only the region. When
373 HIDDEN is obsolete and does nothing. EXT-PLIST is a
374 property list with external parameters overriding org-mode's
375 default settings, but still inferior to file-local settings.
376 When TO-BUFFER is non-nil, create a buffer with that name and
377 export to that buffer. If TO-BUFFER is the symbol `string',
378 don't leave any buffer behind but just return the resulting HTML
379 as a string. When BODY-ONLY is set, don't produce the file
380 header and footer, simply return the content of the document (all
381 top-level sections). When PUB-DIR is set, use this as the
382 publishing directory."
384 ;; Make sure we have a file name when we need it.
385 (when (and (not (or to-buffer body-only
))
386 (not buffer-file-name
))
387 (if (buffer-base-buffer)
388 (org-set-local 'buffer-file-name
389 (with-current-buffer (buffer-base-buffer)
391 (error "Need a file name to be able to export.")))
393 (message "Exporting...")
394 (setq-default org-todo-line-regexp org-todo-line-regexp
)
395 (setq-default org-deadline-line-regexp org-deadline-line-regexp
)
396 (setq-default org-done-keywords org-done-keywords
)
397 (setq-default org-maybe-keyword-time-regexp org-maybe-keyword-time-regexp
)
399 (org-export-process-option-filters
400 (org-combine-plists (org-default-export-plist)
402 (org-infile-export-plist))))
403 (link-validate (plist-get opt-plist
:link-validation-function
))
405 (odd org-odd-levels-only
)
406 (region-p (org-region-active-p))
407 (rbeg (and region-p
(region-beginning)))
408 (rend (and region-p
(region-end)))
410 (if (plist-get opt-plist
:ignore-subree-p
)
415 (and (org-at-heading-p)
416 (>= (org-end-of-subtree t t
) rend
))))))
417 (level-offset (if subtree-p
420 (+ (funcall outline-level
)
421 (if org-odd-levels-only
1 0)))
423 (opt-plist (setq org-export-opt-plist
425 (org-export-add-subtree-options opt-plist rbeg
)
427 ;; The following two are dynamically scoped into other
429 (org-current-export-dir
430 (or pub-dir
(org-export-directory :docbook opt-plist
)))
431 (org-current-export-file buffer-file-name
)
432 (level 0) (line "") (origline "") txt todo
433 (filename (if to-buffer nil
436 (file-name-sans-extension
438 (org-entry-get (region-beginning)
439 "EXPORT_FILE_NAME" t
))
440 (file-name-nondirectory buffer-file-name
)))
441 org-export-docbook-extension
)
442 (file-name-as-directory
443 (or pub-dir
(org-export-directory :docbook opt-plist
))))))
444 (current-dir (if buffer-file-name
445 (file-name-directory buffer-file-name
)
447 (buffer (if to-buffer
449 ((eq to-buffer
'string
) (get-buffer-create "*Org DocBook Export*"))
450 (t (get-buffer-create to-buffer
)))
451 (find-file-noselect filename
)))
452 ;; org-levels-open is a global variable
453 (org-levels-open (make-vector org-level-max nil
))
454 (date (plist-get opt-plist
:date
))
455 (author (or (plist-get opt-plist
:author
)
457 (email (plist-get opt-plist
:email
))
458 firstname othername surname
459 (title (or (and subtree-p
(org-export-get-title-from-subtree))
460 (plist-get opt-plist
:title
)
462 (plist-get opt-plist
:skip-before-1st-heading
))
463 (org-export-grab-title-from-buffer))
464 (and buffer-file-name
465 (file-name-sans-extension
466 (file-name-nondirectory buffer-file-name
)))
468 ;; We will use HTML table formatter to export tables to DocBook
469 ;; format, so need to set html-table-tag here.
470 (html-table-tag (plist-get opt-plist
:html-table-tag
))
471 (quote-re0 (concat "^[ \t]*" org-quote-string
"\\>"))
472 (quote-re (concat "^\\(\\*+\\)\\([ \t]+" org-quote-string
"\\>\\)"))
477 (local-list-type nil
)
478 (local-list-indent nil
)
479 (llt org-plain-list-ordered-item-terminator
)
480 (email (plist-get opt-plist
:email
))
481 (language (plist-get opt-plist
:language
))
485 (coding-system (and (boundp 'buffer-file-coding-system
)
486 buffer-file-coding-system
))
487 (coding-system-for-write (or org-export-docbook-coding-system
489 (save-buffer-coding-system (or org-export-docbook-coding-system
491 (charset (and coding-system-for-write
492 (fboundp 'coding-system-get
)
493 (coding-system-get coding-system-for-write
497 (if region-p
(region-beginning) (point-min))
498 (if region-p
(region-end) (point-max))))
501 (org-export-preprocess-string
505 :skip-before-1st-heading
506 (plist-get opt-plist
:skip-before-1st-heading
)
507 :drawers
(plist-get opt-plist
:drawers
)
508 :todo-keywords
(plist-get opt-plist
:todo-keywords
)
509 :tags
(plist-get opt-plist
:tags
)
510 :priority
(plist-get opt-plist
:priority
)
511 :footnotes
(plist-get opt-plist
:footnotes
)
512 :timestamps
(plist-get opt-plist
:timestamps
)
514 (plist-get opt-plist
:archived-trees
)
515 :select-tags
(plist-get opt-plist
:select-tags
)
516 :exclude-tags
(plist-get opt-plist
:exclude-tags
)
518 (plist-get opt-plist
:text
)
520 (plist-get opt-plist
:LaTeX-fragments
))
522 ;; Use literal output to show check boxes.
524 (nth 1 (assoc "=" org-export-docbook-emphasis-alist
)))
526 (nth 2 (assoc "=" org-export-docbook-emphasis-alist
)))
528 table-buffer table-orig-buffer
529 ind item-type starter didclose
530 rpl path attr caption label desc descp desc1 desc2 link
532 footref-seen footnote-list
536 ;; Fine detailed info about author name.
537 (if (string-match "\\([^ ]+\\) \\(.+ \\)?\\([^ ]+\\)" author
)
539 (setq firstname
(match-string 1 author
)
540 othername
(or (match-string 2 author
) "")
541 surname
(match-string 3 author
))))
543 ;; Get all footnote text.
545 (org-export-docbook-get-footnotes lines
))
547 (let ((inhibit-read-only t
))
549 (remove-text-properties (point-min) (point-max)
550 '(:org-license-to-kill t
))))
552 (setq org-min-level
(org-get-min-level lines level-offset
))
553 (setq org-last-level org-min-level
)
554 (org-init-section-numbers)
556 ;; Get and save the date.
558 ((and date
(string-match "%" date
))
559 (setq date
(format-time-string date
)))
561 (t (setq date
(format-time-string "%Y-%m-%d %T %Z"))))
563 ;; Get the language-dependent settings
564 (setq lang-words
(or (assoc language org-export-language-setup
)
565 (assoc "en" org-export-language-setup
)))
567 ;; Switch to the output buffer. Use fundamental-mode for now. We
568 ;; could turn on nXML mode later and do some indentation.
570 (let ((inhibit-read-only t
)) (erase-buffer))
573 (and (fboundp 'set-buffer-file-coding-system
)
574 (set-buffer-file-coding-system coding-system-for-write
))
577 (let ((case-fold-search nil
)
578 (org-odd-levels-only odd
))
580 ;; Create local variables for all options, to make sure all called
581 ;; functions get the correct information
583 (set (make-local-variable (nth 2 x
))
584 (plist-get opt-plist
(car x
))))
585 org-export-plist-vars
)
587 ;; Insert DocBook file header, title, and author info.
589 (insert org-export-docbook-header
)
590 (if org-export-docbook-doctype
591 (insert org-export-docbook-doctype
))
592 (insert "<!-- Date: " date
" -->\n")
593 (insert (format "<!-- DocBook XML file generated by Org-mode %s Emacs %s -->\n"
594 org-version emacs-major-version
))
595 (insert org-export-docbook-article-header
)
597 "\n <title>%s</title>
601 <firstname>%s</firstname> <othername>%s</othername> <surname>%s</surname>
606 (org-docbook-expand title
)
607 firstname othername surname
608 (if email
(concat "<email>" email
"</email>") "")
611 (org-init-section-numbers)
613 (org-export-docbook-open-para)
615 ;; Loop over all the lines...
616 (while (setq line
(pop lines
) origline line
)
619 ;; End of quote section?
620 (when (and inquote
(string-match "^\\*+ " line
))
621 (insert "]]>\n</programlisting>\n")
622 (org-export-docbook-open-para)
624 ;; Inside a quote section?
626 (insert (org-docbook-protect line
) "\n")
627 (throw 'nextline nil
))
629 ;; Fixed-width, verbatim lines (examples)
630 (when (and org-export-with-fixed-width
631 (string-match "^[ \t]*:\\(\\([ \t]\\|$\\)\\(.*\\)\\)" line
))
634 (org-export-docbook-close-para-maybe)
635 (insert "<programlisting><![CDATA["))
636 (insert (match-string 3 line
) "\n")
637 (when (or (not lines
)
638 (not (string-match "^[ \t]*\\(:.*\\)"
641 (insert "]]>\n</programlisting>\n")
642 (org-export-docbook-open-para))
643 (throw 'nextline nil
))
645 (org-export-docbook-close-lists-maybe line
)
648 (when (get-text-property 0 'org-protected line
)
650 (when (re-search-backward
651 "\\(<para>\\)\\([ \t\r\n]*\\)\\=" (- (point) 100) t
)
652 (setq par
(match-string 1))
653 (replace-match "\\2\n"))
656 (or (= (length (car lines
)) 0)
657 (get-text-property 0 'org-protected
(car lines
))))
658 (insert (pop lines
) "\n"))
659 (and par
(insert "<para>\n")))
660 (throw 'nextline nil
))
662 ;; Start of block quotes and verses
663 (when (or (equal "ORG-BLOCKQUOTE-START" line
)
664 (and (equal "ORG-VERSE-START" line
)
666 (org-export-docbook-close-para-maybe)
667 (insert "<blockquote>")
668 ;; Check whether attribution for this blockquote exists.
671 (end (if inverse
"ORG-VERSE-END" "ORG-BLOCKQUOTE-END"))
673 (while (and (setq tmp1
(pop lines
))
674 (not (equal end tmp1
)))
675 (push tmp1 quote-lines
))
676 (push tmp1 lines
) ; Put back quote end mark
677 ;; Check the last line in the quote to see if it contains
679 (setq tmp1
(pop quote-lines
))
680 (if (string-match "\\(^.*\\)\\(--[ \t]+\\)\\(.+\\)$" tmp1
)
682 (setq attribution
(match-string 3 tmp1
))
683 (when (save-match-data
684 (string-match "[^ \t]" (match-string 1 tmp1
)))
685 (push (match-string 1 tmp1
) lines
)))
687 (while (setq tmp1
(pop quote-lines
))
690 (insert "<attribution>" attribution
"</attribution>")))
691 ;; Insert <literallayout> for verse.
693 (insert "\n<literallayout>")
694 (org-export-docbook-open-para))
695 (throw 'nextline nil
))
697 ;; End of block quotes
698 (when (equal "ORG-BLOCKQUOTE-END" line
)
699 (org-export-docbook-close-para-maybe)
700 (insert "</blockquote>\n")
701 (org-export-docbook-open-para)
702 (throw 'nextline nil
))
705 (when (equal "ORG-VERSE-END" line
)
706 (insert "</literallayout>\n</blockquote>\n")
707 (org-export-docbook-open-para)
709 (throw 'nextline nil
))
711 ;; Text centering. Element <para role="centered"> does not
712 ;; seem to work with FOP, so for now we use <informaltable> to
713 ;; center the text, which can contain multiple paragraphs.
714 (when (equal "ORG-CENTER-START" line
)
715 (org-export-docbook-close-para-maybe)
716 (insert "<informaltable frame=\"none\" colsep=\"0\" rowsep=\"0\">\n"
717 "<tgroup align=\"center\" cols=\"1\">\n"
718 "<tbody><row><entry>\n")
719 (org-export-docbook-open-para)
720 (throw 'nextline nil
))
722 (when (equal "ORG-CENTER-END" line
)
723 (org-export-docbook-close-para-maybe)
724 (insert "</entry></row></tbody>\n"
725 "</tgroup>\n</informaltable>\n")
726 (org-export-docbook-open-para)
727 (throw 'nextline nil
))
729 ;; Make targets to anchors. Note that currently FOP does not
730 ;; seem to support <anchor> tags when generating PDF output,
731 ;; but this can be used in DocBook --> HTML conversion.
732 (while (string-match "<<<?\\([^<>]*\\)>>>?\\((INVISIBLE)\\)?[ \t]*\n?" line
)
735 (setq line
(replace-match
736 (format "@<anchor xml:id=\"%s\"/>"
737 (org-solidify-link-text (match-string 1 line
)))
740 (setq line
(replace-match
741 (format "@<anchor xml:id=\"%s\"/>"
742 (org-solidify-link-text (match-string 1 line
)))
745 ;; Put time stamps and related keywords into special mark-up
747 (setq line
(org-export-docbook-handle-time-stamps line
))
749 ;; Replace "&", "<" and ">" by "&", "<" and ">".
750 ;; Handle @<..> HTML tags (replace "@>..<" by "<..>").
751 ;; Also handle sub_superscripts and check boxes.
752 (or (string-match org-table-hline-regexp line
)
753 (setq line
(org-docbook-expand line
)))
757 (while (string-match org-bracket-link-analytic-regexp
++ line start
)
758 (setq start
(match-beginning 0))
759 (setq path
(save-match-data (org-link-unescape
760 (match-string 3 line
))))
762 ((match-end 2) (match-string 2 line
))
764 (or (file-name-absolute-p path
)
765 (string-match "^\\.\\.?/" path
)))
768 (setq path
(org-extract-attributes (org-link-unescape path
)))
769 (setq attr
(get-text-property 0 'org-attributes path
)
770 caption
(get-text-property 0 'org-caption path
)
771 label
(get-text-property 0 'org-label path
))
772 (setq desc1
(if (match-end 5) (match-string 5 line
))
773 desc2
(if (match-end 2) (concat type
":" path
) path
)
774 descp
(and desc1
(not (equal desc1 desc2
)))
775 desc
(or desc1 desc2
))
776 ;; Make an image out of the description if that is so wanted
777 (when (and descp
(org-file-image-p
778 desc org-export-docbook-inline-image-extensions
))
780 (if (string-match "^file:" desc
)
781 (setq desc
(substring desc
(match-end 0))))))
782 ;; FIXME: do we need to unescape here somewhere?
784 ((equal type
"internal")
785 (setq rpl
(format "<link linkend=\"%s\">%s</link>"
786 (org-solidify-link-text
787 (save-match-data (org-link-unescape path
)) nil
)
788 (org-export-docbook-format-desc desc
))))
789 ((and (equal type
"id")
790 (setq id-file
(org-id-find-id-file path
)))
791 ;; This is an id: link to another file (if it was the same file,
792 ;; it would have become an internal link...)
793 (setq id-file
(file-relative-name
794 id-file
(file-name-directory org-current-export-file
)))
795 (setq id-file
(concat (file-name-sans-extension id-file
)
796 org-export-docbook-extension
))
797 (setq rpl
(format "<link xlink:href=\"%s#%s\">%s</link>"
798 id-file path
(org-export-docbook-format-desc desc
))))
799 ((member type
'("http" "https"))
800 ;; Standard URL, just check if we need to inline an image
801 (if (and (or (eq t org-export-docbook-inline-images
)
802 (and org-export-docbook-inline-images
(not descp
)))
804 path org-export-docbook-inline-image-extensions
))
805 (setq rpl
(org-export-docbook-format-image
806 (concat type
":" path
)))
807 (setq link
(concat type
":" path
))
808 (setq rpl
(format "<link xlink:href=\"%s\">%s</link>"
809 (org-export-html-format-href link
)
810 (org-export-docbook-format-desc desc
)))
812 ((member type
'("ftp" "mailto" "news"))
814 (setq link
(concat type
":" path
))
815 (setq rpl
(format "<link xlink:href=\"%s\">%s</link>"
816 (org-export-html-format-href link
)
817 (org-export-docbook-format-desc desc
))))
818 ((string= type
"coderef")
819 (setq rpl
(format (org-export-get-coderef-format path
(and descp desc
))
820 (cdr (assoc path org-export-code-refs
)))))
821 ((functionp (setq fnc
(nth 2 (assoc type org-link-protocols
))))
822 ;; The link protocol has a function for format the link
825 (funcall fnc
(org-link-unescape path
) desc1
'html
))))
827 ((string= type
"file")
829 (let* ((filename path
)
830 (abs-p (file-name-absolute-p filename
))
831 thefile file-is-image-p search
)
833 (if (string-match "::\\(.*\\)" filename
)
834 (setq search
(match-string 1 filename
)
835 filename
(replace-match "" t nil filename
)))
837 (if (functionp link-validate
)
838 (funcall link-validate filename current-dir
)
840 (setq file-is-image-p
842 filename org-export-docbook-inline-image-extensions
))
843 (setq thefile
(if abs-p
(expand-file-name filename
) filename
))
844 ;; Carry over the properties (expand-file-name will
845 ;; discard the properties of filename)
846 (add-text-properties 0 (1- (length thefile
))
847 (list 'org-caption caption
851 (when (and org-export-docbook-link-org-files-as-docbook
852 (string-match "\\.org$" thefile
))
853 (setq thefile
(concat (substring thefile
0
855 org-export-docbook-extension
))
857 ;; make sure this is can be used as target search
858 (not (string-match "^[0-9]*$" search
))
859 (not (string-match "^\\*" search
))
860 (not (string-match "^/.*/$" search
)))
861 (setq thefile
(concat thefile
"#"
862 (org-solidify-link-text
863 (org-link-unescape search
)))))
864 (when (string-match "^file:" desc
)
865 (setq desc
(replace-match "" t t desc
))
866 (if (string-match "\\.org$" desc
)
867 (setq desc
(replace-match "" t t desc
))))))
868 (setq rpl
(if (and file-is-image-p
869 (or (eq t org-export-docbook-inline-images
)
870 (and org-export-docbook-inline-images
873 (message "image %s %s" thefile org-docbook-para-open
)
874 (org-export-docbook-format-image thefile
))
875 (format "<link xlink:href=\"%s\">%s</link>"
876 thefile
(org-export-docbook-format-desc desc
))))
877 (if (not valid
) (setq rpl desc
))))
880 ;; Just publish the path, as default
881 (setq rpl
(concat "<" type
":"
882 (save-match-data (org-link-unescape path
))
884 (setq line
(replace-match rpl t t line
)
885 start
(+ start
(length rpl
))))
887 ;; TODO items: can we do something better?!
888 (if (and (string-match org-todo-line-regexp line
)
891 (concat (substring line
0 (match-beginning 2))
892 "[" (match-string 2 line
) "]"
893 (substring line
(match-end 2)))))
895 ;; Does this contain a reference to a footnote?
896 (when org-export-with-footnotes
898 (while (string-match "\\([^* \t].*?\\)\\[\\([0-9]+\\)\\]" line start
)
899 (if (get-text-property (match-beginning 2) 'org-protected line
)
900 (setq start
(match-end 2))
901 (let ((num (match-string 2 line
)))
902 (if (assoc num footref-seen
)
903 (setq line
(replace-match
904 (format "%s<footnoteref linkend=\"%s%s\"/>"
905 (match-string 1 line
)
906 org-export-docbook-footnote-id-prefix num
)
908 (setq line
(replace-match
909 (format "%s<footnote xml:id=\"%s%s\"><para>%s</para></footnote>"
910 (match-string 1 line
)
911 org-export-docbook-footnote-id-prefix
915 (cdr (assoc num footnote-list
)))))
917 (push (cons num
1) footref-seen
))))))
920 ((string-match "^\\(\\*+\\)[ \t]+\\(.*\\)" line
)
921 ;; This is a headline
922 (setq level
(org-tr-level (- (match-end 1) (match-beginning 1)
924 txt
(match-string 2 line
))
925 (if (string-match quote-re0 txt
)
926 (setq txt
(replace-match "" t t txt
)))
928 ;; Close any local lists before inserting a new header line
929 (while local-list-type
930 (let ((listtype (car local-list-type
)))
931 (org-export-docbook-close-li listtype
)
933 ((equal listtype
"o") "</orderedlist>\n")
934 ((equal listtype
"u") "</itemizedlist>\n")
935 ((equal listtype
"d") "</variablelist>\n"))))
936 (pop local-list-type
))
937 (setq local-list-indent nil
939 (org-export-docbook-level-start level txt
)
941 (when (string-match quote-re line
)
942 (org-export-docbook-close-para-maybe)
943 (insert "<programlisting><![CDATA[")
946 ;; Tables: since version 4.3 of DocBook DTD, HTML tables are
947 ;; supported. We can use existing HTML table exporter code
949 ((and org-export-with-tables
950 (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)" line
))
955 table-orig-buffer nil
))
957 (setq table-buffer
(cons line table-buffer
)
958 table-orig-buffer
(cons origline table-orig-buffer
))
959 (when (or (not lines
)
960 (not (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)"
963 table-buffer
(nreverse table-buffer
)
964 table-orig-buffer
(nreverse table-orig-buffer
))
965 (org-export-docbook-close-para-maybe)
966 (insert (org-export-docbook-finalize-table
967 (org-format-table-html table-buffer table-orig-buffer
)))))
972 ((eq llt t
) "^\\([ \t]*\\)\\(\\([-+*] \\)\\|\\([0-9]+[.)]\\) \\)?\\( *[^ \t\n\r]\\|[ \t]*$\\)")
973 ((= llt ?.
) "^\\([ \t]*\\)\\(\\([-+*] \\)\\|\\([0-9]+\\.\\) \\)?\\( *[^ \t\n\r]\\|[ \t]*$\\)")
974 ((= llt ?\
)) "^\\([ \t]*\\)\\(\\([-+*] \\)\\|\\([0-9]+)\\) \\)?\\( *[^ \t\n\r]\\|[ \t]*$\\)")
975 (t (error "Invalid value of `org-plain-list-ordered-item-terminator'")))
977 (setq ind
(or (get-text-property 0 'original-indentation line
)
978 (org-get-string-indentation line
))
979 item-type
(if (match-beginning 4) "o" "u")
980 starter
(if (match-beginning 2)
981 (substring (match-string 2 line
) 0 -
1))
982 line
(substring line
(match-beginning 5))
984 (if (and starter
(string-match "\\(.*?\\) ::[ \t]*" line
))
986 item-tag
(match-string 1 line
)
987 line
(substring line
(match-end 0))))
988 (when (and (not (equal item-type
"d"))
989 (not (string-match "[^ \t]" line
)))
990 ;; Empty line. Pretend indentation is large.
991 (setq ind
(if org-empty-line-terminates-plain-lists
993 (1+ (or (car local-list-indent
) 1)))))
995 (while (and in-local-list
996 (or (and (= ind
(car local-list-indent
))
998 (< ind
(car local-list-indent
))))
1000 (let ((listtype (car local-list-type
)))
1001 (org-export-docbook-close-li listtype
)
1003 ((equal listtype
"o") "</orderedlist>\n")
1004 ((equal listtype
"u") "</itemizedlist>\n")
1005 ((equal listtype
"d") "</variablelist>\n"))))
1006 (pop local-list-type
) (pop local-list-indent
)
1007 (setq in-local-list local-list-indent
))
1010 (or (not in-local-list
)
1011 (> ind
(car local-list-indent
))))
1012 ;; Start new (level of) list
1013 (org-export-docbook-close-para-maybe)
1015 ((equal item-type
"u") "<itemizedlist>\n<listitem>\n")
1016 ((equal item-type
"o") "<orderedlist>\n<listitem>\n")
1017 ((equal item-type
"d")
1018 (format "<variablelist>\n<varlistentry><term>%s</term><listitem>\n" item-tag
))))
1019 ;; For DocBook, we need to open a para right after tag
1021 (org-export-docbook-open-para)
1022 (push item-type local-list-type
)
1023 (push ind local-list-indent
)
1024 (setq in-local-list t
))
1026 ;; Continue current list
1027 (let ((listtype (car local-list-type
)))
1028 (org-export-docbook-close-li listtype
)
1030 ((equal listtype
"o") "<listitem>")
1031 ((equal listtype
"u") "<listitem>")
1032 ((equal listtype
"d") (format
1033 "<varlistentry><term>%s</term><listitem>"
1036 ;; For DocBook, we need to open a para right after tag
1038 (org-export-docbook-open-para))
1040 ;; We did close a list, normal text follows: need <para>
1041 (org-export-docbook-open-para)))
1043 (if (string-match "^[ \t]*\\(\\[[X -]\\]\\)" line
)
1045 (replace-match (concat checkbox-start
1046 (match-string 1 line
)
1050 ;; Empty lines start a new paragraph. If hand-formatted lists
1051 ;; are not fully interpreted, lines starting with "-", "+", "*"
1052 ;; also start a new paragraph.
1053 (if (and (string-match "^ [-+*]-\\|^[ \t]*$" line
)
1055 (org-export-docbook-open-para))
1057 ;; Is this the start of a footnote?
1058 (when org-export-with-footnotes
1059 (when (and (boundp 'footnote-section-tag-regexp
)
1060 (string-match (concat "^" footnote-section-tag-regexp
)
1063 (throw 'nextline nil
))
1064 ;; These footnote lines have been read and saved before,
1065 ;; ignore them at this time.
1066 (when (string-match "^[ \t]*\\[\\([0-9]+\\)\\]" line
)
1067 (org-export-docbook-close-para-maybe)
1068 (throw 'nextline nil
)))
1070 ;; FIXME: It might be a good idea to add an option to
1071 ;; support line break processing instruction <?linebreak?>.
1072 ;; Org-mode supports line break "\\" in HTML exporter, and
1073 ;; some DocBook users may also want to force line breaks
1074 ;; even though DocBook only supports that in
1077 (insert line
"\n")))))
1079 ;; Properly close all local lists and other lists
1081 (insert "]]>\n</programlisting>\n")
1082 (org-export-docbook-open-para))
1084 ;; Close any local lists before inserting a new header line
1085 (while local-list-type
1086 (let ((listtype (car local-list-type
)))
1087 (org-export-docbook-close-li listtype
)
1089 ((equal listtype
"o") "</orderedlist>\n")
1090 ((equal listtype
"u") "</itemizedlist>\n")
1091 ((equal listtype
"d") "</variablelist>\n"))))
1092 (pop local-list-type
))
1093 (setq local-list-indent nil
1095 ;; Close all open sections.
1096 (org-export-docbook-level-start 1 nil
)
1098 (unless (plist-get opt-plist
:buffer-will-be-killed
)
1100 (if (eq major-mode default-major-mode
)
1103 ;; Remove empty paragraphs and lists. Replace them with a
1105 (goto-char (point-min))
1106 (while (re-search-forward
1107 "[ \r\n\t]*\\(<para>\\)[ \r\n\t]*</para>[ \r\n\t]*" nil t
)
1108 (when (not (get-text-property (match-beginning 1) 'org-protected
))
1109 (replace-match "\n")
1111 ;; Fill empty sections with <para></para>. This is to make sure
1112 ;; that the DocBook document generated is valid and well-formed.
1113 (goto-char (point-min))
1114 (while (re-search-forward
1115 "</title>\\([ \r\n\t]*\\)</section>" nil t
)
1116 (when (not (get-text-property (match-beginning 0) 'org-protected
))
1117 (replace-match "\n<para></para>\n" nil nil nil
1)))
1118 ;; Insert the last closing tag.
1119 (goto-char (point-max))
1121 (insert "</article>"))
1122 (or to-buffer
(save-buffer))
1123 (goto-char (point-min))
1124 (or (org-export-push-to-kill-ring "DocBook")
1125 (message "Exporting... done"))
1126 (if (eq to-buffer
'string
)
1127 (prog1 (buffer-substring (point-min) (point-max))
1128 (kill-buffer (current-buffer)))
1129 (current-buffer)))))
1131 (defun org-export-docbook-open-para ()
1132 "Insert <para>, but first close previous paragraph if any."
1133 (org-export-docbook-close-para-maybe)
1135 (setq org-docbook-para-open t
))
1137 (defun org-export-docbook-close-para-maybe ()
1138 "Close DocBook paragraph if there is one open."
1139 (when org-docbook-para-open
1140 (insert "</para>\n")
1141 (setq org-docbook-para-open nil
)))
1143 (defun org-export-docbook-close-li (&optional type
)
1144 "Close list if necessary."
1145 (org-export-docbook-close-para-maybe)
1146 (if (equal type
"d")
1147 (insert "</listitem></varlistentry>\n")
1148 (insert "</listitem>\n")))
1150 (defvar in-local-list
)
1151 (defvar local-list-indent
)
1152 (defvar local-list-type
)
1153 (defun org-export-docbook-close-lists-maybe (line)
1154 (let ((ind (or (get-text-property 0 'original-indentation line
)
1155 (org-get-indentation line
)))
1158 (while (and in-local-list
1159 (<= ind
(car local-list-indent
)))
1161 (let ((listtype (car local-list-type
)))
1162 (org-export-docbook-close-li listtype
)
1164 ((equal listtype
"o") "</orderedlist>\n")
1165 ((equal listtype
"u") "</itemizedlist>\n")
1166 ((equal listtype
"d") "</variablelist>\n"))))
1167 (pop local-list-type
) (pop local-list-indent
)
1168 (setq in-local-list local-list-indent
))
1169 (and didclose
(org-export-docbook-open-para)))))
1171 (defun org-export-docbook-level-start (level title
)
1172 "Insert a new level in DocBook export.
1173 When TITLE is nil, just close all open levels."
1174 (org-export-docbook-close-para-maybe)
1175 (let* ((target (and title
(org-get-text-property-any 0 'target title
)))
1179 (if (aref org-levels-open
(1- l
))
1181 (insert "</section>\n")
1182 (aset org-levels-open
(1- l
) nil
)))
1185 ;; If title is nil, this means this function is called to close
1186 ;; all levels, so the rest is done only if title is given.
1188 ;; Format tags: put them into a superscript like format.
1189 (when (string-match (org-re "\\(:[[:alnum:]_@:]+:\\)[ \t]*$") title
)
1192 (if org-export-with-tags
1196 (match-string 1 title
)
1200 (aset org-levels-open
(1- level
) t
)
1201 (setq section-number
(org-section-number level
))
1202 (insert (format "\n<section xml:id=\"%s%s\">\n<title>%s</title>"
1203 org-export-docbook-section-id-prefix
1204 section-number title
))
1205 (org-export-docbook-open-para))))
1207 (defun org-docbook-expand (string)
1208 "Prepare STRING for DocBook export.
1209 Applies all active conversions. If there are links in the
1210 string, don't modify these."
1211 (let* ((re (concat org-bracket-link-regexp
"\\|"
1212 (org-re "[ \t]+\\(:[[:alnum:]_@:]+:\\)[ \t]*$")))
1214 (while (setq m
(string-match re string
))
1215 (setq s
(substring string
0 m
)
1216 l
(match-string 0 string
)
1217 string
(substring string
(match-end 0)))
1218 (push (org-docbook-do-expand s
) res
)
1220 (push (org-docbook-do-expand string
) res
)
1221 (apply 'concat
(nreverse res
))))
1223 (defun org-docbook-do-expand (s)
1224 "Apply all active conversions to translate special ASCII to DocBook."
1225 (setq s
(org-html-protect s
))
1226 (while (string-match "@<\\([^&]*\\)>" s
)
1227 (setq s
(replace-match "<\\1>" t nil s
)))
1228 (if org-export-with-emphasize
1229 (setq s
(org-export-docbook-convert-emphasize s
)))
1230 (if org-export-with-special-strings
1231 (setq s
(org-export-docbook-convert-special-strings s
)))
1232 (if org-export-with-sub-superscripts
1233 (setq s
(org-export-docbook-convert-sub-super s
)))
1234 (if org-export-with-TeX-macros
1235 (let ((start 0) wd ass
)
1236 (while (setq start
(string-match "\\\\\\([a-zA-Z]+\\)\\({}\\)?"
1238 (if (get-text-property (match-beginning 0) 'org-protected s
)
1239 (setq start
(match-end 0))
1240 (setq wd
(match-string 1 s
))
1241 (if (setq ass
(assoc wd org-html-entities
))
1242 (setq s
(replace-match (or (cdr ass
)
1243 (concat "&" (car ass
) ";"))
1245 (setq start
(+ start
(length wd
))))))))
1248 (defun org-export-docbook-format-desc (desc)
1249 "Make sure DESC is valid as a description in a link."
1251 (org-docbook-do-expand desc
)))
1253 (defun org-export-docbook-convert-emphasize (string)
1254 "Apply emphasis for DocBook exporting."
1256 (while (string-match org-emph-re string s
)
1258 (substring string
(match-beginning 3) (1+ (match-beginning 3)))
1259 (substring string
(match-beginning 4) (1+ (match-beginning 4)))))
1260 (setq s
(match-beginning 0)
1263 (match-string 1 string
)
1264 (nth 1 (assoc (match-string 3 string
)
1265 org-export-docbook-emphasis-alist
))
1266 (match-string 4 string
)
1267 (nth 2 (assoc (match-string 3 string
)
1268 org-export-docbook-emphasis-alist
))
1269 (match-string 5 string
))
1270 string
(replace-match rpl t t string
)
1271 s
(+ s
(- (length rpl
) 2)))
1275 (defun org-docbook-protect (string)
1276 (org-html-protect string
))
1278 ;; For now, simply return string as it is.
1279 (defun org-export-docbook-convert-special-strings (string)
1280 "Convert special characters in STRING to DocBook."
1283 (defun org-export-docbook-get-footnotes (lines)
1284 "Given a list of LINES, return a list of alist footnotes."
1285 (let ((list nil
) line
)
1286 (while (setq line
(pop lines
))
1287 (if (string-match "^[ \t]*\\[\\([0-9]+\\)\\] \\(.+\\)" line
)
1288 (push (cons (match-string 1 line
) (match-string 2 line
))
1292 (defun org-export-docbook-format-image (src)
1293 "Create image element in DocBook."
1295 (let* ((caption (org-find-text-property-in-string 'org-caption src
))
1296 (attr (or (org-find-text-property-in-string 'org-attributes src
)
1298 (label (org-find-text-property-in-string 'org-label src
))
1299 (default-attr org-export-docbook-default-image-attributes
)
1301 (while (setq tmp
(pop default-attr
))
1302 (if (not (string-match (concat (car tmp
) "=") attr
))
1303 (setq attr
(concat attr
" " (car tmp
) "=" (cdr tmp
)))))
1304 (format "<mediaobject%s>
1305 <imageobject>\n<imagedata fileref=\"%s\" %s/>\n</imageobject>
1307 (if label
(concat " xml:id=\"" label
"\"") "")
1310 (concat "<caption>\n<para>"
1312 "</para>\n</caption>\n")
1316 (defun org-export-docbook-preprocess (parameters)
1317 "Extra preprocessing work for DocBook export."
1318 ;; Merge lines starting with "\par" to one line. Such lines are
1319 ;; regarded as the continuation of a long footnote.
1320 (goto-char (point-min))
1321 (while (re-search-forward "\n\\(\\\\par\\>\\)" nil t
)
1322 (if (not (get-text-property (match-beginning 1) 'org-protected
))
1323 (replace-match ""))))
1325 (defun org-export-docbook-finalize-table (table)
1326 "Change TABLE to informaltable if caption does not exist.
1327 TABLE is a string containing the HTML code generated by
1328 `org-format-table-html' for a table in Org-mode buffer."
1330 "^<table \\(\\(.\\|\n\\)+\\)<caption></caption>\n\\(\\(.\\|\n\\)+\\)</table>"
1332 (replace-match (concat "<informaltable "
1333 (match-string 1 table
)
1334 (match-string 3 table
)
1339 ;; Note: This function is very similar to
1340 ;; org-export-html-convert-sub-super. They can be merged in the future.
1341 (defun org-export-docbook-convert-sub-super (string)
1342 "Convert sub- and superscripts in STRING for DocBook."
1343 (let (key c
(s 0) (requireb (eq org-export-with-sub-superscripts
'{})))
1344 (while (string-match org-match-substring-regexp string s
)
1346 ((and requireb
(match-end 8)) (setq s
(match-end 2)))
1347 ((get-text-property (match-beginning 2) 'org-protected string
)
1348 (setq s
(match-end 2)))
1350 (setq s
(match-end 1)
1351 key
(if (string= (match-string 2 string
) "_")
1354 c
(or (match-string 8 string
)
1355 (match-string 6 string
)
1356 (match-string 5 string
))
1357 string
(replace-match
1358 (concat (match-string 1 string
)
1359 "<" key
">" c
"</" key
">")
1361 (while (string-match "\\\\\\([_^]\\)" string
)
1362 (setq string
(replace-match (match-string 1 string
) t t string
)))
1365 (defun org-export-docbook-protect-tags (string)
1366 "Change ``<...>'' in string STRING into ``@<...>''.
1367 This is normally needed when STRING contains DocBook elements
1368 that need to be preserved in later phase of DocBook exporting."
1370 (while (string-match "<\\([^>]*\\)>" string start
)
1371 (setq string
(replace-match
1372 "@<\\1>" t nil string
)
1373 start
(match-end 0)))
1376 (defun org-export-docbook-handle-time-stamps (line)
1377 "Format time stamps in string LINE."
1379 (kw-markup (org-export-docbook-protect-tags
1380 org-export-docbook-keywords-markup
))
1381 (ts-markup (org-export-docbook-protect-tags
1382 org-export-docbook-timestamp-markup
)))
1383 (while (string-match org-maybe-keyword-time-regexp line
)
1386 (substring line
0 (match-beginning 0))
1389 (match-string 1 line
)))
1392 (substring (org-translate-time
1393 (match-string 3 line
)) 1 -
1)))
1394 line
(substring line
(match-end 0))))
1395 (concat replaced line
)))
1397 (provide 'org-docbook
)
1399 ;;; org-docbook.el ends here