Warn user when publishing fails due to a private directory.
[muse-el.git] / muse-docbook.el
blobc2842908d04d25bd0774e9e7baf846594cc7ea02
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 ;; the beginning of the buffer begins the first paragraph
74 (10300 "\\`\n*\\([^<]\\)" 0 "<para>\\1")
75 ;; plain paragraph separator
76 (10400 ,(concat "\\(\n</\\(blockquote\\|center\\)>\\)?\n"
77 "\\(["
78 muse-regexp-blank
79 "]*\n\\)+\\(<\\(blockquote\\|center\\)>\n\\)?")
80 0 muse-docbook-markup-paragraph)
81 (10500 "\\s-*\\'" 0 muse-docbook-markup-paragraph-close))
82 "List of markup rules for publishing a Muse page to DocBook XML.
83 For more on the structure of this list, see `muse-publish-markup-regexps'."
84 :type '(repeat (choice
85 (list :tag "Markup rule"
86 integer
87 (choice regexp symbol)
88 integer
89 (choice string function symbol))
90 function))
91 :group 'muse-docbook)
93 (defcustom muse-docbook-markup-functions
94 '((table . muse-docbook-markup-table))
95 "An alist of style types to custom functions for that kind of text.
96 For more on the structure of this list, see
97 `muse-publish-markup-functions'."
98 :type '(alist :key-type symbol :value-type function)
99 :group 'muse-docbook)
101 (defcustom muse-docbook-markup-strings
102 '((url-link . "<ulink url=\"%s\">%s</ulink>")
103 (email-addr . "<email>%s</email>")
104 (emdash . " &mdash; ")
105 (rule . "")
106 (enddots . "....")
107 (dots . "...")
108 (section . "<section><title>")
109 (section-end . "</title>")
110 (subsection . "<section><title>")
111 (subsection-end . "</title>")
112 (subsubsection . "<section><title>")
113 (subsubsection-end . "</title>")
114 (footnote . "<footnote>")
115 (footnote-end . "</footnote>")
116 (begin-underline . "")
117 (end-underline . "")
118 (begin-literal . "<filename>")
119 (end-literal . "</filename>")
120 (begin-emph . "<emphasis>")
121 (end-emph . "</emphasis>")
122 (begin-more-emph . "<emphasis role=\"strong\">")
123 (end-more-emph . "</emphasis>")
124 (begin-most-emph . "<emphasis role=\"strong\"><emphasis>")
125 (end-most-emph . "</emphasis>></emphasis role=\"strong\">")
126 (begin-verse . "<literallayout>\n")
127 (verse-space . " ")
128 (end-verse . "</literallayout>")
129 (begin-example . "<example>")
130 (end-example . "</example>")
131 (begin-center . "<center>\n")
132 (end-center . "\n</center>")
133 (begin-quote . "<blockquote>\n")
134 (end-quote . "\n</blockquote>")
135 (begin-uli . "<itemizedlist mark=\"bullet\">\n<listitem>")
136 (end-uli . "</listitem>\n</itemizedlist>")
137 (begin-oli . "<orderedlist>\n<listitem>")
138 (end-oli . "</listitem>\n</orderedlist>")
139 (begin-ddt . "<dl>\n<dt>")
140 (start-dde . "</dt>\n <dd>")
141 (end-ddt . "</dd>\n</dl>"))
142 "Strings used for marking up text.
143 These cover the most basic kinds of markup, the handling of which
144 differs little between the various styles."
145 :type '(alist :key-type symbol :value-type string)
146 :group 'muse-docbook)
148 (defcustom muse-docbook-markup-specials
149 '((?\" . "&quot;")
150 (?\< . "&lt;")
151 (?\> . "&gt;")
152 (?\& . "&amp;"))
153 "A table of characters which must be represented specially."
154 :type '(alist :key-type character :value-type string)
155 :group 'muse-docbook)
157 (unless (fboundp 'looking-back)
158 (defun looking-back (regexp &optional limit)
159 (save-excursion
160 (re-search-backward (concat "\\(?:" regexp "\\)\\=") limit t))))
162 (defun muse-docbook-markup-paragraph ()
163 (let ((end (copy-marker (match-end 0) t)))
164 (goto-char (match-beginning 0))
165 (unless (eq (char-before) ?\>) (insert "</para>"))
166 (goto-char end)
167 (unless (eq (char-after) ?\<)
168 (insert "<para>"))))
170 (defun muse-docbook-markup-paragraph-close ()
171 (cond
172 ((save-excursion
173 (save-match-data
174 (and (re-search-backward "<\\(/\\)?para[ >]" nil t)
175 (not (equal (match-string 1) "/")))))
176 "</para>\n")
177 ((and (bolp) (eolp))
178 nil)
180 "\n")))
182 (defun muse-docbook-markup-table ()
183 (let* ((str (save-match-data
184 (if (featurep 'xemacs)
185 ;; more emacs divergence. :(
186 (replace-in-string (match-string 1) " *|+ *$" "")
187 (match-string 1))))
188 (fields (append (save-match-data
189 (split-string str (concat "["
190 muse-regexp-blank
191 "]*|+["
192 muse-regexp-blank
193 "]*")))
194 (list (match-string 4))))
195 (len (length (match-string 3)))
196 (row (cond ((= len 1) "tbody")
197 ((= len 2) "thead")
198 ((= len 3) "tfoot")))
199 (col "entry"))
200 (concat "<table>\n" "<" row ">\n" "<row>\n<" col ">"
201 (mapconcat 'identity fields (format "</%s><%s>" col col))
202 "</" col ">\n" "</row>\n" "</" row ">\n"
203 "</table>\n")))
205 (defun muse-docbook-fixup-sections ()
206 (goto-char (point-min))
207 (let (last)
208 (while (re-search-forward "\n*<section>" nil t)
209 (when last
210 (replace-match "\n</section>\n\n<section>"))
211 (setq last (match-beginning 0)))
212 (when last
213 (goto-char (point-max))
214 (insert "</section>"))))
216 ;; Register the Muse DocBook XML Publisher
218 (unless (assoc "docbook" muse-publishing-styles)
219 (muse-define-style "docbook"
220 :suffix 'muse-docbook-extension
221 :regexps 'muse-docbook-markup-regexps
222 :functions 'muse-docbook-markup-functions
223 :strings 'muse-docbook-markup-strings
224 :specials 'muse-docbook-markup-specials
225 :before-end 'muse-docbook-fixup-sections
226 :header 'muse-docbook-header
227 :footer 'muse-docbook-footer
228 :browser 'find-file))
230 (provide 'muse-docbook)
232 ;;; muse-docbook.el ends here