Merge ../master
[muse-el.git] / lisp / muse-html.el
blob5f937d573acc541c0f0d8463a6b80a35096522a0
1 ;;; muse-html.el --- publish to HTML and XHTML
3 ;; Copyright (C) 2004, 2005, 2006, 2007 Free Software Foundation, Inc.
5 ;; This file is part of Emacs Muse. It is not part of GNU Emacs.
7 ;; Emacs Muse is free software; you can redistribute it and/or modify
8 ;; it under the terms of the GNU General Public License as published
9 ;; by the Free Software Foundation; either version 3, or (at your
10 ;; option) any later version.
12 ;; Emacs Muse is distributed in the hope that it will be useful, but
13 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
14 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 ;; General Public License for more details.
17 ;; You should have received a copy of the GNU General Public License
18 ;; along with Emacs Muse; see the file COPYING. If not, write to the
19 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 ;; Boston, MA 02110-1301, USA.
22 ;;; Commentary:
24 ;;; Contributors:
26 ;; Zhiqiang Ye (yezq AT mail DOT cbi DOT pku DOT edu DOT cn) suggested
27 ;; appending an 'encoding="..."' fragment to the first line of the
28 ;; sample publishing header so that when editing the resulting XHTML
29 ;; file, Emacs would use the proper encoding.
31 ;; Sun Jiyang (sunyijiang AT gmail DOT com) came up with the idea for
32 ;; the <src> tag and provided an implementation for emacs-wiki.
34 ;; Charles Wang (wcy123 AT gmail DOT com) provided an initial
35 ;; implementation of the <src> tag for Muse.
37 ;; Clinton Ebadi (clinton AT unknownlamer DOT org) provided further
38 ;; ideas for the implementation of the <src> tag.
40 ;;; Code:
42 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
44 ;; Muse HTML Publishing
46 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
48 (require 'muse-publish)
49 (require 'muse-regexps)
50 (require 'muse-xml-common)
52 (defgroup muse-html nil
53 "Options controlling the behavior of Muse HTML publishing."
54 :group 'muse-publish)
56 (defcustom muse-html-extension ".html"
57 "Default file extension for publishing HTML files."
58 :type 'string
59 :group 'muse-html)
61 (defcustom muse-xhtml-extension ".html"
62 "Default file extension for publishing XHTML files."
63 :type 'string
64 :group 'muse-html)
66 (defcustom muse-html-style-sheet
67 "<style type=\"text/css\">
68 body {
69 background: white; color: black;
70 margin-left: 3%; margin-right: 7%;
73 p { margin-top: 1% }
74 p.verse { margin-left: 3% }
76 .example { margin-left: 3% }
78 h2 {
79 margin-top: 25px;
80 margin-bottom: 0px;
82 h3 { margin-bottom: 0px; }
83 </style>"
84 "Store your stylesheet definitions here.
85 This is used in `muse-html-header'.
86 You can put raw CSS in here or a <link> tag to an external stylesheet.
87 This text may contain <lisp> markup tags.
89 An example of using <link> is as follows.
91 <link rel=\"stylesheet\" type=\"text/css\" charset=\"utf-8\" media=\"all\" href=\"/default.css\">"
92 :type 'string
93 :group 'muse-html)
95 (defcustom muse-xhtml-style-sheet
96 "<style type=\"text/css\">
97 body {
98 background: white; color: black;
99 margin-left: 3%; margin-right: 7%;
102 p { margin-top: 1% }
103 p.verse { margin-left: 3% }
105 .example { margin-left: 3% }
107 h2 {
108 margin-top: 25px;
109 margin-bottom: 0px;
111 h3 { margin-bottom: 0px; }
112 </style>"
113 "Store your stylesheet definitions here.
114 This is used in `muse-xhtml-header'.
115 You can put raw CSS in here or a <link> tag to an external stylesheet.
116 This text may contain <lisp> markup tags.
118 An example of using <link> is as follows.
120 <link rel=\"stylesheet\" type=\"text/css\" charset=\"utf-8\" media=\"all\" href=\"/default.css\" />"
121 :type 'string
122 :group 'muse-html)
124 (defcustom muse-html-header
125 "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\">
126 <html>
127 <head>
128 <title><lisp>
129 (concat (muse-publishing-directive \"title\")
130 (let ((author (muse-publishing-directive \"author\")))
131 (if (not (string= author (user-full-name)))
132 (concat \" (by \" author \")\"))))</lisp></title>
133 <meta name=\"generator\" content=\"muse.el\">
134 <meta http-equiv=\"<lisp>muse-html-meta-http-equiv</lisp>\"
135 content=\"<lisp>muse-html-meta-content-type</lisp>\">
136 <lisp>
137 (let ((maintainer (muse-style-element :maintainer)))
138 (when maintainer
139 (concat \"<link rev=\\\"made\\\" href=\\\"\" maintainer \"\\\">\")))
140 </lisp><lisp>
141 (muse-style-element :style-sheet muse-publishing-current-style)
142 </lisp>
143 </head>
144 <body>
145 <h1><lisp>
146 (concat (muse-publishing-directive \"title\")
147 (let ((author (muse-publishing-directive \"author\")))
148 (if (not (string= author (user-full-name)))
149 (concat \" (by \" author \")\"))))</lisp></h1>
150 <!-- Page published by Emacs Muse begins here -->\n"
151 "Header used for publishing HTML files. This may be text or a filename."
152 :type 'string
153 :group 'muse-html)
155 (defcustom muse-html-footer "
156 <!-- Page published by Emacs Muse ends here -->
157 </body>
158 </html>\n"
159 "Footer used for publishing HTML files. This may be text or a filename."
160 :type 'string
161 :group 'muse-html)
163 (defcustom muse-xhtml-header
164 "<?xml version=\"1.0\" encoding=\"<lisp>
165 (muse-html-encoding)</lisp>\"?>
166 <!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"
167 \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">
168 <html xmlns=\"http://www.w3.org/1999/xhtml\">
169 <head>
170 <title><lisp>
171 (concat (muse-publishing-directive \"title\")
172 (let ((author (muse-publishing-directive \"author\")))
173 (if (not (string= author (user-full-name)))
174 (concat \" (by \" author \")\"))))</lisp></title>
175 <meta name=\"generator\" content=\"muse.el\" />
176 <meta http-equiv=\"<lisp>muse-html-meta-http-equiv</lisp>\"
177 content=\"<lisp>muse-html-meta-content-type</lisp>\" />
178 <lisp>
179 (let ((maintainer (muse-style-element :maintainer)))
180 (when maintainer
181 (concat \"<link rev=\\\"made\\\" href=\\\"\" maintainer \"\\\" />\")))
182 </lisp><lisp>
183 (muse-style-element :style-sheet muse-publishing-current-style)
184 </lisp>
185 </head>
186 <body>
187 <h1><lisp>
188 (concat (muse-publishing-directive \"title\")
189 (let ((author (muse-publishing-directive \"author\")))
190 (if (not (string= author (user-full-name)))
191 (concat \" (by \" author \")\"))))</lisp></h1>
192 <!-- Page published by Emacs Muse begins here -->\n"
193 "Header used for publishing XHTML files. This may be text or a filename."
194 :type 'string
195 :group 'muse-html)
197 (defcustom muse-xhtml-footer "
198 <!-- Page published by Emacs Muse ends here -->
199 </body>
200 </html>\n"
201 "Footer used for publishing XHTML files. This may be text or a filename."
202 :type 'string
203 :group 'muse-html)
205 (defcustom muse-html-anchor-on-word nil
206 "When true, anchors surround the closest word. This allows you
207 to select them in a browser (i.e. for pasting), but has the
208 side-effect of marking up headers in multiple colors if your
209 header style is different from your link style."
210 :type 'boolean
211 :group 'muse-html)
213 (defcustom muse-html-table-attributes
214 " class=\"muse-table\" border=\"2\" cellpadding=\"5\""
215 "The attribute to be used with HTML <table> tags.
216 Note that Muse supports insertion of raw HTML tags, as long
217 as you wrap the region in <literal></literal>."
218 :type 'string
219 :group 'muse-html)
221 (defcustom muse-html-markup-regexps
222 `(;; Beginning of doc, end of doc, or plain paragraph separator
223 (10000 ,(concat "\\(\\(\n\\(?:[" muse-regexp-blank "]*\n\\)*"
224 "\\([" muse-regexp-blank "]*\n\\)\\)"
225 "\\|\\`\\s-*\\|\\s-*\\'\\)")
226 ;; this is somewhat repetitive because we only require the
227 ;; line just before the paragraph beginning to be not
228 ;; read-only
229 3 muse-html-markup-paragraph))
230 "List of markup rules for publishing a Muse page to HTML.
231 For more on the structure of this list, see `muse-publish-markup-regexps'."
232 :type '(repeat (choice
233 (list :tag "Markup rule"
234 integer
235 (choice regexp symbol)
236 integer
237 (choice string function symbol))
238 function))
239 :group 'muse-html)
241 (defcustom muse-html-markup-functions
242 '((anchor . muse-html-markup-anchor)
243 (table . muse-html-markup-table)
244 (footnote . muse-html-markup-footnote))
245 "An alist of style types to custom functions for that kind of text.
246 For more on the structure of this list, see
247 `muse-publish-markup-functions'."
248 :type '(alist :key-type symbol :value-type function)
249 :group 'muse-html)
251 (defcustom muse-html-markup-strings
252 '((image-with-desc . "<table class=\"image\" width=\"100%%\">
253 <tr><td align=\"center\"><img src=\"%1%.%2%\" alt=\"%3%\"></td></tr>
254 <tr><td align=\"center\" class=\"image-caption\">%3%</td></tr>
255 </table>")
256 (image . "<img src=\"%s.%s\" alt=\"\">")
257 (image-link . "<a class=\"image-link\" href=\"%s\">
258 <img src=\"%s.%s\"></a>")
259 (anchor-ref . "<a href=\"#%s\">%s</a>")
260 (url . "<a href=\"%s\">%s</a>")
261 (link . "<a href=\"%s\">%s</a>")
262 (link-and-anchor . "<a href=\"%s#%s\">%s</a>")
263 (email-addr . "<a href=\"mailto:%s\">%s</a>")
264 (anchor . "<a name=\"%1%\" id=\"%1%\">")
265 (emdash . "%s&mdash;%s")
266 (comment-begin . "<!-- ")
267 (comment-end . " -->")
268 (rule . "<hr>")
269 (fn-sep . "<hr>\n")
270 (no-break-space . "&nbsp;")
271 (enddots . "....")
272 (dots . "...")
273 (section . "<h2>")
274 (section-end . "</h2>")
275 (subsection . "<h3>")
276 (subsection-end . "</h3>")
277 (subsubsection . "<h4>")
278 (subsubsection-end . "</h4>")
279 (section-other . "<h5>")
280 (section-other-end . "</h5>")
281 (begin-underline . "<u>")
282 (end-underline . "</u>")
283 (begin-literal . "<code>")
284 (end-literal . "</code>")
285 (begin-cite . "<span class=\"citation\">")
286 (begin-cite-author . "<span class=\"citation-author\">")
287 (begin-cite-year . "<span class=\"citation-year\">")
288 (end-cite . "</span>")
289 (begin-emph . "<em>")
290 (end-emph . "</em>")
291 (begin-more-emph . "<strong>")
292 (end-more-emph . "</strong>")
293 (begin-most-emph . "<strong><em>")
294 (end-most-emph . "</em></strong>")
295 (begin-verse . "<p class=\"verse\">\n")
296 (verse-space . "&nbsp;&nbsp;")
297 (end-verse-line . "<br>")
298 (end-last-stanza-line . "<br>")
299 (empty-verse-line . "<br>")
300 (end-verse . "</p>")
301 (begin-example . "<pre class=\"example\">")
302 (end-example . "</pre>")
303 (begin-center . "<center>\n<p>")
304 (end-center . "</p>\n</center>")
305 (begin-quote . "<blockquote>\n")
306 (end-quote . "\n</blockquote>")
307 (begin-quote-item . "<p class=\"quoted\">")
308 (end-quote-item . "</p>")
309 (begin-uli . "<ul>\n")
310 (end-uli . "\n</ul>")
311 (begin-uli-item . "<li>")
312 (end-uli-item . "</li>")
313 (begin-oli . "<ol>\n")
314 (end-oli . "\n</ol>")
315 (begin-oli-item . "<li>")
316 (end-oli-item . "</li>")
317 (begin-dl . "<dl>\n")
318 (end-dl . "\n</dl>")
319 (begin-ddt . "<dt><strong>")
320 (end-ddt . "</strong></dt>")
321 (begin-dde . "<dd>")
322 (end-dde . "</dd>")
323 (begin-table . "<table%s>\n")
324 (end-table . "</table>")
325 (begin-table-row . " <tr>\n")
326 (end-table-row . " </tr>\n")
327 (begin-table-entry . " <%s>")
328 (end-table-entry . "</%s>\n"))
329 "Strings used for marking up text as HTML.
330 These cover the most basic kinds of markup, the handling of which
331 differs little between the various styles."
332 :type '(alist :key-type symbol :value-type string)
333 :group 'muse-html)
335 (defcustom muse-xhtml-markup-strings
336 '((image-with-desc . "<table class=\"image\" width=\"100%%\">
337 <tr><td align=\"center\"><img src=\"%1%.%2%\" alt=\"%3%\" /></td></tr>
338 <tr><td align=\"center\" class=\"image-caption\">%3%</td></tr>
339 </table>")
340 (image . "<img src=\"%s.%s\" alt=\"\" />")
341 (image-link . "<a class=\"image-link\" href=\"%s\">
342 <img src=\"%s.%s\" alt=\"\" /></a>")
343 (rule . "<hr />")
344 (fn-sep . "<hr />\n")
345 (begin-underline . "<span style=\"text-decoration: underline;\">")
346 (end-underline . "</span>")
347 (begin-center . "<p style=\"text-align: center;\">\n")
348 (end-center . "\n</p>")
349 (end-verse-line . "<br />")
350 (end-last-stanza-line . "<br />")
351 (empty-verse-line . "<br />"))
352 "Strings used for marking up text as XHTML.
353 These cover the most basic kinds of markup, the handling of which
354 differs little between the various styles.
356 If a markup rule is not found here, `muse-html-markup-strings' is
357 searched."
358 :type '(alist :key-type symbol :value-type string)
359 :group 'muse-html)
361 (defcustom muse-xhtml1.1-markup-strings
362 '((anchor . "<a id=\"%s\">"))
363 "Strings used for marking up text as XHTML 1.1.
364 These cover the most basic kinds of markup, the handling of which
365 differs little between the various styles.
367 If a markup rule is not found here, `muse-xhtml-markup-strings'
368 and `muse-html-markup-strings' are searched."
369 :type '(alist :key-type symbol :value-type string)
370 :group 'muse-html)
372 (defcustom muse-html-markup-tags
373 '(("class" t t t muse-html-class-tag)
374 ("src" t t nil muse-html-src-tag))
375 "A list of tag specifications, for specially marking up HTML."
376 :type '(repeat (list (string :tag "Markup tag")
377 (boolean :tag "Expect closing tag" :value t)
378 (boolean :tag "Parse attributes" :value nil)
379 (boolean :tag "Nestable" :value nil)
380 function))
381 :group 'muse-html)
383 (defcustom muse-html-meta-http-equiv "Content-Type"
384 "The http-equiv attribute used for the HTML <meta> tag."
385 :type 'string
386 :group 'muse-html)
388 (defcustom muse-html-meta-content-type "text/html"
389 "The content type used for the HTML <meta> tag.
390 If you are striving for XHTML 1.1 compliance, you may want to
391 change this to \"application/xhtml+xml\"."
392 :type 'string
393 :group 'muse-html)
395 (defcustom muse-html-meta-content-encoding (if (featurep 'mule)
396 'detect
397 "iso-8859-1")
398 "The charset to append to the HTML <meta> tag.
399 If set to the symbol 'detect, use `muse-html-encoding-map' to try
400 and determine the HTML charset from emacs's coding. If set to a
401 string, this string will be used to force a particular charset"
402 :type '(choice string symbol)
403 :group 'muse-html)
405 (defcustom muse-html-encoding-default 'iso-8859-1
406 "The default Emacs buffer encoding to use in published files.
407 This will be used if no special characters are found."
408 :type 'symbol
409 :group 'muse-html)
411 (defcustom muse-html-charset-default "iso-8859-1"
412 "The default HTML meta charset to use if no translation is found in
413 `muse-html-encoding-map'."
414 :type 'string
415 :group 'muse-html)
417 (defun muse-html-insert-anchor (anchor)
418 "Insert an anchor, either around the word at point, or within a tag."
419 (skip-chars-forward (concat muse-regexp-blank "\n"))
420 (if (looking-at (concat "<\\([^" muse-regexp-blank "/>\n]+\\)>"))
421 (let ((tag (match-string 1)))
422 (goto-char (match-end 0))
423 (muse-insert-markup (muse-markup-text 'anchor anchor))
424 (when muse-html-anchor-on-word
425 (or (and (search-forward (format "</%s>" tag)
426 (muse-line-end-position) t)
427 (goto-char (match-beginning 0)))
428 (forward-word 1)))
429 (muse-insert-markup "</a>"))
430 (muse-insert-markup (muse-markup-text 'anchor anchor))
431 (when muse-html-anchor-on-word
432 (forward-word 1))
433 (muse-insert-markup "</a>\n")))
435 (defun muse-html-markup-anchor ()
436 (unless (get-text-property (match-end 1) 'muse-link)
437 (save-match-data
438 (muse-html-insert-anchor (match-string 2)))
439 (match-string 1)))
441 (defun muse-html-markup-paragraph ()
442 (let ((end (copy-marker (match-end 0) t)))
443 (goto-char (match-beginning 0))
444 (when (save-excursion
445 (save-match-data
446 (and (re-search-backward "<\\(/?\\)p[ >]" nil t)
447 (not (string-equal (match-string 1) "/")))))
448 (when (get-text-property (1- (point)) 'end-list)
449 (goto-char (previous-single-property-change (1- (point)) 'end-list)))
450 (muse-insert-markup "</p>"))
451 (goto-char end))
452 (cond
453 ((eobp)
454 (unless (bolp)
455 (insert "\n")))
456 ((eq (char-after) ?\<)
457 (cond
458 ((looking-at "<\\(em\\|strong\\|code\\|span\\)[ >]")
459 (muse-insert-markup "<p>"))
460 ((looking-at "<a ")
461 (if (looking-at "<a[^>\n]+><img")
462 (muse-insert-markup "<p class=\"image-link\">")
463 (muse-insert-markup "<p>")))
464 ((looking-at "<img[ >]")
465 (muse-insert-markup "<p class=\"image\">"))
467 (forward-char 1)
468 nil)))
469 ((muse-looking-back "\\(</h[1-4]>\\|<hr>\\)\n\n")
470 (muse-insert-markup "<p class=\"first\">"))
472 (muse-insert-markup "<p>"))))
474 (defun muse-html-markup-footnote ()
475 (cond
476 ((get-text-property (match-beginning 0) 'muse-link)
477 nil)
478 ((= (muse-line-beginning-position) (match-beginning 0))
479 (prog1
480 (let ((text (match-string 1)))
481 (muse-insert-markup
482 (concat "<p class=\"footnote\">"
483 "<a class=\"footnum\" name=\"fn." text
484 "\" href=\"#fnr." text "\">"
485 text ".</a>")))
486 (save-excursion
487 (save-match-data
488 (let* ((beg (goto-char (match-end 0)))
489 (end (and (search-forward "\n\n" nil t)
490 (prog1
491 (copy-marker (match-beginning 0))
492 (goto-char beg)))))
493 (while (re-search-forward (concat "^["
494 muse-regexp-blank
495 "]+\\([^\n]\\)")
496 end t)
497 (replace-match "\\1" t)))))
498 (replace-match "")))
499 (t (let ((text (match-string 1)))
500 (muse-insert-markup
501 (concat "<sup><a class=\"footref\" name=\"fnr." text
502 "\" href=\"#fn." text "\">"
503 text "</a></sup>")))
504 (replace-match ""))))
506 (defun muse-html-markup-table ()
507 (muse-xml-markup-table muse-html-table-attributes))
509 ;; Handling of tags for HTML
511 (defun muse-html-insert-contents (depth)
512 "Scan the current document and generate a table of contents at point.
513 DEPTH indicates how many levels of headings to include. The default is 2."
514 (let ((max-depth (or depth 2))
515 (index 1)
516 base contents l)
517 (save-excursion
518 (goto-char (point-min))
519 (search-forward "Page published by Emacs Muse begins here" nil t)
520 (catch 'done
521 (while (re-search-forward "<h\\([0-9]+\\)>\\(.+?\\)</h\\1>$" nil t)
522 (unless (and (get-text-property (point) 'read-only)
523 (not (get-text-property (match-beginning 0)
524 'muse-contents)))
525 (remove-text-properties (match-beginning 0) (match-end 0)
526 '(muse-contents nil))
527 (setq l (1- (string-to-number (match-string 1))))
528 (if (null base)
529 (setq base l)
530 (if (< l base)
531 (throw 'done t)))
532 (when (<= l max-depth)
533 (setq contents (cons (cons l (muse-match-string-no-properties 2))
534 contents))
535 (goto-char (match-beginning 2))
536 (muse-html-insert-anchor (concat "sec" (int-to-string index)))
537 (setq index (1+ index)))))))
538 (setq index 1 contents (nreverse contents))
539 (let ((depth 1) (sub-open 0) (p (point)))
540 (muse-insert-markup "<div class=\"contents\">\n<dl>\n")
541 (while contents
542 (muse-insert-markup "<dt>\n"
543 "<a href=\"#sec" (int-to-string index) "\">"
544 (muse-publish-strip-tags (cdar contents))
545 "</a>\n"
546 "</dt>\n")
547 (setq index (1+ index)
548 depth (caar contents)
549 contents (cdr contents))
550 (when contents
551 (cond
552 ((< (caar contents) depth)
553 (let ((idx (caar contents)))
554 (while (< idx depth)
555 (muse-insert-markup "</dl>\n</dd>\n")
556 (setq sub-open (1- sub-open)
557 idx (1+ idx)))))
558 ((> (caar contents) depth) ; can't jump more than one ahead
559 (muse-insert-markup "<dd>\n<dl>\n")
560 (setq sub-open (1+ sub-open))))))
561 (while (> sub-open 0)
562 (muse-insert-markup "</dl>\n</dd>\n")
563 (setq sub-open (1- sub-open)))
564 (muse-insert-markup "</dl>\n</div>\n")
565 (muse-publish-mark-read-only p (point)))))
567 (defun muse-html-denote-headings ()
568 "Place a text property on any headings in the current buffer.
569 This allows the headings to be picked up later on if publishing a
570 table of contents."
571 (save-excursion
572 (goto-char (point-min))
573 (search-forward "Page published by Emacs Muse begins here" nil t)
574 (while (re-search-forward "<h\\([0-9]+\\)>\\(.+?\\)</h\\1>$" nil t)
575 (unless (get-text-property (point) 'read-only)
576 (add-text-properties (match-beginning 0) (match-end 0)
577 '(muse-contents t))))))
579 (defun muse-html-class-tag (beg end attrs)
580 (goto-char beg)
581 (muse-insert-markup "<span class=\"" (cdr (assoc "name" attrs)) "\">")
582 (goto-char end)
583 (muse-insert-markup "</span>"))
585 (defun muse-html-src-tag (beg end attrs)
586 "Publish the region using htmlize.
587 The language to use may be specified by the \"lang\" attribute.
589 Muse will look for a function named LANG-mode, where LANG is the
590 value of the \"lang\" attribute.
592 This tag requires htmlize 1.34 or later in order to work."
593 (if (condition-case nil
594 (progn
595 (require 'htmlize)
596 (if (fboundp 'htmlize-region-for-paste)
598 (muse-display-warning
599 (concat "The `htmlize-region-for-paste' function was not"
600 " found.\nThis is available in htmlize.el 1.34"
601 " or later."))
603 (error nil t))
604 ;; if htmlize.el was not found, treat this like an example tag
605 (muse-publish-example-tag beg end)
606 (muse-publish-ensure-block beg end)
607 (let* ((mode (and (assoc "lang" attrs)
608 (intern (concat (cdr (assoc "lang" attrs))
609 "-mode"))))
610 (text (delete-and-extract-region beg end))
611 (htmltext
612 (with-temp-buffer
613 (insert text)
614 (if (functionp mode)
615 (funcall mode)
616 (fundamental-mode))
617 (font-lock-fontify-buffer)
618 ;; silence the byte-compiler
619 (when (fboundp 'htmlize-region-for-paste)
620 ;; transform the region to HTML
621 (htmlize-region-for-paste (point-min) (point-max))))))
622 (save-restriction
623 (narrow-to-region (point) (point))
624 (insert htmltext)
625 (goto-char (point-min))
626 (re-search-forward "<pre\\([^>]*\\)>\n?" nil t)
627 (replace-match "<pre class=\"src\">")
628 (goto-char (point-max))
629 (muse-publish-mark-read-only (point-min) (point-max))))))
631 ;; Register the Muse HTML Publisher
633 (defun muse-html-browse-file (file)
634 (browse-url (concat "file:" file)))
636 (defun muse-html-encoding ()
637 (if (stringp muse-html-meta-content-encoding)
638 muse-html-meta-content-encoding
639 (muse-xml-transform-content-type
640 (or (and (boundp 'buffer-file-coding-system)
641 buffer-file-coding-system)
642 muse-html-encoding-default)
643 muse-html-charset-default)))
645 (defun muse-html-prepare-buffer ()
646 (make-local-variable 'muse-html-meta-http-equiv)
647 (set (make-local-variable 'muse-html-meta-content-type)
648 (if (save-match-data
649 (string-match "charset=" muse-html-meta-content-type))
650 muse-html-meta-content-type
651 (concat muse-html-meta-content-type "; charset="
652 (muse-html-encoding)))))
654 (defun muse-html-munge-buffer ()
655 (if muse-publish-generate-contents
656 (progn
657 (goto-char (car muse-publish-generate-contents))
658 (muse-html-insert-contents (cdr muse-publish-generate-contents))
659 (setq muse-publish-generate-contents nil))
660 (muse-html-denote-headings)))
662 (defun muse-html-finalize-buffer ()
663 (when (and (boundp 'buffer-file-coding-system)
664 (memq buffer-file-coding-system '(no-conversion undecided-unix)))
665 ;; make it agree with the default charset
666 (setq buffer-file-coding-system muse-html-encoding-default)))
668 ;;; Register the Muse HTML and XHTML Publishers
670 (muse-define-style "html"
671 :suffix 'muse-html-extension
672 :regexps 'muse-html-markup-regexps
673 :functions 'muse-html-markup-functions
674 :strings 'muse-html-markup-strings
675 :tags 'muse-html-markup-tags
676 :specials 'muse-xml-decide-specials
677 :before 'muse-html-prepare-buffer
678 :before-end 'muse-html-munge-buffer
679 :after 'muse-html-finalize-buffer
680 :header 'muse-html-header
681 :footer 'muse-html-footer
682 :style-sheet 'muse-html-style-sheet
683 :browser 'muse-html-browse-file)
685 (muse-derive-style "xhtml" "html"
686 :suffix 'muse-xhtml-extension
687 :strings 'muse-xhtml-markup-strings
688 :header 'muse-xhtml-header
689 :footer 'muse-xhtml-footer
690 :style-sheet 'muse-xhtml-style-sheet)
692 ;; xhtml1.0 is an alias for xhtml
693 (muse-derive-style "xhtml1.0" "xhtml")
695 ;; xhtml1.1 has some quirks that need attention from us
696 (muse-derive-style "xhtml1.1" "xhtml"
697 :strings 'muse-xhtml1.1-markup-strings)
699 (provide 'muse-html)
701 ;;; muse-html.el ends here