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