Adjust copyright headers for 2009.
[muse-el.git] / lisp / muse-ikiwiki.el
blob09b7cd51d40ee779e2d2b914f3991b2caafc4f8d
1 ;;; muse-ikiwiki.el --- integrate with Ikiwiki
3 ;; Copyright (C) 2008, 2009 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 (defcustom muse-ikiwiki-markup-regexps
58 `(;; Ikiwiki directives
59 (1350 ,(concat "\\(\\\\?\\)\\[\\[!""\\(?:-\\|\\w\\)+"
60 "\\([" muse-regexp-blank "\n]+"
61 "\\(?:\\(?:\\(?:-\\|\\w\\)+=\\)?"
62 "\\(?:\"\"\".*?\"\"\"\\|\"[^\"]+\""
63 "\\|[^]" muse-regexp-blank "\n]+\\)"
64 "[" muse-regexp-blank "\n]*\\)*\\)?\\]\\]")
65 0 muse-ikiwiki-markup-directive))
66 "List of markup rules for publishing Ikiwiki markup on Muse pages.
67 For more on the structure of this list, see `muse-publish-markup-regexps'."
68 :type '(repeat (choice
69 (list :tag "Markup rule"
70 integer
71 (choice regexp symbol)
72 integer
73 (choice string function symbol))
74 function))
75 :group 'muse-ikiwiki)
77 ;;; Publishing
79 (defun muse-ikiwiki-markup-directive ()
80 "Handle publishing of an Ikiwiki directive."
81 (unless (get-text-property (match-beginning 0) 'read-only)
82 (add-text-properties (match-beginning 0) (match-end 0)
83 '(muse-no-paragraph t))
84 (muse-publish-mark-read-only (match-beginning 0) (match-end 0))))
86 (defun muse-ikiwiki-publish-file (file name &optional style)
87 "Publish a single file for Ikiwiki.
88 The name of the style is given by STYLE. It defaults to \"ikiwiki\".
89 The name of the real file is NAME, and the name of the temporary
90 file containing the content is FILE."
91 (if (not (stringp file))
92 (message "Error: No file given to publish")
93 (unless style
94 (setq style "ikiwiki"))
95 (let ((muse-batch-publishing-p t)
96 (title (muse-page-name name))
97 (output-path file)
98 (target file)
99 (muse-publishing-current-file file)
100 (muse-publishing-current-output-path file)
101 (font-lock-verbose nil)
102 muse-current-output-style)
103 ;; don't activate VC when publishing files
104 (setq vc-handled-backends nil)
105 (setq muse-current-output-style (list :base style :path file))
106 (setq auto-mode-alist
107 (delete (cons (concat "\\." muse-file-extension "\\'")
108 'muse-mode-choose-mode)
109 auto-mode-alist))
110 (muse-with-temp-buffer
111 (muse-insert-file-contents file)
112 (run-hooks 'muse-before-publish-hook)
113 (let ((muse-inhibit-before-publish-hook t))
114 (muse-publish-markup-buffer title style))
115 (when (muse-write-file output-path t)
116 (muse-style-run-hooks :final style file output-path target))))))
118 ;;; Colors
120 (defface muse-ikiwiki-directive
121 '((((class color) (background light))
122 (:foreground "dark green"))
123 (((class color) (background dark))
124 (:foreground "green")))
125 "Face for Ikiwiki directives."
126 :group 'muse-ikiwiki)
128 (defun muse-colors-ikiwiki-directive ()
129 "Color ikiwiki directives."
130 (let ((start (match-beginning 0)))
131 (unless (or (eq (get-text-property start 'invisible) 'muse)
132 (get-text-property start 'muse-comment)
133 (get-text-property start 'muse-directive))
134 ;; beginning of line or space or symbol
135 (save-excursion
136 (and
137 (catch 'valid
138 (while t
139 (skip-chars-forward "^\"]" muse-colors-region-end)
140 (cond ((eq (point) (point-max))
141 (throw 'valid nil))
142 ((> (point) muse-colors-region-end)
143 (throw 'valid nil))
144 ((eq (char-after) ?\")
145 (if (and (< (1+ (point)) muse-colors-region-end)
146 (eq (char-after (1+ (point))) ?\"))
147 (if (and (< (+ 2 (point)) muse-colors-region-end)
148 (eq (char-after (+ 2 (point))) ?\"))
149 ;; triple-quote
150 (progn
151 (forward-char 3)
152 (or (and (looking-at "\"\"\"")
153 (goto-char (match-end 0)))
154 (re-search-forward
155 "\"\"\"" muse-colors-region-end t)
156 (throw 'valid nil)))
157 ;; empty quotes (""), which are invalid
158 (throw 'valid nil))
159 ;; quote with content
160 (forward-char 1)
161 (skip-chars-forward "^\"" muse-colors-region-end)
162 (when (eq (char-after) ?\")
163 (forward-char 1))))
164 ((eq (char-after) ?\])
165 (forward-char 1)
166 (when (and (< (point) muse-colors-region-end)
167 (eq (char-after (point)) ?\]))
168 (forward-char 1)
169 (throw 'valid t)))
170 (t (throw 'valid nil)))))
171 ;; found a valid directive
172 (let ((end (point)))
173 ;; remove flyspell overlays
174 (when (fboundp 'flyspell-unhighlight-at)
175 (let ((cur start))
176 (while (> end cur)
177 (flyspell-unhighlight-at cur)
178 (setq cur (1+ cur)))))
179 (add-text-properties start end
180 '(face muse-ikiwiki-directive
181 muse-directive t muse-no-flyspell t))
182 (when (progn
183 (goto-char start)
184 (skip-chars-forward "^\n" end)
185 (and (eq (char-after) ?\n)
186 (not (= (point) end))))
187 (add-text-properties start end
188 '(font-lock-multiline t)))))))))
190 (defun muse-ikiwiki-insinuate-colors ()
191 (add-to-list 'muse-colors-markup
192 '("\\[\\[!" ?\[ muse-colors-ikiwiki-directive)
193 nil))
195 (eval-after-load "muse-colors" '(muse-ikiwiki-insinuate-colors))
197 ;; Styles
198 (muse-derive-style "ikiwiki" "xhtml"
199 :header 'muse-ikiwiki-header
200 :footer 'muse-ikiwiki-footer
201 :regexps 'muse-ikiwiki-markup-regexps)
203 (provide 'muse-ikiwiki)
205 ;;; muse-ikiwiki.el ends here