diff options
Diffstat (limited to 'lisp/org/org-docbook.el')
-rw-r--r-- | lisp/org/org-docbook.el | 105 |
1 files changed, 71 insertions, 34 deletions
diff --git a/lisp/org/org-docbook.el b/lisp/org/org-docbook.el index e5ee98bb344..12ab96deff9 100644 --- a/lisp/org/org-docbook.el +++ b/lisp/org/org-docbook.el @@ -4,7 +4,7 @@ ;; ;; Emacs Lisp Archive Entry ;; Filename: org-docbook.el -;; Version: 6.35i +;; Version: 7.01 ;; Author: Baoqiu Cui <cbaoqiu AT yahoo DOT com> ;; Maintainer: Baoqiu Cui <cbaoqiu AT yahoo DOT com> ;; Keywords: org, wp, docbook @@ -26,7 +26,7 @@ ;; You should have received a copy of the GNU General Public License ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. -;; Commentary: +;;; Commentary: ;; ;; This library implements a DocBook exporter for org-mode. The basic ;; idea and design is very similar to what `org-export-as-html' has. @@ -76,6 +76,7 @@ (require 'org) (require 'org-exp) (require 'org-html) +(require 'format-spec) ;;; Variables: @@ -141,8 +142,8 @@ people work on the same document." :type 'string) (defcustom org-export-docbook-footnote-id-prefix "fn-" - "The prefix of footnote IDs used during exporting. Like -`org-export-docbook-section-id-prefix', this variable can help + "The prefix of footnote IDs used during exporting. +Like `org-export-docbook-section-id-prefix', this variable can help avoid same set of footnote IDs being used multiple times." :group 'org-export-docbook :type 'string) @@ -154,7 +155,7 @@ avoid same set of footnote IDs being used multiple times." ("=" "<code>" "</code>") ("~" "<literal>" "</literal>") ("+" "<emphasis role=\"strikethrough\">" "</emphasis>")) - "Alist of DocBook expressions to convert emphasis fontifiers. + "A list of DocBook expressions to convert emphasis fontifiers. Each element of the list is a list of three elements. The first element is the character used as a marker for fontification. The second element is a formatting string to wrap fontified text with. @@ -183,32 +184,39 @@ default, but users can override them using `#+ATTR_DocBook:'." :group 'org-export-docbook :type 'coding-system) +(defcustom org-export-docbook-xslt-stylesheet nil + "File name of the XSLT stylesheet used by DocBook exporter. +This XSLT stylesheet is used by +`org-export-docbook-xslt-proc-command' to generate the Formatting +Object (FO) files. You can use either `fo/docbook.xsl' that +comes with DocBook, or any customization layer you may have." + :group 'org-export-docbook + :type 'string) + (defcustom org-export-docbook-xslt-proc-command nil - "XSLT processor command used by DocBook exporter. -This is the command used to process a DocBook XML file to -generate the formatting object (FO) file. + "Format of XSLT processor command used by DocBook exporter. +This command is used to process a DocBook XML file to generate +the Formatting Object (FO) file. The value of this variable should be a format control string that -includes two `%s' arguments: the first one is for the output FO -file name, and the second one is for the input DocBook XML file -name. +includes three arguments: `%i', `%o', and `%s'. During exporting +time, `%i' is replaced by the input DocBook XML file name, `%o' +is replaced by the output FO file name, and `%s' is replaced by +`org-export-docbook-xslt-stylesheet' (or the #+XSLT option if it +is specified in the Org file). For example, if you use Saxon as the XSLT processor, you may want to set the variable to - \"java com.icl.saxon.StyleSheet -o %s %s /path/to/docbook.xsl\" + \"java com.icl.saxon.StyleSheet -o %o %i %s\" If you use Xalan, you can set it to - \"java org.apache.xalan.xslt.Process -out %s -in %s -xsl /path/to/docbook.xsl\" + \"java org.apache.xalan.xslt.Process -out %o -in %i -xsl %s\" For xsltproc, the following string should work: - \"xsltproc --output %s /path/to/docbook.xsl %s\" - -You need to replace \"/path/to/docbook.xsl\" with the actual path -to the DocBook stylesheet file on your machine. You can also -replace it with your own customization layer if you have one. + \"xsltproc --output %o %s %i\" You can include additional stylesheet parameters in this command. Just make sure that they meet the syntax requirement of each @@ -217,18 +225,19 @@ processor." :type 'string) (defcustom org-export-docbook-xsl-fo-proc-command nil - "XSL-FO processor command used by DocBook exporter. -This is the command used to process a formatting object (FO) file -to generate the PDF file. + "Format of XSL-FO processor command used by DocBook exporter. +This command is used to process a Formatting Object (FO) file to +generate the PDF file. The value of this variable should be a format control string that -includes two `%s' arguments: the first one is for the input FO -file name, and the second one is for the output PDF file name. +includes two arguments: `%i' and `%o'. During exporting time, +`%i' is replaced by the input FO file name, and `%o' is replaced +by the output PDF file name. For example, if you use FOP as the XSL-FO processor, you can set the variable to - \"fop %s %s\"" + \"fop %i %o\"" :group 'org-export-docbook :type 'string) @@ -333,13 +342,18 @@ in a window. A non-interactive call will only return the buffer." "Export as DocBook XML file, and generate PDF file." (interactive "P") (if (or (not org-export-docbook-xslt-proc-command) - (not (string-match "%s.+%s" org-export-docbook-xslt-proc-command))) + (not (string-match "%[ios].+%[ios].+%[ios]" org-export-docbook-xslt-proc-command))) (error "XSLT processor command is not set correctly")) (if (or (not org-export-docbook-xsl-fo-proc-command) - (not (string-match "%s.+%s" org-export-docbook-xsl-fo-proc-command))) + (not (string-match "%[io].+%[io]" org-export-docbook-xsl-fo-proc-command))) (error "XSL-FO processor command is not set correctly")) (message "Exporting to PDF...") (let* ((wconfig (current-window-configuration)) + (opt-plist + (org-export-process-option-filters + (org-combine-plists (org-default-export-plist) + ext-plist + (org-infile-export-plist)))) (docbook-buf (org-export-as-docbook hidden ext-plist to-buffer body-only pub-dir)) (filename (buffer-file-name docbook-buf)) @@ -348,10 +362,17 @@ in a window. A non-interactive call will only return the buffer." (pdffile (concat base ".pdf"))) (and (file-exists-p pdffile) (delete-file pdffile)) (message "Processing DocBook XML file...") - (shell-command (format org-export-docbook-xslt-proc-command - fofile (shell-quote-argument filename))) - (shell-command (format org-export-docbook-xsl-fo-proc-command - fofile pdffile)) + (shell-command (format-spec org-export-docbook-xslt-proc-command + (format-spec-make + ?i (shell-quote-argument filename) + ?o (shell-quote-argument fofile) + ?s (shell-quote-argument + (or (plist-get opt-plist :xslt) + org-export-docbook-xslt-stylesheet))))) + (shell-command (format-spec org-export-docbook-xsl-fo-proc-command + (format-spec-make + ?i (shell-quote-argument fofile) + ?o (shell-quote-argument pdffile)))) (message "Processing DocBook file...done") (if (not (file-exists-p pdffile)) (error "PDF file was not produced") @@ -533,7 +554,7 @@ publishing directory." table-buffer table-orig-buffer ind item-type starter didclose rpl path attr caption label desc descp desc1 desc2 link - fnc item-tag + fnc item-tag initial-number footref-seen footnote-list id-file ) @@ -998,7 +1019,11 @@ publishing directory." starter (if (match-beginning 2) (substring (match-string 2 line) 0 -1)) line (substring line (match-beginning 5)) - item-tag nil) + item-tag nil + initial-number nil) + (if (string-match "\\`\\[@start:\\([0-9]+\\)\\][ \t]?" line) + (setq initial-number (match-string 1 line) + line (replace-match "" t t line))) (if (and starter (string-match "\\(.*?\\) ::[ \t]*" line)) (setq item-type "d" item-tag (match-string 1 line) @@ -1031,7 +1056,18 @@ publishing directory." (org-export-docbook-close-para-maybe) (insert (cond ((equal item-type "u") "<itemizedlist>\n<listitem>\n") - ((equal item-type "o") "<orderedlist>\n<listitem>\n") + ((equal item-type "o") + ;; Check for a specific start number. If it + ;; is specified, we use the ``override'' + ;; attribute of element <listitem> to pass the + ;; info to DocBook. We could also use the + ;; ``startingnumber'' attribute of element + ;; <orderedlist>, but the former works on both + ;; DocBook 5.0 and prior versions. + (if initial-number + (format "<orderedlist>\n<listitem override=\"%s\">\n" + initial-number) + "<orderedlist>\n<listitem>\n")) ((equal item-type "d") (format "<variablelist>\n<varlistentry><term>%s</term><listitem>\n" item-tag)))) ;; For DocBook, we need to open a para right after tag @@ -1228,7 +1264,8 @@ When TITLE is nil, just close all open levels." (setq section-number (org-section-number level)) (insert (format "\n<section xml:id=\"%s%s\">\n<title>%s</title>" org-export-docbook-section-id-prefix - section-number title)) + (replace-regexp-in-string "\\." "_" section-number) + title)) (org-export-docbook-open-para)))) (defun org-docbook-expand (string) |