Introduce the muse-no-paragraph property.
[muse-el.git] / lisp / muse-ikiwiki.el
blob9dc627488b33b185b92e4c7d40d031a2579879a5
1 ;;; muse-ikiwiki.el --- integrate with Ikiwiki
3 ;; Copyright (C) 2008 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 ;;; Code:
28 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
30 ;; Muse Ikiwiki Integration
32 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
34 (require 'muse)
35 (require 'muse-html)
36 (require 'muse-publish)
38 (eval-when-compile
39 (require 'muse-colors))
41 (defgroup muse-ikiwiki nil
42 "Options controlling the behavior of Muse integration with Ikiwiki."
43 :group 'muse-publish)
45 (defcustom muse-ikiwiki-header ""
46 "Header used for publishing Ikiwiki output files.
47 This may be text or a filename."
48 :type 'string
49 :group 'muse-ikiwiki)
51 (defcustom muse-ikiwiki-footer ""
52 "Footer used for publishing Ikiwiki output files.
53 This may be text or a filename."
54 :type 'string
55 :group 'muse-ikiwiki)
57 ;;; Publishing
59 (defun muse-ikiwiki-publish-file (file name &optional style)
60 "Publish a single file for Ikiwiki.
61 The name of the style is given by STYLE. It defaults to \"ikiwiki\".
62 The name of the real file is NAME, and the name of the temporary
63 file containing the content is FILE."
64 (if (not (stringp file))
65 (message "Error: No file given to publish")
66 (unless style
67 (setq style "ikiwiki"))
68 (let ((muse-batch-publishing-p t)
69 (title (muse-page-name name))
70 (output-path file)
71 (target file)
72 (muse-publishing-current-file file)
73 (muse-publishing-current-output-path file)
74 (font-lock-verbose nil)
75 muse-current-output-style)
76 ;; don't activate VC when publishing files
77 (setq vc-handled-backends nil)
78 (setq muse-current-output-style (list :base style :path file))
79 (setq auto-mode-alist
80 (delete (cons (concat "\\." muse-file-extension "\\'")
81 'muse-mode-choose-mode)
82 auto-mode-alist))
83 (muse-with-temp-buffer
84 (muse-insert-file-contents file)
85 (run-hooks 'muse-before-publish-hook)
86 (let ((muse-inhibit-before-publish-hook t))
87 (muse-publish-markup-buffer title style))
88 (when (muse-write-file output-path t)
89 (muse-style-run-hooks :final style file output-path target))))))
91 ;;; Colors
93 (defface muse-ikiwiki-directive
94 '((((class color) (background light))
95 (:foreground "dark green"))
96 (((class color) (background dark))
97 (:foreground "green")))
98 "Face for Ikiwiki directives."
99 :group 'muse-ikiwiki)
101 (defun muse-colors-ikiwiki-directive ()
102 "Color ikiwiki directives."
103 (let ((start (match-beginning 0)))
104 (unless (or (eq (get-text-property start 'invisible) 'muse)
105 (get-text-property start 'muse-comment)
106 (get-text-property start 'muse-directive))
107 ;; beginning of line or space or symbol
108 (save-excursion
109 (and
110 (catch 'valid
111 (while t
112 (skip-chars-forward "^\"]" muse-colors-region-end)
113 (cond ((eq (point) (point-max))
114 (throw 'valid nil))
115 ((> (point) muse-colors-region-end)
116 (throw 'valid nil))
117 ((eq (char-after) ?\")
118 (if (and (< (1+ (point)) muse-colors-region-end)
119 (eq (char-after (1+ (point))) ?\"))
120 (if (and (< (+ 2 (point)) muse-colors-region-end)
121 (eq (char-after (+ 2 (point))) ?\"))
122 ;; triple-quote
123 (progn
124 (forward-char 3)
125 (or (and (looking-at "\"\"\"")
126 (goto-char (match-end 0)))
127 (re-search-forward
128 "\"\"\"" muse-colors-region-end t)
129 (throw 'valid nil)))
130 ;; empty quotes (""), which are invalid
131 (throw 'valid nil))
132 ;; quote with content
133 (forward-char 1)
134 (skip-chars-forward "^\"" muse-colors-region-end)
135 (when (eq (char-after) ?\")
136 (forward-char 1))))
137 ((eq (char-after) ?\])
138 (forward-char 1)
139 (when (and (< (point) muse-colors-region-end)
140 (eq (char-after (point)) ?\]))
141 (forward-char 1)
142 (throw 'valid t)))
143 (t (throw 'valid nil)))))
144 ;; found a valid directive
145 (let ((end (point)))
146 ;; remove flyspell overlays
147 (when (fboundp 'flyspell-unhighlight-at)
148 (let ((cur start))
149 (while (> end cur)
150 (flyspell-unhighlight-at cur)
151 (setq cur (1+ cur)))))
152 (add-text-properties start end
153 '(face muse-ikiwiki-directive
154 muse-directive t muse-no-flyspell t))
155 (when (progn
156 (goto-char start)
157 (skip-chars-forward "^\n" end)
158 (and (eq (char-after) ?\n)
159 (not (= (point) end))))
160 (add-text-properties start end
161 '(font-lock-multiline t)))))))))
163 (defun muse-ikiwiki-insinuate-colors ()
164 (add-to-list 'muse-colors-markup
165 '("\\[\\[!" ?\[ muse-colors-ikiwiki-directive)
166 nil))
168 (eval-after-load "muse-colors" '(muse-ikiwiki-insinuate-colors))
170 ;; Styles
171 (muse-derive-style "ikiwiki" "xhtml"
172 :header 'muse-ikiwiki-header
173 :footer 'muse-ikiwiki-footer)
175 (provide 'muse-ikiwiki)
177 ;;; muse-ikiwiki.el ends here