1 ;;; muse-xml.el --- publish XML files
3 ;; Copyright (C) 2005, 2006, 2007 Free Software Foundation, Inc.
5 ;; Author: Michael Olson <mwolson@gnu.org>
6 ;; Date: Sat 23-Jul-2005
8 ;; This file is part of Emacs Muse. It is not part of GNU Emacs.
10 ;; Emacs Muse is free software; you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published
12 ;; by the Free Software Foundation; either version 3, or (at your
13 ;; option) any later version.
15 ;; Emacs Muse is distributed in the hope that it will be useful, but
16 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 ;; General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with Emacs Muse; see the file COPYING. If not, write to the
22 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
23 ;; Boston, MA 02110-1301, USA.
27 ;; James Clarke's nxml-mode can be used for editing and validating
28 ;; Muse-generated XML files. If you are in nxml-mode use the command
29 ;; C-c C-s C-f to point to the schema in `contrib/muse.rnc', which
30 ;; comes with Muse. Say yes if you are asked if you want to copy the
31 ;; file to your location. C-c C-s C-a can then be used to reload the
32 ;; schema if you make changes to the file.
36 ;; Peter K. Lee (saint AT corenova DOT com) made the initial
37 ;; implementation of planner-publish.el, which was heavily borrowed
40 ;; Brad Collins (brad AT chenla DOT org) provided a Compact RelaxNG
45 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
47 ;; Muse XML Publishing
49 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
51 (require 'muse-publish
)
52 (require 'muse-regexps
)
53 (require 'muse-xml-common
)
55 (defgroup muse-xml nil
56 "Options controlling the behavior of Muse XML publishing.
57 See `muse-xml' for more information."
60 (defcustom muse-xml-extension
".xml"
61 "Default file extension for publishing XML files."
65 (defcustom muse-xml-header
66 "<?xml version=\"1.0\" encoding=\"<lisp>
67 (muse-xml-encoding)</lisp>\"?>
70 <title><lisp>(muse-publishing-directive \"title\")</lisp></title>
71 <author><lisp>(muse-publishing-directive \"author\")</lisp></author>
72 <maintainer><lisp>(muse-style-element :maintainer)</lisp></maintainer>
73 <pubdate><lisp>(muse-publishing-directive \"date\")</lisp></pubdate>
75 <!-- Page published by Emacs Muse begins here -->\n"
76 "Header used for publishing XML files.
77 This may be text or a filename."
81 (defcustom muse-xml-footer
"
82 <!-- Page published by Emacs Muse ends here -->
84 "Footer used for publishing XML files.
85 This may be text or a filename."
89 (defcustom muse-xml-markup-regexps
90 `(;; Beginning of doc, end of doc, or plain paragraph separator
91 (10000 ,(concat "\\(\\(\n\\(?:[" muse-regexp-blank
"]*\n\\)*"
92 "\\([" muse-regexp-blank
"]*\n\\)\\)"
93 "\\|\\`\\s-*\\|\\s-*\\'\\)")
94 ;; this is somewhat repetitive because we only require the
95 ;; line just before the paragraph beginning to be not
97 3 muse-xml-markup-paragraph
))
98 "List of markup rules for publishing a Muse page to XML.
99 For more on the structure of this list, see `muse-publish-markup-regexps'."
100 :type
'(repeat (choice
101 (list :tag
"Markup rule"
103 (choice regexp symbol
)
105 (choice string function symbol
))
109 (defcustom muse-xml-markup-functions
110 '((anchor . muse-xml-markup-anchor
)
111 (table . muse-xml-markup-table
))
112 "An alist of style types to custom functions for that kind of text.
113 For more on the structure of this list, see
114 `muse-publish-markup-functions'."
115 :type
'(alist :key-type symbol
:value-type function
)
118 (defcustom muse-xml-markup-strings
119 '((image-with-desc .
"<image href=\"%s.%s\">%s</image>")
120 (image .
"<image href=\"%s.%s\"></image>")
121 (image-link .
"<link type=\"image\" href=\"%s\">%s.%s</link>")
122 (anchor-ref .
"<link type=\"url\" href=\"#%s\">%s</link>")
123 (url .
"<link type=\"url\" href=\"%s\">%s</link>")
124 (link .
"<link type=\"url\" href=\"%s\">%s</link>")
125 (link-and-anchor .
"<link type=\"url\" href=\"%s#%s\">%s</link>")
126 (email-addr .
"<link type=\"email\" href=\"%s\">%s</link>")
127 (anchor .
"<anchor id=\"%s\" />\n")
129 (comment-begin .
"<!-- ")
130 (comment-end .
" -->")
132 (fn-sep .
"<hr />\n")
133 (no-break-space .
" ")
136 (section .
"<section level=\"1\"><title>")
137 (section-end .
"</title>")
138 (subsection .
"<section level=\"2\"><title>")
139 (subsection-end .
"</title>")
140 (subsubsection .
"<section level=\"3\"><title>")
141 (subsubsection-end .
"</title>")
142 (section-other .
"<section level=\"%s\"><title>")
143 (section-other-end .
"</title>")
144 (section-close .
"</section>")
145 (footnote .
"<footnote>")
146 (footnote-end .
"</footnote>")
147 (begin-underline .
"<format type=\"underline\">")
148 (end-underline .
"</format>")
149 (begin-literal .
"<code>")
150 (end-literal .
"</code>")
151 (begin-emph .
"<format type=\"emphasis\" level=\"1\">")
152 (end-emph .
"</format>")
153 (begin-more-emph .
"<format type=\"emphasis\" level=\"2\">")
154 (end-more-emph .
"</format>")
155 (begin-most-emph .
"<format type=\"emphasis\" level=\"3\">")
156 (end-most-emph .
"</format>")
157 (begin-verse .
"<verse>\n")
158 (begin-verse-line .
"<line>")
159 (end-verse-line .
"</line>")
160 (empty-verse-line .
"<line />")
161 (begin-last-stanza-line .
"<line>")
162 (end-last-stanza-line .
"</line>")
163 (end-verse .
"</verse>")
164 (begin-example .
"<example>")
165 (end-example .
"</example>")
166 (begin-center .
"<p><format type=\"center\">\n")
167 (end-center .
"\n</format></p>")
168 (begin-quote .
"<blockquote>\n")
169 (end-quote .
"\n</blockquote>")
171 (begin-cite-author .
"")
172 (begin-cite-year .
"")
174 (begin-quote-item .
"<p>")
175 (end-quote-item .
"</p>")
176 (begin-uli .
"<list type=\"unordered\">\n")
177 (end-uli .
"\n</list>")
178 (begin-uli-item .
"<item>")
179 (end-uli-item .
"</item>")
180 (begin-oli .
"<list type=\"ordered\">\n")
181 (end-oli .
"\n</list>")
182 (begin-oli-item .
"<item>")
183 (end-oli-item .
"</item>")
184 (begin-dl .
"<list type=\"definition\">\n")
185 (end-dl .
"\n</list>")
186 (begin-dl-item .
"<item>\n")
187 (end-dl-item .
"\n</item>")
188 (begin-ddt .
"<term>")
189 (end-ddt .
"</term>")
190 (begin-dde .
"<definition>")
191 (end-dde .
"</definition>")
192 (begin-table .
"<table%s>\n")
193 (end-table .
"</table>")
194 (begin-table-row .
" <tr>\n")
195 (end-table-row .
" </tr>\n")
196 (begin-table-entry .
" <%s>")
197 (end-table-entry .
"</%s>\n"))
198 "Strings used for marking up text.
199 These cover the most basic kinds of markup, the handling of which
200 differs little between the various styles."
201 :type
'(alist :key-type symbol
:value-type string
)
204 (defcustom muse-xml-encoding-default
'utf-8
205 "The default Emacs buffer encoding to use in published files.
206 This will be used if no special characters are found."
210 (defcustom muse-xml-charset-default
"utf-8"
211 "The default XML charset to use if no translation is
212 found in `muse-xml-encoding-map'."
216 (defun muse-xml-encoding ()
217 (muse-xml-transform-content-type
218 (or (and (boundp 'buffer-file-coding-system
)
219 buffer-file-coding-system
)
220 muse-xml-encoding-default
)
221 muse-xml-charset-default
))
223 (defun muse-xml-markup-paragraph ()
224 (let ((end (copy-marker (match-end 0) t
)))
225 (goto-char (match-beginning 0))
226 (when (save-excursion
228 (and (re-search-backward "<\\(/?\\)p[ >]" nil t
)
229 (not (string-equal (match-string 1) "/")))))
230 (when (get-text-property (1- (point)) 'end-list
)
231 (goto-char (previous-single-property-change (1- (point)) 'end-list
)))
232 (muse-insert-markup "</p>"))
238 ((eq (char-after) ?\
<)
239 (when (looking-at (concat "<\\(format\\|code\\|link\\|image"
240 "\\|anchor\\|footnote\\)[ >]"))
241 (muse-insert-markup "<p>")))
243 (muse-insert-markup "<p>"))))
245 (defun muse-xml-finalize-buffer ()
246 (when (boundp 'buffer-file-coding-system
)
247 (when (memq buffer-file-coding-system
'(no-conversion undecided-unix
))
248 ;; make it agree with the default charset
249 (setq buffer-file-coding-system muse-xml-encoding-default
))))
251 ;;; Register the Muse XML Publisher
253 (muse-define-style "xml"
254 :suffix
'muse-xml-extension
255 :regexps
'muse-xml-markup-regexps
256 :functions
'muse-xml-markup-functions
257 :strings
'muse-xml-markup-strings
258 :specials
'muse-xml-decide-specials
259 :after
'muse-xml-finalize-buffer
260 :header
'muse-xml-header
261 :footer
'muse-xml-footer
266 ;;; muse-xml.el ends here