1 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3 ;; Muse HTML Publishing
5 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7 (require 'muse-publish
)
9 (defgroup muse-docbook nil
10 "Options controlling the behaviour of Muse DocBook XML publishing.
11 See `muse-docbook' for more information."
14 (defcustom muse-docbook-extension
".xml"
15 "Default file extension for publishing DocBook XML files."
19 (defcustom muse-docbook-header
20 "<!DOCTYPE article PUBLIC \"-//OASIS//DTD DocBook V4.2//EN\">
23 <title><lisp>(muse-publishing-directive \"title\")</lisp></title>
24 <author><lisp>(muse-publishing-directive \"author\")</lisp></author>
25 <pubdate><lisp>(muse-publishing-directive \"date\")</lisp></pubdate>
27 <!-- Page published by Emacs Muse begins here -->\n"
28 "Header used for publishing DocBook XML files."
29 :type
'(choice string file
)
32 (defcustom muse-docbook-footer
"
33 <!-- Page published by Emacs Muse ends here -->
35 "Footer used for publishing DocBook XML files."
36 :type
'(choice string file
)
39 (defcustom muse-docbook-markup-regexps
40 `(;; join together the parts of a list or table
41 (10000 "</\\([oud]l\\)>\\s-*<\\1>\\s-*" 0 "")
42 (10100 "</tbody>\\s-*</table>\\s-*<table[^>]*>\\s-*<tbody>\\s-*" 0 "")
43 (10200 "</table>\\s-*<table[^>]*>\\s-*" 0 "")
45 ;; the beginning of the buffer begins the first paragraph
46 (10300 "\\`\n*\\([^<]\\)" 0 "<para>\\1")
47 ;; plain paragraph separator
48 (10400 ,(concat "\\(\n</\\(blockquote\\|center\\)>\\)?\n"
49 "\\([[:blank:]]*\n\\)+\\(<\\(blockquote\\|center\\)>\n\\)?") 0
50 muse-docbook-markup-paragraph
)
51 (10500 "\\([^>[:space:]]\\)\\s-+\\'" 0 "\\1</para>\n"))
52 "List of markup rules for publishing a Muse page to DocBook XML.
53 For more on the structure of this list, see `muse-publish-markup-regexps'."
54 :type
'(repeat (choice
55 (list :tag
"Markup rule"
57 (choice regexp symbol
)
59 (choice string function symbol
))
63 (defcustom muse-docbook-markup-functions
64 '((table . muse-docbook-markup-table
))
65 "An alist of style types to custom functions for that kind of text.
66 For more on the structure of this list, see
67 `muse-publish-markup-functions'."
68 :type
'(alist :key-type symbol
:value-type function
)
71 (defcustom muse-docbook-markup-strings
72 '((url-link .
"<ulink url=\"%s\">%s</ulink>")
73 (email-addr .
"<email>%s</email>")
78 (section .
"<section><title>")
79 (section-end .
"</title>")
80 (subsection .
"<section><title>")
81 (subsection-end .
"</title>")
82 (subsubsection .
"<section><title>")
83 (subsubsection-end .
"</title>")
84 (footnote .
"<footnote>")
85 (footnote-end .
"</footnote>")
86 (begin-underline .
"")
88 (begin-literal .
"<filename>")
89 (end-literal .
"</filename>")
90 (begin-emph .
"<emphasis>")
91 (end-emph .
"</emphasis>")
92 (begin-more-emph .
"<emphasis role=\"strong\">")
93 (end-more-emph .
"</emphasis>")
94 (begin-most-emph .
"<emphasis role=\"strong\"><emphasis>")
95 (end-most-emph .
"</emphasis>></emphasis role=\"strong\">")
96 (begin-verse .
"<literallayout>\n")
98 (end-verse .
"</literallayout>")
99 (begin-example .
"<example>")
100 (end-example .
"</example>")
101 (begin-center .
"<center>\n")
102 (end-center .
"\n</center>")
103 (begin-quote .
"<blockquote>\n")
104 (end-quote .
"\n</blockquote>")
105 (begin-uli .
"<itemizedlist mark=\"bullet\">\n<listitem>")
106 (end-uli .
"</listitem>\n</itemizedlist>")
107 (begin-oli .
"<orderedlist>\n<listitem>")
108 (end-oli .
"</listitem>\n</orderedlist>")
109 (begin-ddt .
"<dl>\n<dt>")
110 (start-dde .
"</dt>\n <dd>")
111 (end-ddt .
"</dd>\n</dl>"))
112 "Strings used for marking up text.
113 These cover the most basic kinds of markup, the handling of which
114 differs little between the various styles."
115 :type
'(alist :key-type symbol
:value-type string
)
116 :group
'muse-docbook
)
118 (defcustom muse-docbook-markup-specials
123 "A table of characters which must be represented specially."
124 :type
'(alist :key-type character
:value-type string
)
125 :group
'muse-docbook
)
127 (unless (fboundp 'looking-back
)
128 (defun looking-back (regexp &optional limit
)
130 (re-search-backward (concat "\\(?:" regexp
"\\)\\=") limit t
))))
132 (defun muse-docbook-markup-paragraph ()
133 (let ((end (copy-marker (match-end 0) t
)))
134 (goto-char (match-beginning 0))
135 (unless (eq (char-before) ?\
>) (insert "</para>"))
137 (unless (eq (char-after) ?\
<)
140 (defun muse-docbook-markup-table ()
141 (let* ((str (save-match-data
142 (if (featurep 'xemacs
)
143 ;; more emacs divergence. :(
144 (replace-in-string (match-string 1) " *|+ *$" "")
146 (fields (append (save-match-data
147 (split-string str
"[[:blank:]]*|+[[:blank:]]*"))
148 (list (match-string 4))))
149 (len (length (match-string 3)))
150 (row (cond ((= len
1) "tbody")
152 ((= len
3) "tfoot")))
154 (concat "<table>\n" "<" row
">\n" "<row>\n<" col
">"
155 (mapconcat 'identity fields
(format "</%s><%s>" col col
))
156 "</" col
">\n" "</row>\n" "</" row
">\n"
159 (defun muse-docbook-fixup-sections ()
160 (goto-char (point-min))
162 (while (re-search-forward "\n*<section>" nil t
)
164 (replace-match "\n</section>\n\n<section>"))
165 (setq last
(match-beginning 0)))
167 (goto-char (point-max))
168 (insert "</section>"))))
170 ;; Register the Muse DocBook XML Publisher
172 (unless (assoc "docbook" muse-publishing-styles
)
173 (muse-define-style "docbook"
174 :suffix
'muse-docbook-extension
175 :regexps
'muse-docbook-markup-regexps
176 :functions
'muse-docbook-markup-functions
177 :strings
'muse-docbook-markup-strings
178 :specials
'muse-docbook-markup-specials
179 :before-end
'muse-docbook-fixup-sections
180 :header
'muse-docbook-header
181 :footer
'muse-docbook-footer
182 :browser
'find-file
))
184 (provide 'muse-docbook
)
186 ;;; muse-docbook.el ends here