1 ;;; planner-publish.el --- planner-specific publishing
3 ;; Copyright (C) 2005, 2006 Peter K. Lee
4 ;; Parts copyright (C) 2005 Chris McMahan
5 ;; Parts copyright (C) 2005, 2006 Free Software Foundation, Inc.
6 ;; Parts copyright (C) 2005 Dale P. Smith
8 ;; Author: Peter K. Lee <saint@ c o r e n o v a .com>
9 ;; Keywords: planner publish
10 ;; Timestamp: 20 Jul 2005 10:05:29
11 ;; X-URL: http://www.corenova.com/...
13 ;; This file is part of Planner. It is not part of GNU Emacs.
15 ;; Planner is free software; you can redistribute it and/or modify it
16 ;; under the terms of the GNU General Public License as published by
17 ;; the Free Software Foundation; either version 2, or (at your option)
20 ;; Planner is distributed in the hope that it will be useful, but
21 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
22 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
23 ;; General Public License for more details.
25 ;; You should have received a copy of the GNU General Public License
26 ;; along with Planner; see the file COPYING. If not, write to the
27 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
28 ;; Boston, MA 02110-1301, USA.
32 ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
36 ;; Muse Styles for Planner: planner-xml, planner-html, planner-xhtml, etc.
38 ;; Handles publishing of planner files. Works with Muse to generate
43 ;; 2005-07-15 (0.1) : creation date
44 ;; 2005-07-20 (0.2) : first public release
45 ;; 2005-07-21 (0.3) : added planner-html-style-sheet customize option
46 ;; 2005-08-09 : added to Planner, see ChangeLog for further changes
50 ;; add support for various PLANNER specific sections such as Diary,
51 ;; Accomplishments, Timeclock, etc.
55 ;; Chris McMahan (cmcmahan AT one.net) helped notes to publish correctly.
57 ;; Jim Ottaway fixed several bugs.
59 ;; David Smith fixed a few bugs.
61 ;; Dale Smith implemented a new version of the "notes" tag and
62 ;; provided several patches.
64 ;; Andrew J. Korty enabled multiple links with the "categories"
70 (require 'muse-publish
)
71 (require 'muse-html
) ;;; allow derive style from "html" and "xhtml"
72 (require 'muse-xml
) ;;; allow derive style from "xml"
74 (defgroup planner-publish nil
75 "Options controlling the behavior of PLANNER publishing.
76 See `planner-publish' for more information."
79 (defcustom planner-publish-markup-regexps
80 '((1275 "^#\\([A-C]\\)\\([0-9]*\\)\\s-*\\([_oXDCP]\\)\\s-*\\(.+\\)" 0 task
)
81 (1280 "^\\.#[0-9]+\\s-*" 0 note
)
82 (3200 planner-date-regexp
0 link
))
83 "List of markup rules for publishing PLANNER.
84 For more on the structure of this list, see `muse-publish-markup-regexps'."
85 :type
'(repeat (choice
86 (list :tag
"Markup rule"
88 (choice regexp symbol
)
90 (choice string function symbol
))
94 (defcustom planner-publish-markup-functions
95 '((task . planner-publish-markup-task
)
96 (note . planner-publish-markup-note
))
97 "An alist of style types to custom functions for that kind of text.
98 For more on the structure of this list, see
99 `muse-publish-markup-functions'."
100 :type
'(alist :key-type symbol
:value-type function
)
101 :group
'planner-publish
)
103 (defcustom planner-publish-markup-tags
104 '(("nested-section" t nil planner-publish-nested-section-tag
)
105 ("title" t nil planner-publish-title-tag
)
106 ("content" t nil planner-publish-content-tag
)
107 ("tasks-section" t nil planner-publish-tasks-section-tag
)
108 ("notes-section" t nil planner-publish-notes-section-tag
)
109 ("notes" nil nil planner-publish-notes-tag
)
110 ("past-notes" nil t planner-publish-past-notes-tag
)
111 ("task" t t planner-publish-task-tag
)
112 ("note" t t planner-publish-note-tag
))
113 "A list of tag specifications, for specially marking up PLANNER.
114 See `muse-publish-markup-tags' for more information."
115 :type
'(repeat (list (string :tag
"Markup tag")
116 (boolean :tag
"Expect closing tag" :value t
)
117 (boolean :tag
"Parse attributes" :value nil
)
119 :group
'planner-publish
)
121 ;;;_ + XML specific customizations
123 (defcustom planner-xml-markup-strings
124 '((planner-begin-nested-section .
"<section>")
125 (planner-end-nested-section .
"</section>")
126 (planner-begin-title .
"<title>")
127 (planner-end-title .
"</title>")
128 (planner-begin-content .
"")
129 (planner-end-content .
"")
130 (planner-begin-body .
"")
131 (planner-end-body .
"")
132 (planner-begin-task-section .
"<tasks>")
133 (planner-end-task-section .
"</tasks>")
134 (planner-begin-task-body .
"")
135 (planner-end-task-body .
"")
136 (planner-begin-note-section .
"<notes>")
137 (planner-end-note-section .
"</notes>")
138 (planner-begin-task .
"<task status=\"%s\" priority=\"%s\">")
139 (planner-end-task .
"</task>")
140 (planner-begin-note .
"<note number=\"%s\">")
141 (planner-end-note .
"</note>")
142 (planner-begin-note-details .
"<details><timestamp>%s</timestamp>")
143 (planner-end-note-details .
"</details>")
144 (planner-begin-note-link .
"<references>")
145 (planner-end-note-link .
"</references>")
146 (planner-begin-note-categories .
"<categories>")
147 (planner-end-note-categories .
"</categories>"))
148 "Strings used for marking up text as XML.
149 These cover the most basic kinds of markup, the handling of which
150 differs little between the various styles.
152 If a markup rule is not found here, `muse-xml-markup-strings' is
154 :type
'(alist :key-type symbol
:value-type string
)
155 :group
'planner-publish
)
157 (defcustom planner-xml-header
158 "<?xml version=\"1.0\" encoding=\"<lisp>(muse-xml-encoding)</lisp>\"?>
161 <title><lisp>(muse-publishing-directive \"title\")</lisp></title>
162 <author><lisp>(muse-publishing-directive \"author\")</lisp></author>
163 <maintainer><lisp>(muse-style-element :maintainer)</lisp></maintainer>
164 <pubdate><lisp>(muse-publishing-directive \"date\")</lisp></pubdate>
166 <!-- Page published by Emacs Muse begins here -->\n"
167 "Header used for publishing PLANNER XML files.
168 This may be text or a filename."
170 :group
'planner-publish
)
172 (defcustom planner-xml-footer
"
173 <!-- Page published by Emacs Muse ends here -->
175 "Footer used for publishing PLANNER XML files.
176 This may be text or a filename."
178 :group
'planner-publish
)
180 ;;;_ + HTML specific customizations
182 (defcustom planner-html-markup-strings
183 '((planner-begin-nested-section .
"<div class=\"section\">")
184 (planner-end-nested-section .
"</div>")
185 (planner-begin-title .
"<div class=\"title\">")
186 (planner-end-title .
"</div>")
187 (planner-begin-content .
"<div class=\"content\">")
188 (planner-end-content .
"</div>")
189 (planner-begin-body .
"<div class=\"body\">")
190 (planner-end-body .
"</div>")
191 (planner-begin-task-section .
"<div id=\"tasks\" class=\"section\">")
192 (planner-end-task-section .
"</div>")
193 (planner-begin-task-body .
"<ul class=\"body\">")
194 (planner-end-task-body .
"</ul>")
195 (planner-begin-note-section .
"<div id=\"notes\" class=\"section\">")
196 (planner-end-note-section .
"</div>")
197 (planner-begin-task .
"<li class=\"task\"><span class=\"%s\"><span class=\"%s\">%s</span>")
198 (planner-end-task .
"</span></li>")
199 (planner-begin-note .
"<div class=\"note\"><a name=\"%s\"></a><span class=\"anchor\">%s</span>")
200 (planner-end-note .
"</div>")
201 (planner-begin-note-details .
"<div class=\"details\"><span class=\"timestamp\">%s</span>")
202 (planner-end-note-details .
"</div>")
203 (planner-begin-note-link .
" <span class=\"link\">")
204 (planner-end-note-link .
"</span>")
205 (planner-begin-note-categories .
" <span class=\"categories\">")
206 (planner-end-note-categories .
"</span>"))
207 "Strings used for marking up text as HTML.
208 These cover the most basic kinds of markup, the handling of which
209 differs little between the various styles.
211 If a markup rule is not found here, `muse-html-markup-strings' is
213 :type
'(alist :key-type symbol
:value-type string
)
214 :group
'planner-publish
)
216 (defcustom planner-html-style-sheet
217 "<style type=\"text/css\">
219 background: white; color: black;
220 margin-left: 3%; margin-right: 3%;
223 p { margin-top: 3px; margin-bottom: 3px; }
224 p.verse { margin-left: 3% }
226 h1,h2,h3,h4,h5 { margin:0; padding:0; }
228 h1 { padding: 10px; margin-bottom: 10px; }
230 table.muse-table { margin: 0; font-size: 11px;
231 border-collapse: collapse;
233 border: 1px solid #aadeed; }
235 table.muse-table tbody td { border: 1px solid #ccdeed; }
237 .example { margin-left: 5px; padding: 3px;
239 border: 1px solid #ccdeed; }
241 /* nested sections */
242 .section { margin: 0; padding: 10px;
246 .section .section { margin: 0; margin-left: 5px;
249 .title { margin: 0; padding; 0 }
251 .section .title { font-size: 14px; }
252 .section .section .title { font-size: 12px; }
253 .section .section .section .title { font-size: 11px; }
256 .task .A { color: red }
257 .task .B { color: green }
258 .task .C { color: navy }
259 .task .done { color: gray; text-decoration: line-through; }
260 .task .cancelled { color: gray; text-decoration: italic; }
263 "Store your stylesheet definitions here. The provided default
264 is for reference only. You definitely want to customize this for
265 your particular needs & wants. This is used in
266 `planner-html-header' and `planner-xhtml-header'. Refer to
267 `muse-html-style-sheet' for details on usage. You may simply
268 override the above by specifying an explicit link to a CSS file."
270 :group
'planner-publish
)
272 (defcustom planner-html-header
273 "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\">
277 (concat (muse-publishing-directive \"title\")
278 (let ((author (muse-publishing-directive \"author\")))
279 (if (not (string= author (user-full-name)))
280 (concat \" (by \" author \")\"))))</lisp></title>
281 <meta name=\"generator\" content=\"muse.el\">
282 <meta http-equiv=\"<lisp>muse-html-meta-http-equiv</lisp>\"
283 content=\"<lisp>muse-html-meta-content-type</lisp>\">
285 (let ((maintainer (muse-style-element :maintainer)))
287 (concat \"<link rev=\\\"made\\\" href=\\\"\" maintainer \"\\\">\")))
289 <lisp>planner-html-style-sheet</lisp>
294 (concat (muse-publishing-directive \"title\")
295 (let ((author (muse-publishing-directive \"author\")))
296 (if (not (string= author (user-full-name)))
297 (concat \" (by \" author \")\"))))</lisp></span></h1>
298 <div id=\"inner-header\">
299 <lisp>planner-html-inner-header</lisp>
301 <div id=\"muse-sections\">
302 <!-- Page published by Emacs Muse begins here -->\n"
303 "Header used for publishing PLANNER HTML files.
304 This may be text or a filename."
306 :group
'planner-publish
)
308 (defcustom planner-html-footer
"
309 <!-- Page published by Emacs Muse ends here -->
311 <div id=\"inner-footer\">
312 <lisp>planner-html-inner-footer</lisp>
317 "Footer used for publishing PLANNER HTML files.
318 This may be text or a filename."
320 :group
'planner-publish
)
322 (defcustom planner-xhtml-header
323 "<?xml version=\"1.0\" encoding=\"<lisp>
324 (muse-html-encoding)</lisp>\"?>
325 <!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"
326 \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">
327 <html xmlns=\"http://www.w3.org/1999/xhtml\">
330 (concat (muse-publishing-directive \"title\")
331 (let ((author (muse-publishing-directive \"author\")))
332 (if (not (string= author (user-full-name)))
333 (concat \" (by \" author \")\"))))</lisp></title>
334 <meta name=\"generator\" content=\"muse.el\" />
335 <meta http-equiv=\"<lisp>muse-html-meta-http-equiv</lisp>\"
336 content=\"<lisp>muse-html-meta-content-type</lisp>\" />
338 (let ((maintainer (muse-style-element :maintainer)))
340 (concat \"<link rev=\\\"made\\\" href=\\\"\" maintainer \"\\\" />\")))
342 <lisp>planner-html-style-sheet</lisp>
347 (concat (muse-publishing-directive \"title\")
348 (let ((author (muse-publishing-directive \"author\")))
349 (if (not (string= author (user-full-name)))
350 (concat \" (by \" author \")\"))))</lisp></span></h1>
351 <div id=\"inner-header\">
352 <lisp>planner-html-inner-header</lisp>
354 <div id=\"muse-sections\">
355 <!-- Page published by Emacs Muse begins here -->\n"
356 "Header used for publishing PLANNER XHTML files.
357 This may be text or a filename."
359 :group
'planner-publish
)
361 (defcustom planner-xhtml-footer
"
362 <!-- Page published by Emacs Muse ends here -->
364 <div id=\"inner-footer\">
365 <lisp>planner-html-inner-footer</lisp>
370 "Footer used for publishing PLANNER XHTML files.
371 This may be text or a filename."
373 :group
'planner-publish
)
375 (defcustom planner-html-inner-header
""
376 "Extra header section that can be embedded w/in existing
377 `planner-html-header'. This may be text or a filename."
379 :group
'planner-publish
)
381 (defcustom planner-html-inner-footer
""
382 "Extra footer section that can be embedded w/in existing
383 `planner-html-footer'. This may be text or a filename."
385 :group
'planner-publish
)
387 ;;;_ + Publishing hooks
389 (defun planner-publish-prepare-buffer ()
390 (goto-char (point-min))
391 (muse-publish-markup "sections"
392 '((100 "^\\(\\*+\\)\\s-+" 0
393 planner-publish-section
))))
397 (defun planner-publish-markup-task ()
398 "Replace tasks with XML representation of task data."
401 (planner-line-beginning-position)
402 (planner-line-end-position))
403 (muse-publish-escape-specials (point-min) (point-max))
404 (let ((info (planner-current-task-info)))
405 (delete-region (point-min) (point-max))
408 (format (concat "<task id=\"%s\" priority=\"%s\" status=\"%s\""
409 " link=\"%s\" plan=\"%s\" date=\"%s\">")
410 (or (planner-task-number info
) "")
411 (or (planner-task-priority info
) "")
412 (or (planner-publish-task-status-expand
413 (planner-task-status info
)) "")
414 (or (planner-task-link-text info
) "")
415 (or (planner-task-plan info
) "")
416 (or (planner-task-date info
) ""))
417 (planner-task-description info
) ; mark this area read only
420 (defun planner-publish-markup-note ()
421 "Replace note with XML representation of note data. Borrowed
422 heavily from Sacha's personal configs."
425 (save-excursion (beginning-of-line) (point))
427 (and (re-search-forward "^\\(\\.#\\|* \\|</notes-section>\\)" nil t
)
428 (match-beginning 0)))
430 (let ((info (planner-current-note-info t
)))
431 (delete-region (point-min) (point-max))
432 (insert (format (concat "<note anchor=\"%s\" timestamp=\"%s\""
433 " link=\"%s\" categories=\"%s\">")
434 (planner-note-anchor info
)
435 (or (planner-note-timestamp info
) "")
436 (or (planner-note-link info
) "")
437 (or (planner-note-link-text info
) ""))
438 "<title>" (planner-note-title info
) "</title>\n"
439 "<content>\n" (planner-note-body info
) "\n\n</content>\n"
445 (defun planner-insert-markup (&rest args
)
446 (if (fboundp 'muse-insert-markup
)
447 (apply 'muse-insert-markup args
)
448 (apply 'insert args
)))
450 (defun planner-publish-nested-section-tag (beg end
)
451 "Generated by `planner-publish-section', the nested section tag
452 now takes in TITLE and LEVEL attributes.
454 This is related to the Muse concept of sections, but done before
455 marking up the buffer, and with special actions done on the title
459 (planner-insert-markup (muse-markup-text 'planner-begin-nested-section
))
461 (planner-insert-markup (muse-markup-text 'planner-end-nested-section
))))
463 (defun planner-publish-title-tag (beg end
)
466 (planner-insert-markup (muse-markup-text 'planner-begin-title
))
468 (planner-insert-markup (muse-markup-text 'planner-end-title
))))
470 (defun planner-publish-content-tag (beg end
)
473 (planner-insert-markup (muse-markup-text 'planner-end-content
))
475 (planner-insert-markup (muse-markup-text 'planner-begin-content
))))
477 (defun planner-publish-tasks-section-tag (beg end
)
480 (planner-insert-markup (muse-markup-text 'planner-begin-task-section
))
482 (planner-insert-markup (muse-markup-text 'planner-begin-task-body
))
484 (planner-insert-markup (muse-markup-text 'planner-end-task-body
))
485 (planner-insert-markup (muse-markup-text 'planner-end-task-section
))))
487 (defun planner-publish-task-tag (beg end attrs
)
489 (let ((number (cdr (assoc "id" attrs
)))
490 (status (cdr (assoc "status" attrs
)))
491 (priority (cdr (assoc "priority" attrs
)))
492 (link (cdr (assoc "link" attrs
)))
493 (plan (cdr (assoc "plan" attrs
)))
494 (date (cdr (assoc "date" attrs
))))
496 (planner-insert-markup
497 (muse-markup-text 'planner-begin-task
500 (concat priority number
" "
501 (planner-publish-task-status-collapse status
)
505 (insert " (" (planner-make-link link
) ")"))
506 (planner-insert-markup (muse-markup-text 'planner-end-task
)))))
508 (defun planner-publish-notes-section-tag (beg end
)
509 "Replace the region BEG to END with the notes for this page."
511 (planner-insert-markup (muse-markup-text 'planner-begin-note-section
))
513 (planner-insert-markup (muse-markup-text 'planner-begin-body
))
516 (planner-insert-markup (muse-markup-text 'planner-end-body
))
517 (planner-insert-markup (muse-markup-text 'planner-end-note-section
))))
519 (defun planner-publish-notes-tag (beg end
)
520 "Replace the region BEG to END with an index of the notes for this page."
521 (delete-region beg end
)
525 (insert (format " - [[%s%s][%s]]\n"
528 (planner-remove-links (cdr item
)))))
530 (find-file muse-publishing-current-file
)
531 (planner-notes-get-headlines)))
534 (defun planner-publish-past-notes-tag (beg end attrs
)
535 "Replace the region BEG to END with an index of past notes.
536 If ATTRS is non-nil, it is an alist containing values for
537 DIRECTORY and START."
538 (let ((files (save-excursion
539 (find-file muse-publishing-current-file
)
540 (planner-get-day-pages nil nil t
)))
541 (earliest (cdr (assoc "start" attrs
))))
543 (when (or (null earliest
)
544 (not (string-lessp (caar files
) earliest
)))
545 (let ((title-lines (list t
)))
547 (insert-file-contents (cdar files
))
548 (while (re-search-forward "^\\.#\\([0-9]+\\)\\s-+\\(.+\\)" nil t
)
549 (nconc title-lines
(list (cons (match-string 1)
550 (match-string 2))))))
551 (setq title-lines
(cdr title-lines
))
553 (insert (planner-make-link (planner-page-name (caar files
)))
555 (planner-insert-markup " <dl class=\"contents\">\n")
557 (planner-insert-markup " <dt class=\"contents\">")
558 (insert (format "[[%s#%s][%s]]"
559 (planner-page-name (caar files
))
560 (caar title-lines
) (cdar title-lines
)))
561 (planner-insert-markup "</dt>\n")
562 (setq title-lines
(cdr title-lines
)))
563 (planner-insert-markup " </dl>\n\n"))))
564 (setq files
(cdr files
)))))
566 (defun planner-publish-note-tag (beg end attrs
)
568 (let ((anchor (or (cdr (assoc "anchor" attrs
)) ""))
569 (timestamp (or (cdr (assoc "timestamp" attrs
)) ""))
570 (link (or (cdr (assoc "link" attrs
)) ""))
571 (categories (or (cdr (assoc "categories" attrs
)) "")))
574 (planner-insert-markup (muse-markup-text 'planner-begin-note
576 (concat "#" anchor
)))
578 (planner-insert-markup (muse-markup-text 'planner-begin-note-details
580 (muse-markup-text 'planner-begin-note-link
))
582 (planner-insert-markup (muse-markup-text 'planner-end-note-link
)
583 (muse-markup-text 'planner-begin-note-categories
))
585 (planner-insert-markup (muse-markup-text 'planner-end-note-categories
))
587 (planner-insert-markup (muse-markup-text 'planner-end-note-details
))
588 (planner-insert-markup (muse-markup-text 'planner-end-note
)))))
590 ;;;_ + helper routine
592 (defun planner-publish-task-status-expand (status)
594 ((string= status
"_") "open")
595 ((string= status
"o") "in-progress")
596 ((string= status
"D") "delegated")
597 ((string= status
"P") "pending")
598 ((string= status
"X") "done")
599 ((string= status
"C") "cancelled")
602 (defun planner-publish-task-status-collapse (status)
604 ((string= status
"open") "_")
605 ((string= status
"in-progress") "o")
606 ((string= status
"delegated") "D")
607 ((string= status
"pending") "P")
608 ((string= status
"done") "X")
609 ((string= status
"cancelled") "C")
612 (defun planner-publish-section-close (depth text
)
613 "Find where the closing tag of DEPTH should go, and insert TEXT."
616 (while (and (setq not-end
(re-search-forward
617 (concat "^\\*\\{1," (number-to-string depth
)
620 (get-text-property (match-beginning 0) 'read-only
)))
623 (goto-char (point-max)))
624 (cond ((not (eq (char-before) ?
\n))
626 ((not (eq (char-before (1- (point))) ?
\n))
631 (defvar planner-section-tagnames
632 "Alist of sections and their tag name."
633 '(("Tasks" .
"tasks-section")
634 ("Notes" .
"notes-section")))
636 (defun planner-publish-section-tagname (text)
637 "A routine that checks `planner-section-tagnames' for tagname."
638 (let ((tagname (cdr (assoc text planner-section-tagnames
))))
643 (defun planner-publish-section ()
644 "Publish the current heading as a section."
645 (let* ((depth (length (match-string 1)))
646 (title (buffer-substring (match-end 0) (planner-line-end-position)))
647 (tagname (planner-publish-section-tagname title
)))
648 (delete-region (match-beginning 0) (match-end 0))
649 (insert (format "<%s level=\"%s\"><title>" tagname depth
))
652 (planner-publish-section-close depth
(format "</%s>" tagname
))))
654 ;;;_ + Planner Style Definitions
656 (unless (assoc "planner-xml" muse-publishing-styles
)
657 (muse-derive-style "planner-xml" "xml"
658 :regexps
'planner-publish-markup-regexps
659 :functions
'planner-publish-markup-functions
660 :tags
'planner-publish-markup-tags
661 :strings
'planner-xml-markup-strings
662 :before
'planner-publish-prepare-buffer
663 :header
'planner-xml-header
664 :footer
'planner-xml-footer
)
665 (muse-derive-style "planner-html" "html"
666 :regexps
'planner-publish-markup-regexps
667 :functions
'planner-publish-markup-functions
668 :tags
'planner-publish-markup-tags
669 :strings
'planner-html-markup-strings
670 :before
'planner-publish-prepare-buffer
671 :header
'planner-html-header
672 :footer
'planner-html-footer
)
673 (muse-derive-style "planner-xhtml" "xhtml"
674 :regexps
'planner-publish-markup-regexps
675 :functions
'planner-publish-markup-functions
676 :tags
'planner-publish-markup-tags
677 :strings
'planner-html-markup-strings
678 :before
'planner-publish-prepare-buffer
679 :header
'planner-xhtml-header
680 :footer
'planner-xhtml-footer
))
682 (provide 'planner-publish
)
684 ;;; planner-publish.el ends here