1 ;;; muse-docbook.el --- Publish DocBook files.
3 ;; Copyright (C) 2004, 2005 Free Software Foundation, Inc.
5 ;; This file is not part of GNU Emacs.
7 ;; This is free software; you can redistribute it and/or modify it under
8 ;; the terms of the GNU General Public License as published by the Free
9 ;; Software Foundation; either version 2, or (at your option) any later
12 ;; This is distributed in the hope that it will be useful, but WITHOUT
13 ;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 ;; FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 ;; You should have received a copy of the GNU General Public License
18 ;; along with GNU Emacs; see the file COPYING. If not, write to the
19 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 ;; Boston, MA 02110-1301, USA.
26 ;; Dale P. Smith (dpsm AT en DOT com) improved the markup
27 ;; significantly and made many valuable suggestions.
31 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
33 ;; Muse DocBook XML Publishing
35 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
37 (require 'muse-publish
)
38 (require 'muse-regexps
)
40 (defgroup muse-docbook nil
41 "Options controlling the behavior of Muse DocBook XML publishing.
42 See `muse-docbook' for more information."
45 (defcustom muse-docbook-extension
".xml"
46 "Default file extension for publishing DocBook XML files."
50 (defcustom muse-docbook-header
51 "<!DOCTYPE article PUBLIC \"-//OASIS//DTD DocBook V4.2//EN\">
54 <title><lisp>(muse-publishing-directive \"title\")</lisp></title>
55 <author><lisp>(muse-publishing-directive \"author\")</lisp></author>
56 <pubdate><lisp>(muse-publishing-directive \"date\")</lisp></pubdate>
58 <!-- Page published by Emacs Muse begins here -->\n"
59 "Header used for publishing DocBook XML files."
60 :type
'(choice string file
)
63 (defcustom muse-docbook-footer
"
64 <!-- Page published by Emacs Muse ends here -->
66 "Footer used for publishing DocBook XML files."
67 :type
'(choice string file
)
70 (defcustom muse-docbook-markup-regexps
71 `(;; join together the parts of a list or table
72 (10000 "</\\([oud]l\\)>\\s-*<\\1>\\s-*" 0 "")
73 (10100 "</tbody>\\s-*</table>\\s-*<table[^>]*>\\s-*<tbody>\\s-*" 0 "")
74 (10200 "</table>\\s-*<table[^>]*>\\s-*" 0 "")
76 ;; beginning of doc, end of doc, or plain paragraph separator
77 (10300 ,(concat "\\(\n</\\(blockquote\\|center\\)>\\)?"
80 "]*\n\\)+\\|\\`\\s-*\\|\\s-*\\'\\)"
81 "\\(<\\(blockquote\\|center\\)>\n\\)?")
82 0 muse-docbook-markup-paragraph
))
83 "List of markup rules for publishing a Muse page to DocBook XML.
84 For more on the structure of this list, see `muse-publish-markup-regexps'."
85 :type
'(repeat (choice
86 (list :tag
"Markup rule"
88 (choice regexp symbol
)
90 (choice string function symbol
))
94 (defcustom muse-docbook-markup-functions
95 '((table . muse-docbook-markup-table
))
96 "An alist of style types to custom functions for that kind of text.
97 For more on the structure of this list, see
98 `muse-publish-markup-functions'."
99 :type
'(alist :key-type symbol
:value-type function
)
100 :group
'muse-docbook
)
102 (defcustom muse-docbook-markup-strings
103 '((url-link .
"<ulink url=\"%s\">%s</ulink>")
104 (email-addr .
"<email>%s</email>")
105 (emdash .
" — ")
109 (section .
"<section><title>")
110 (section-end .
"</title>")
111 (subsection .
"<section><title>")
112 (subsection-end .
"</title>")
113 (subsubsection .
"<section><title>")
114 (subsubsection-end .
"</title>")
115 (footnote .
"<footnote><para>")
116 (footnote-end .
"</para></footnote>")
117 (begin-underline .
"")
119 (begin-literal .
"<filename>")
120 (end-literal .
"</filename>")
121 (begin-emph .
"<emphasis>")
122 (end-emph .
"</emphasis>")
123 (begin-more-emph .
"<emphasis role=\"strong\">")
124 (end-more-emph .
"</emphasis>")
125 (begin-most-emph .
"<emphasis role=\"strong\"><emphasis>")
126 (end-most-emph .
"</emphasis></emphasis>")
127 (begin-verse .
"<literallayout>\n")
129 (end-verse .
"</literallayout>")
130 (begin-example .
"<programlisting>")
131 (end-example .
"</programlisting>")
132 (begin-center .
"<center>\n")
133 (end-center .
"\n</center>")
134 (begin-quote .
"<blockquote>\n")
135 (end-quote .
"\n</blockquote>")
136 (begin-uli .
"<itemizedlist mark=\"bullet\">\n<listitem><para>")
137 (end-uli .
"</para></listitem>\n</itemizedlist>")
138 (begin-oli .
"<orderedlist>\n<listitem><para>")
139 (end-oli .
"</para></listitem>\n</orderedlist>")
140 (begin-ddt .
"<variablelist>\n<varlistentry>\n<term>")
141 (start-dde .
"</term>\n<listitem><para>")
142 (end-ddt .
"</para></listitem>\n</varlistentry>\n</variablelist>"))
143 "Strings used for marking up text.
144 These cover the most basic kinds of markup, the handling of which
145 differs little between the various styles."
146 :type
'(alist :key-type symbol
:value-type string
)
147 :group
'muse-docbook
)
149 (defcustom muse-docbook-markup-specials
154 "A table of characters which must be represented specially."
155 :type
'(alist :key-type character
:value-type string
)
156 :group
'muse-docbook
)
158 (defun muse-docbook-markup-paragraph ()
159 (let ((end (copy-marker (match-end 0) t
)))
160 (goto-char (match-beginning 0))
161 (when (save-excursion
163 (and (re-search-backward "<\\(/?\\)para[ >]" nil t
)
164 (not (string-equal (match-string 1) "/")))))
173 (unless (eq (char-after) ?\
<)
176 (defun muse-docbook-markup-table ()
177 (let* ((str (save-match-data
178 (if (featurep 'xemacs
)
179 ;; more emacs divergence. :(
180 (replace-in-string (match-string 1) " *|+ *$" "")
182 (fields (append (save-match-data
183 (split-string str
(concat "["
188 (list (match-string 4))))
189 (len (length (match-string 3)))
190 (row (cond ((= len
1) "tbody")
192 ((= len
3) "tfoot")))
194 (concat "<table>\n" "<" row
">\n" "<row>\n<" col
">"
195 (mapconcat 'identity fields
(format "</%s><%s>" col col
))
196 "</" col
">\n" "</row>\n" "</" row
">\n"
199 (defun muse-docbook-fixup-sections ()
200 (goto-char (point-min))
202 (while (re-search-forward "\n*<section>" nil t
)
204 (replace-match "\n</section>\n\n<section>"))
205 (setq last
(match-beginning 0)))
207 (goto-char (point-max))
208 (insert "</section>"))))
210 ;; Register the Muse DocBook XML Publisher
212 (unless (assoc "docbook" muse-publishing-styles
)
213 (muse-define-style "docbook"
214 :suffix
'muse-docbook-extension
215 :regexps
'muse-docbook-markup-regexps
216 :functions
'muse-docbook-markup-functions
217 :strings
'muse-docbook-markup-strings
218 :specials
'muse-docbook-markup-specials
219 :before-end
'muse-docbook-fixup-sections
220 :header
'muse-docbook-header
221 :footer
'muse-docbook-footer
222 :browser
'find-file
))
224 (provide 'muse-docbook
)
226 ;;; muse-docbook.el ends here