74
75
:group 'muse-docbook)
76
77
(defcustom muse-docbook-markup-regexps
77
`(;; Join together the parts of a table
78
(10000 ,(concat " </t\\(body\\|head\\|foot\\)>\\s-*"
79
"</tgroup>\\s-*</informaltable>"
80
"\\([" muse-regexp-blank "]*\n\\)\\{0,2\\}"
81
"[" muse-regexp-blank "]*"
82
"<informaltable[^>]*>\\s-*<tgroup[^>]*>\\s-*"
85
(10100 ,(concat " </tgroup>\\s-*</informaltable>"
86
"\\([" muse-regexp-blank "]*\n\\)\\{0,2\\}"
87
"[" muse-regexp-blank "]*"
88
"<informaltable[^>]*>\\s-*<tgroup[^>]*>\n")
91
;; Join together the parts of a list
92
(10200 ,(concat "</\\(itemized\\|ordered\\|variable\\)list>"
93
"\\([" muse-regexp-blank "]*\n\\)\\{0,2\\}"
94
"[" muse-regexp-blank "]*"
95
"<\\1list" "[^>]*>\\s-*")
98
;; Beginning of doc, end of doc, or plain paragraph separator
99
(10300 ,(concat "\\(\n</\\(blockquote\\|center\\)>\\)?"
102
"]*\n\\)+\\)\\|\\`\\s-*\\|\\s-*\\'\\)"
103
"\\(<\\(blockquote\\|center\\)>\n\\)?")
104
0 muse-docbook-markup-paragraph))
78
`(;; Beginning of doc, end of doc, or plain paragraph separator
79
(10000 ,(concat "\\(\\(\n\\(?:[" muse-regexp-blank "]*\n\\)*"
80
"\\([" muse-regexp-blank "]*\n\\)\\)"
81
"\\|\\`\\s-*\\|\\s-*\\'\\)")
82
3 muse-docbook-markup-paragraph))
105
83
"List of markup rules for publishing a Muse page to DocBook XML.
106
84
For more on the structure of this list, see `muse-publish-markup-regexps'."
107
85
:type '(repeat (choice
123
101
:group 'muse-docbook)
125
103
(defcustom muse-docbook-markup-strings
126
'((url-link . "<ulink url=\"%s\">%s</ulink>")
127
(internal-link . "<link linkend=\"%s\">%s</link>")
104
'((image-with-desc . "<mediaobject>
106
<imagedata fileref=\"%1%.%2%\" format=\"%2%\" />
108
<caption><para>%3%</para></caption>
110
(image . "<inlinemediaobject><imageobject>
111
<imagedata fileref=\"%1%.%2%\" format=\"%2%\" />
112
</imageobject></inlinemediaobject>")
113
(image-link . "<ulink url=\"%1%\"><inlinemediaobject><imageobject>
114
<imagedata fileref=\"%2%.%3%\" format=\"%3%\" />
115
</imageobject></inlinemediaobject></ulink>")
116
(anchor-ref . "<link linkend=\"%s\">%s</link>")
117
(url . "<ulink url=\"%s\">%s</ulink>")
118
(link . "<ulink url=\"%s\">%s</ulink>")
119
(link-and-anchor . "<ulink url=\"%s#%s\">%s</ulink>")
128
120
(email-addr . "<email>%s</email>")
129
(emdash . " — ")
121
(anchor . "<anchor id=\"%s\" />\n")
122
(emdash . "%s—%s")
130
123
(comment-begin . "<!-- ")
131
124
(comment-end . " -->")
163
156
(end-center . "\n</para>")
164
157
(begin-quote . "<blockquote>\n")
165
158
(end-quote . "\n</blockquote>")
166
(begin-uli . "<itemizedlist mark=\"bullet\">\n<listitem><para>")
167
(end-uli . "</para></listitem>\n</itemizedlist>")
168
(begin-oli . "<orderedlist>\n<listitem><para>")
169
(end-oli . "</para></listitem>\n</orderedlist>")
170
(begin-ddt . "<variablelist>\n<varlistentry>\n<term>")
171
(start-dde . "</term>\n<listitem><para>")
172
(end-ddt . "</para></listitem>\n</varlistentry>\n</variablelist>"))
159
(begin-quote-item . "<para>")
160
(end-quote-item . "</para>")
161
(begin-uli . "<itemizedlist mark=\"bullet\">\n")
162
(end-uli . "\n</itemizedlist>")
163
(begin-uli-item . "<listitem><para>")
164
(end-uli-item . "</para></listitem>")
165
(begin-oli . "<orderedlist>\n")
166
(end-oli . "\n</orderedlist>")
167
(begin-oli-item . "<listitem><para>")
168
(end-oli-item . "</para></listitem>")
169
(begin-dl . "<variablelist>\n")
170
(end-dl . "\n</variablelist>")
171
(begin-dl-item . "<varlistentry>\n")
172
(end-dl-item . "\n</varlistentry>")
173
(begin-ddt . "<term>")
174
(end-ddt . "</term>")
175
(begin-dde . "<listitem><para>")
176
(end-dde . "</para></listitem>")
177
(begin-table . "<informaltable>\n")
178
(end-table . "</informaltable>")
179
(begin-table-group . " <tgroup cols='%s'>\n")
180
(end-table-group . " </tgroup>\n")
181
(begin-table-row . " <row>\n")
182
(end-table-row . " </row>\n")
183
(begin-table-entry . " <entry>")
184
(end-table-entry . "</entry>\n"))
173
185
"Strings used for marking up text.
174
186
These cover the most basic kinds of markup, the handling of which
175
187
differs little between the various styles."
176
188
:type '(alist :key-type symbol :value-type string)
177
189
:group 'muse-docbook)
179
(defcustom muse-docbook-markup-specials
184
"A table of characters which must be represented specially."
185
:type '(alist :key-type character :value-type string)
186
:group 'muse-docbook)
188
191
(defcustom muse-docbook-encoding-default 'utf-8
189
192
"The default Emacs buffer encoding to use in published files.
190
193
This will be used if no special characters are found."
198
201
:group 'muse-docbook)
200
(defcustom muse-docbook-encoding-map
201
'((iso-8859-1 . "iso-8859-1")
202
(iso-2022-jp . "iso-2022-jp")
204
(japanese-iso-8bit . "euc-jp")
205
(chinese-big5 . "big5")
206
(mule-utf-8 . "utf-8")
207
(chinese-iso-8bit . "gb2312")
208
(chinese-gbk . "gbk"))
209
"An alist mapping emacs coding systems to appropriate DocBook charsets.
210
Use the base name of the coding system (i.e. without the -unix)."
211
:type '(alist :key-type coding-system :value-type string)
212
:group 'muse-docbook)
214
(defun muse-docbook-transform-content-type (content-type)
215
"Using `muse-docbook-encoding-map', try and resolve an emacs
216
coding system to an associated DocBook XML coding system. If no
217
match is found, `muse-docbook-charset-default' is used instead."
218
(let ((match (and (fboundp 'coding-system-base)
219
(assoc (coding-system-base content-type)
220
muse-docbook-encoding-map))))
223
muse-docbook-charset-default)))
225
203
(defun muse-docbook-encoding ()
226
(muse-docbook-transform-content-type
204
(muse-xml-transform-content-type
227
205
(or (and (boundp 'buffer-file-coding-system)
228
206
buffer-file-coding-system)
229
muse-docbook-encoding-default)))
207
muse-docbook-encoding-default)
208
muse-docbook-charset-default))
231
210
(defun muse-docbook-markup-paragraph ()
232
(let ((end (copy-marker (match-end 0) t)))
233
(goto-char (match-beginning 0))
234
(when (save-excursion
236
(and (re-search-backward "<\\(/?\\)\\(para\\|footnote\\)[ >]"
238
(or (and (string= (match-string 2) "para")
239
(not (string= (match-string 1) "/")))
240
(and (string= (match-string 2) "footnote")
241
(string= (match-string 1) "/"))))))
248
((eq (char-after) ?\<)
249
(when (looking-at (concat "<\\(emphasis\\|systemitem"
250
"\\|u?link\\|anchor\\|email\\)[ >]"))
255
(defun muse-docbook-insert-anchor (anchor)
256
"Insert an anchor, either before the next word, or within a tag."
257
(unless (get-text-property (match-end 1) 'noemphasis)
258
(skip-chars-forward (concat muse-regexp-blank "\n"))
259
(when (looking-at "<\\([^ />]+\\)>")
260
(goto-char (match-end 0)))
261
(insert "<anchor id=\"" anchor "\" />\n")))
263
(defun muse-docbook-markup-anchor ()
265
(muse-docbook-insert-anchor (match-string 2)))
268
(defun muse-docbook-markup-table ()
271
(delete-region (match-beginning 0) (match-end 0))))
272
(fields (split-string str "\\s-*|+\\s-*"))
273
(type (and (string-match "\\s-*\\(|+\\)\\s-*" str)
274
(length (match-string 1 str))))
275
(part (cond ((= type 1) "tbody")
277
((= type 3) "tfoot"))))
278
(insert "<informaltable>\n"
279
" <tgroup cols='" (number-to-string (length fields)) "'>\n"
282
(dolist (field fields)
283
(insert " <entry>" field "</entry>\n"))
287
"</informaltable>\n")))
212
(let ((end (copy-marker (match-end 0) t)))
213
(goto-char (match-beginning 0))
214
(when (save-excursion
216
(and (re-search-backward
217
"<\\(/?\\)\\(para\\|footnote\\|literallayout\\)[ >]"
219
(cond ((string= (match-string 2) "literallayout")
221
((string= (match-string 2) "para")
223
(not (string= (match-string 1) "/"))
224
;; don't mess up nested lists
225
(not (and (muse-looking-back "<listitem>")
226
(throw 'bail-out t)))))
227
((string= (match-string 2) "footnote")
228
(string= (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 "</para>"))
238
((eq (char-after) ?\<)
239
(when (looking-at (concat "<\\(emphasis\\|systemitem\\|inlinemediaobject"
240
"\\|u?link\\|anchor\\|email\\)[ >]"))
241
(muse-insert-markup "<para>")))
243
(muse-insert-markup "<para>")))))
289
245
(defun muse-docbook-get-author (&optional author)
290
246
"Split the AUTHOR directive into separate fields.
314
270
"<surname>" last "</surname>"))))))
316
(defun muse-docbook-fixup-tables ()
272
(defun muse-docbook-fixup-images ()
318
273
(goto-char (point-min))
320
(while (re-search-forward "^ *<tgroup[^>]*>$" nil t)
321
(unless (get-text-property (point) 'read-only)
325
(narrow-to-region beg (and (re-search-forward "^ *</tgroup>"
327
(match-beginning 0))))
328
(goto-char (point-min))
329
(let ((inhibit-read-only t))
333
(if (re-search-forward
334
"^\\s-*<t\\(head\\|body\\|foot\\)>$" nil t)
335
(goto-char (match-beginning 0))
336
(goto-char (point-max)))))
339
(if (re-search-forward
340
"^\\s-*</t\\(head\\|body\\|foot\\)>$" nil t)
341
(goto-char (match-end 0))
342
(goto-char (point-max)))))
345
(looking-at "\\s-*<t\\(head\\|body\\|foot\\)>")
346
(cond ((string= (match-string 1) "head") 1)
347
((string= (match-string 1) "foot") 2)
274
(while (re-search-forward (concat "<imagedata fileref=\"[^\"]+\""
275
" format=\"\\([^\"]+\\)\" />$")
277
(replace-match (upcase (match-string 1)) t t nil 1)))
279
(defun muse-docbook-munge-buffer ()
280
(muse-docbook-fixup-images))
350
282
(defun muse-docbook-finalize-buffer ()
351
283
(when (boundp 'buffer-file-coding-system)
353
285
;; make it agree with the default charset
354
286
(setq buffer-file-coding-system muse-docbook-encoding-default))))
356
;; Register the Muse DocBook XML Publisher
288
;;; Register the Muse DocBook XML Publisher
358
(unless (assoc "docbook" muse-publishing-styles)
359
(muse-define-style "docbook"
360
:suffix 'muse-docbook-extension
361
:regexps 'muse-docbook-markup-regexps
362
:functions 'muse-docbook-markup-functions
363
:strings 'muse-docbook-markup-strings
364
:specials 'muse-docbook-markup-specials
365
:before-end 'muse-docbook-fixup-tables
366
:after 'muse-docbook-finalize-buffer
367
:header 'muse-docbook-header
368
:footer 'muse-docbook-footer
369
:browser 'find-file))
290
(muse-define-style "docbook"
291
:suffix 'muse-docbook-extension
292
:regexps 'muse-docbook-markup-regexps
293
:functions 'muse-docbook-markup-functions
294
:strings 'muse-docbook-markup-strings
295
:specials 'muse-xml-decide-specials
296
:before-end 'muse-docbook-munge-buffer
297
:after 'muse-docbook-finalize-buffer
298
:header 'muse-docbook-header
299
:footer 'muse-docbook-footer
371
302
(provide 'muse-docbook)