Move regexps to same group, only make 4 heading faces.
[muse-el.git] / muse-docbook.el
blob84b5ba78383d3c1527f898ef443a6b8da6ebd457
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
10 ;; version.
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
15 ;; for more details.
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., 59 Temple Place - Suite 330, Boston,
20 ;; MA 02111-1307, USA.
22 ;;; Commentary:
24 ;;; Contributors:
26 ;;; Code:
28 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
30 ;; Muse DocBook XML Publishing
32 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
34 (require 'muse-publish)
35 (require 'muse-regexps)
37 (defgroup muse-docbook nil
38 "Options controlling the behaviour of Muse DocBook XML publishing.
39 See `muse-docbook' for more information."
40 :group 'muse-publish)
42 (defcustom muse-docbook-extension ".xml"
43 "Default file extension for publishing DocBook XML files."
44 :type 'string
45 :group 'muse-docbook)
47 (defcustom muse-docbook-header
48 "<!DOCTYPE article PUBLIC \"-//OASIS//DTD DocBook V4.2//EN\">
49 <article>
50 <articleinfo>
51 <title><lisp>(muse-publishing-directive \"title\")</lisp></title>
52 <author><lisp>(muse-publishing-directive \"author\")</lisp></author>
53 <pubdate><lisp>(muse-publishing-directive \"date\")</lisp></pubdate>
54 </articleinfo>
55 <!-- Page published by Emacs Muse begins here -->\n"
56 "Header used for publishing DocBook XML files."
57 :type '(choice string file)
58 :group 'muse-docbook)
60 (defcustom muse-docbook-footer "
61 <!-- Page published by Emacs Muse ends here -->
62 </article>\n"
63 "Footer used for publishing DocBook XML files."
64 :type '(choice string file)
65 :group 'muse-docbook)
67 (defcustom muse-docbook-markup-regexps
68 `(;; join together the parts of a list or table
69 (10000 "</\\([oud]l\\)>\\s-*<\\1>\\s-*" 0 "")
70 (10100 "</tbody>\\s-*</table>\\s-*<table[^>]*>\\s-*<tbody>\\s-*" 0 "")
71 (10200 "</table>\\s-*<table[^>]*>\\s-*" 0 "")
73 ;; beginning of doc, end of doc, or plain paragraph separator
74 (10300 ,(concat "\\(\n</\\(blockquote\\|center\\)>\\)?"
75 "\\(?:\n\\(["
76 muse-regexp-blank
77 "]*\n\\)+\\|\\`\\s-*\\|\\s-*\\'\\)"
78 "\\(<\\(blockquote\\|center\\)>\n\\)?")
79 0 muse-docbook-markup-paragraph))
80 "List of markup rules for publishing a Muse page to DocBook XML.
81 For more on the structure of this list, see `muse-publish-markup-regexps'."
82 :type '(repeat (choice
83 (list :tag "Markup rule"
84 integer
85 (choice regexp symbol)
86 integer
87 (choice string function symbol))
88 function))
89 :group 'muse-docbook)
91 (defcustom muse-docbook-markup-functions
92 '((table . muse-docbook-markup-table))
93 "An alist of style types to custom functions for that kind of text.
94 For more on the structure of this list, see
95 `muse-publish-markup-functions'."
96 :type '(alist :key-type symbol :value-type function)
97 :group 'muse-docbook)
99 (defcustom muse-docbook-markup-strings
100 '((url-link . "<ulink url=\"%s\">%s</ulink>")
101 (email-addr . "<email>%s</email>")
102 (emdash . " &mdash; ")
103 (rule . "")
104 (enddots . "....")
105 (dots . "...")
106 (section . "<section><title>")
107 (section-end . "</title>")
108 (subsection . "<section><title>")
109 (subsection-end . "</title>")
110 (subsubsection . "<section><title>")
111 (subsubsection-end . "</title>")
112 (footnote . "<footnote>")
113 (footnote-end . "</footnote>")
114 (begin-underline . "")
115 (end-underline . "")
116 (begin-literal . "<filename>")
117 (end-literal . "</filename>")
118 (begin-emph . "<emphasis>")
119 (end-emph . "</emphasis>")
120 (begin-more-emph . "<emphasis role=\"strong\">")
121 (end-more-emph . "</emphasis>")
122 (begin-most-emph . "<emphasis role=\"strong\"><emphasis>")
123 (end-most-emph . "</emphasis>></emphasis role=\"strong\">")
124 (begin-verse . "<literallayout>\n")
125 (verse-space . " ")
126 (end-verse . "</literallayout>")
127 (begin-example . "<example>")
128 (end-example . "</example>")
129 (begin-center . "<center>\n")
130 (end-center . "\n</center>")
131 (begin-quote . "<blockquote>\n")
132 (end-quote . "\n</blockquote>")
133 (begin-uli . "<itemizedlist mark=\"bullet\">\n<listitem>")
134 (end-uli . "</listitem>\n</itemizedlist>")
135 (begin-oli . "<orderedlist>\n<listitem>")
136 (end-oli . "</listitem>\n</orderedlist>")
137 (begin-ddt . "<dl>\n<dt>")
138 (start-dde . "</dt>\n <dd>")
139 (end-ddt . "</dd>\n</dl>"))
140 "Strings used for marking up text.
141 These cover the most basic kinds of markup, the handling of which
142 differs little between the various styles."
143 :type '(alist :key-type symbol :value-type string)
144 :group 'muse-docbook)
146 (defcustom muse-docbook-markup-specials
147 '((?\" . "&quot;")
148 (?\< . "&lt;")
149 (?\> . "&gt;")
150 (?\& . "&amp;"))
151 "A table of characters which must be represented specially."
152 :type '(alist :key-type character :value-type string)
153 :group 'muse-docbook)
155 (defun muse-docbook-markup-paragraph ()
156 (let ((end (copy-marker (match-end 0) t)))
157 (goto-char (match-beginning 0))
158 (when (save-excursion
159 (save-match-data
160 (and (re-search-backward "<\\(/\\)?para[ >]" nil t)
161 (not (string-equal (match-string 1) "/")))))
162 (insert "</para>"))
163 (goto-char end))
164 (if (eobp)
165 (cond
166 ((bolp)
167 nil)
169 (insert "\n")))
170 (unless (eq (char-after) ?\<)
171 (insert "<para>"))))
173 (defun muse-docbook-markup-table ()
174 (let* ((str (save-match-data
175 (if (featurep 'xemacs)
176 ;; more emacs divergence. :(
177 (replace-in-string (match-string 1) " *|+ *$" "")
178 (match-string 1))))
179 (fields (append (save-match-data
180 (split-string str (concat "["
181 muse-regexp-blank
182 "]*|+["
183 muse-regexp-blank
184 "]*")))
185 (list (match-string 4))))
186 (len (length (match-string 3)))
187 (row (cond ((= len 1) "tbody")
188 ((= len 2) "thead")
189 ((= len 3) "tfoot")))
190 (col "entry"))
191 (concat "<table>\n" "<" row ">\n" "<row>\n<" col ">"
192 (mapconcat 'identity fields (format "</%s><%s>" col col))
193 "</" col ">\n" "</row>\n" "</" row ">\n"
194 "</table>\n")))
196 (defun muse-docbook-fixup-sections ()
197 (goto-char (point-min))
198 (let (last)
199 (while (re-search-forward "\n*<section>" nil t)
200 (when last
201 (replace-match "\n</section>\n\n<section>"))
202 (setq last (match-beginning 0)))
203 (when last
204 (goto-char (point-max))
205 (insert "</section>"))))
207 ;; Register the Muse DocBook XML Publisher
209 (unless (assoc "docbook" muse-publishing-styles)
210 (muse-define-style "docbook"
211 :suffix 'muse-docbook-extension
212 :regexps 'muse-docbook-markup-regexps
213 :functions 'muse-docbook-markup-functions
214 :strings 'muse-docbook-markup-strings
215 :specials 'muse-docbook-markup-specials
216 :before-end 'muse-docbook-fixup-sections
217 :header 'muse-docbook-header
218 :footer 'muse-docbook-footer
219 :browser 'find-file))
221 (provide 'muse-docbook)
223 ;;; muse-docbook.el ends here