Document planner-registry.el.
[planner-el.git] / planner-publish.el
blob27c094abc25cbb4b07c7931616e8047d201481ba
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)
18 ;; any later version.
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.
30 ;;; Commentary:
32 ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
34 ;;; Introduction
36 ;; Muse Styles for Planner: planner-xml, planner-html, planner-xhtml, etc.
38 ;; Handles publishing of planner files. Works with Muse to generate
39 ;; flexible markup.
41 ;;; History:
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
48 ;;; TODO:
50 ;; add support for various PLANNER specific sections such as Diary,
51 ;; Accomplishments, Timeclock, etc.
53 ;;; Contributors:
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"
65 ;; attribute.
67 (require 'planner)
69 (require 'muse-mode)
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."
77 :group 'planner)
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"
87 integer
88 (choice regexp symbol)
89 integer
90 (choice string function symbol))
91 function))
92 :group 'muse-html)
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 t planner-publish-title-tag)
106 ("content" t nil planner-publish-content-tag)
107 ("diary-section" t nil planner-publish-diary-section-tag)
108 ("tasks-section" t nil planner-publish-tasks-section-tag)
109 ("notes-section" t nil planner-publish-notes-section-tag)
110 ("notes" nil nil planner-publish-notes-tag)
111 ("past-notes" nil t planner-publish-past-notes-tag)
112 ("task" t t planner-publish-task-tag)
113 ("note" t t planner-publish-note-tag))
114 "A list of tag specifications, for specially marking up PLANNER.
115 See `muse-publish-markup-tags' for more information."
116 :type '(repeat (list (string :tag "Markup tag")
117 (boolean :tag "Expect closing tag" :value t)
118 (boolean :tag "Parse attributes" :value nil)
119 function))
120 :group 'planner-publish)
122 ;;;_ + XML specific customizations
124 (defcustom planner-xml-markup-strings
125 '((planner-begin-nested-section . "<section>")
126 (planner-end-nested-section . "</section>")
127 (planner-begin-title . "<title>")
128 (planner-end-title . "</title>")
129 (planner-begin-content . "")
130 (planner-end-content . "")
131 (planner-begin-body . "")
132 (planner-end-body . "")
133 (planner-begin-diary-section . "<diary>")
134 (planner-end-diary-section . "</diary>")
135 (planner-begin-task-section . "<tasks>")
136 (planner-end-task-section . "</tasks>")
137 (planner-begin-task-body . "")
138 (planner-end-task-body . "")
139 (planner-begin-note-section . "<notes>")
140 (planner-end-note-section . "</notes>")
141 (planner-begin-task . "<task status=\"%s\" priority=\"%s\">")
142 (planner-end-task . "</task>")
143 (planner-begin-note . "<note number=\"%s\">")
144 (planner-end-note . "</note>")
145 (planner-begin-note-details . "<details><timestamp>%s</timestamp>")
146 (planner-end-note-details . "</details>")
147 (planner-begin-note-link . "<references>")
148 (planner-end-note-link . "</references>")
149 (planner-begin-note-categories . "<categories>")
150 (planner-end-note-categories . "</categories>"))
151 "Strings used for marking up text as XML.
152 These cover the most basic kinds of markup, the handling of which
153 differs little between the various styles.
155 If a markup rule is not found here, `muse-xml-markup-strings' is
156 searched."
157 :type '(alist :key-type symbol :value-type string)
158 :group 'planner-publish)
160 (defcustom planner-xml-header
161 "<?xml version=\"1.0\" encoding=\"<lisp>(muse-xml-encoding)</lisp>\"?>
162 <PLANNER>
163 <pageinfo>
164 <title><lisp>(muse-publishing-directive \"title\")</lisp></title>
165 <author><lisp>(muse-publishing-directive \"author\")</lisp></author>
166 <maintainer><lisp>(muse-style-element :maintainer)</lisp></maintainer>
167 <pubdate><lisp>(muse-publishing-directive \"date\")</lisp></pubdate>
168 </pageinfo>
169 <!-- Page published by Emacs Muse begins here -->\n"
170 "Header used for publishing PLANNER XML files.
171 This may be text or a filename."
172 :type 'string
173 :group 'planner-publish)
175 (defcustom planner-xml-footer "
176 <!-- Page published by Emacs Muse ends here -->
177 </PLANNER>\n"
178 "Footer used for publishing PLANNER XML files.
179 This may be text or a filename."
180 :type 'string
181 :group 'planner-publish)
183 ;;;_ + HTML specific customizations
185 (defcustom planner-html-markup-strings
186 '((planner-begin-nested-section . "<div class=\"section\">")
187 (planner-end-nested-section . "</div>")
188 (planner-begin-title . "<h%s>")
189 (planner-end-title . "</h%s>")
190 (planner-begin-content . "<div class=\"content\">")
191 (planner-end-content . "</div>")
192 (planner-begin-body . "<div class=\"body\">")
193 (planner-end-body . "</div>")
194 (planner-begin-diary-section . "<div id=\"diary\" class=\"section\">")
195 (planner-end-diary-section . "</div>")
196 (planner-begin-task-section . "<div id=\"tasks\" class=\"section\">")
197 (planner-end-task-section . "</div>")
198 (planner-begin-task-body . "<ul class=\"body\">")
199 (planner-end-task-body . "</ul>")
200 (planner-begin-note-section . "<div id=\"notes\" class=\"section\">")
201 (planner-end-note-section . "</div>")
202 (planner-begin-task . "<li class=\"task\"><span class=\"%s\"><span class=\"%s\">%s</span>")
203 (planner-end-task . "</span></li>")
204 (planner-begin-note . "<div class=\"note\"><a name=\"%s\"></a><span class=\"anchor\">%s</span>")
205 (planner-end-note . "</div>")
206 (planner-begin-note-details . "<div class=\"details\"><span class=\"timestamp\">%s</span>")
207 (planner-end-note-details . "</div>")
208 (planner-begin-note-link . " <span class=\"link\">")
209 (planner-end-note-link . "</span>")
210 (planner-begin-note-categories . " <span class=\"categories\">")
211 (planner-end-note-categories . "</span>"))
212 "Strings used for marking up text as HTML.
213 These cover the most basic kinds of markup, the handling of which
214 differs little between the various styles.
216 If a markup rule is not found here, `muse-html-markup-strings' is
217 searched."
218 :type '(alist :key-type symbol :value-type string)
219 :group 'planner-publish)
221 (defcustom planner-html-style-sheet
222 "<style type=\"text/css\">
223 body {
224 background: white; color: black;
225 margin-left: 3%; margin-right: 3%;
228 p { margin-top: 3px; margin-bottom: 3px; }
229 p.verse { margin-left: 3% }
231 h1,h2,h3,h4,h5 { margin:0; padding:0; }
233 h1 { padding: 10px; margin-bottom: 10px; }
235 table.muse-table { margin: 0; font-size: 11px;
236 border-collapse: collapse;
237 background: #e2effa;
238 border: 1px solid #aadeed; }
240 table.muse-table tbody td { border: 1px solid #ccdeed; }
242 .example { margin-left: 5px; padding: 3px;
243 background: #fffffc;
244 border: 1px solid #ccdeed; }
246 /* nested sections */
247 .section { margin: 0; padding: 10px;
248 margin-bottom: 15px;
249 font-size: 12px; }
251 .section .section { margin: 0; margin-left: 5px;
252 font-size: 11px; }
254 .title { margin: 0; padding; 0 }
256 /* optional calendar section */
257 .calendar { float: right; }
258 table.month-calendar { font-size: 9px; }
260 /* Diary section */
261 #diary p { margin-top: 1em; }
263 /* Tasks section */
264 .task .A { color: red }
265 .task .B { color: green }
266 .task .C { color: navy }
267 .task .done { color: gray; text-decoration: line-through; }
268 .task .cancelled { color: gray; text-decoration: italic; }
270 /* Notes section */
271 .note { margin-top: 1.5em; }
272 .note .anchor { float: left; margin-right: 5px; }
273 .note .details { margin-top: .5em; }
275 </style>"
276 "Store your stylesheet definitions here. The provided default
277 is for reference only. You definitely want to customize this for
278 your particular needs & wants. This is used in
279 `planner-html-header' and `planner-xhtml-header'. Refer to
280 `muse-html-style-sheet' for details on usage. You may simply
281 override the above by specifying an explicit link to a CSS file."
282 :type 'string
283 :group 'planner-publish)
285 (defcustom planner-html-header
286 "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\">
287 <html>
288 <head>
289 <title><lisp>
290 (concat (muse-publishing-directive \"title\")
291 (let ((author (muse-publishing-directive \"author\")))
292 (if (not (string= author (user-full-name)))
293 (concat \" (by \" author \")\"))))</lisp></title>
294 <meta name=\"generator\" content=\"muse.el\">
295 <meta http-equiv=\"<lisp>muse-html-meta-http-equiv</lisp>\"
296 content=\"<lisp>muse-html-meta-content-type</lisp>\">
297 <lisp>
298 (let ((maintainer (muse-style-element :maintainer)))
299 (when maintainer
300 (concat \"<link rev=\\\"made\\\" href=\\\"\" maintainer \"\\\">\")))
301 </lisp>
302 <lisp>planner-html-style-sheet</lisp>
303 </head>
304 <body>
305 <div id=\"content\">
306 <h1><span><lisp>
307 (concat (muse-publishing-directive \"title\")
308 (let ((author (muse-publishing-directive \"author\")))
309 (if (not (string= author (user-full-name)))
310 (concat \" (by \" author \")\"))))</lisp></span></h1>
311 <div id=\"inner-header\">
312 <lisp>planner-html-inner-header</lisp>
313 </div>
314 <div id=\"muse-sections\">
315 <!-- Page published by Emacs Muse begins here -->\n"
316 "Header used for publishing PLANNER HTML files.
317 This may be text or a filename."
318 :type 'string
319 :group 'planner-publish)
321 (defcustom planner-html-footer "
322 <!-- Page published by Emacs Muse ends here -->
323 </div>
324 <div id=\"inner-footer\">
325 <lisp>planner-html-inner-footer</lisp>
326 </div>
327 </div>
328 </body>
329 </html>\n"
330 "Footer used for publishing PLANNER HTML files.
331 This may be text or a filename."
332 :type 'string
333 :group 'planner-publish)
335 (defcustom planner-xhtml-header
336 "<?xml version=\"1.0\" encoding=\"<lisp>
337 (muse-html-encoding)</lisp>\"?>
338 <!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"
339 \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">
340 <html xmlns=\"http://www.w3.org/1999/xhtml\">
341 <head>
342 <title><lisp>
343 (concat (muse-publishing-directive \"title\")
344 (let ((author (muse-publishing-directive \"author\")))
345 (if (not (string= author (user-full-name)))
346 (concat \" (by \" author \")\"))))</lisp></title>
347 <meta name=\"generator\" content=\"muse.el\" />
348 <meta http-equiv=\"<lisp>muse-html-meta-http-equiv</lisp>\"
349 content=\"<lisp>muse-html-meta-content-type</lisp>\" />
350 <lisp>
351 (let ((maintainer (muse-style-element :maintainer)))
352 (when maintainer
353 (concat \"<link rev=\\\"made\\\" href=\\\"\" maintainer \"\\\" />\")))
354 </lisp>
355 <lisp>planner-html-style-sheet</lisp>
356 </head>
357 <body>
358 <div id=\"content\">
359 <h1><span><lisp>
360 (concat (muse-publishing-directive \"title\")
361 (let ((author (muse-publishing-directive \"author\")))
362 (if (not (string= author (user-full-name)))
363 (concat \" (by \" author \")\"))))</lisp></span></h1>
364 <div id=\"inner-header\">
365 <lisp>planner-html-inner-header</lisp>
366 </div>
367 <div id=\"muse-sections\">
368 <!-- Page published by Emacs Muse begins here -->\n"
369 "Header used for publishing PLANNER XHTML files.
370 This may be text or a filename."
371 :type 'string
372 :group 'planner-publish)
374 (defcustom planner-xhtml-footer "
375 <!-- Page published by Emacs Muse ends here -->
376 </div>
377 <div id=\"inner-footer\">
378 <lisp>planner-html-inner-footer</lisp>
379 </div>
380 </div>
381 </body>
382 </html>\n"
383 "Footer used for publishing PLANNER XHTML files.
384 This may be text or a filename."
385 :type 'string
386 :group 'planner-publish)
388 (defcustom planner-html-inner-header ""
389 "Extra header section that can be embedded within
390 `planner-html-header' and `planner-xhtml-header'."
391 :type 'string
392 :group 'planner-publish)
394 (defcustom planner-html-inner-footer ""
395 "Extra footer section that can be embedded within
396 `planner-html-footer' and `planner-xhtml-footer'."
397 :type 'string
398 :group 'planner-publish)
400 ;;;_ + Publishing hooks
402 (defcustom planner-publish-prepare-regexps
403 '((100 "^\\(\\*+\\)\\s-+" 0 planner-publish-section))
404 "List of markup rules to apply before publishing a page with Planner.
405 See `muse-publish-markup-regexps' for details on the syntax used."
406 :type '(repeat (choice
407 (list :tag "Markup rule"
408 integer
409 (choice regexp symbol)
410 integer
411 (choice string function symbol))
412 function))
413 :group 'planner-publish)
415 (defcustom planner-publish-finalize-regexps
417 "List of markup rules to apply after publishing a page with Planner.
418 See `muse-publish-markup-regexps' for details on the syntax used."
419 :type '(repeat (choice
420 (list :tag "Markup rule"
421 integer
422 (choice regexp symbol)
423 integer
424 (choice string function symbol))
425 function))
426 :group 'planner-publish)
428 (defun planner-publish-prepare-buffer ()
429 (goto-char (point-min))
430 (muse-publish-markup "preparing Planner page"
431 planner-publish-prepare-regexps)
432 ;; indicate that we are to continue preparing the buffer
433 nil)
435 (defun planner-publish-finalize-buffer ()
436 (goto-char (point-min))
437 (muse-publish-markup "finalizing Planner page"
438 planner-publish-finalize-regexps)
439 ;; indicate that we are to continue finalizing the buffer
440 nil)
442 ;;;_ + Markup
444 (defun planner-publish-markup-task ()
445 "Replace tasks with XML representation of task data."
446 (save-restriction
447 (narrow-to-region
448 (planner-line-beginning-position)
449 (planner-line-end-position))
450 (muse-publish-escape-specials (point-min) (point-max))
451 (let ((info (planner-current-task-info)))
452 (delete-region (point-min) (point-max))
453 (forward-line 1)
454 (insert
455 (format (concat "<task id=\"%s\" priority=\"%s\" status=\"%s\""
456 " link=\"%s\" plan=\"%s\" date=\"%s\">")
457 (or (planner-task-number info) "")
458 (or (planner-task-priority info) "")
459 (or (planner-publish-task-status-expand
460 (planner-task-status info)) "")
461 (or (planner-task-link-text info) "")
462 (or (planner-task-plan info) "")
463 (or (planner-task-date info) ""))
464 (planner-task-description info) ; mark this area read only
465 "</task>"))))
467 (defun planner-publish-markup-note ()
468 "Replace note with XML representation of note data. Borrowed
469 heavily from Sacha's personal configs."
470 (save-restriction
471 (narrow-to-region
472 (save-excursion (beginning-of-line) (point))
473 (or (save-excursion
474 (and (re-search-forward "^\\(\\.#\\|* \\|</notes-section>\\)" nil t)
475 (match-beginning 0)))
476 (point-max)))
477 (let ((info (planner-current-note-info t)))
478 (delete-region (point-min) (point-max))
479 (insert (format (concat "<note anchor=\"%s\" timestamp=\"%s\""
480 " link=\"%s\" categories=\"%s\">")
481 (planner-note-anchor info)
482 (or (planner-note-timestamp info) "")
483 (or (planner-note-link info) "")
484 (or (planner-note-link-text info) ""))
485 "<title level=\"3\">" (planner-note-title info) "</title>\n"
486 "<content>\n" (planner-note-body info) "\n\n</content>\n"
487 "</note>\n"))))
490 ;;;_ + Tags
492 (defun planner-insert-markup (&rest args)
493 (if (fboundp 'muse-insert-markup)
494 (apply 'muse-insert-markup args)
495 (let ((beg (point)))
496 (apply 'insert args)
497 (muse-publish-mark-read-only beg (point)))))
499 (defun planner-publish-nested-section-tag (beg end)
500 "Generated by `planner-publish-section', the nested section tag
501 now takes in TITLE and LEVEL attributes.
503 This is related to the Muse concept of sections, but done before
504 marking up the buffer, and with special actions done on the title
505 of each section."
506 (save-excursion
507 (goto-char beg)
508 (planner-insert-markup (muse-markup-text 'planner-begin-nested-section))
509 (goto-char end)
510 (planner-insert-markup (muse-markup-text 'planner-end-nested-section))))
512 (defun planner-publish-title-tag (beg end attrs)
513 (let ((level (cdr (assoc "level" attrs))))
514 (save-excursion
515 (goto-char beg)
516 (planner-insert-markup (muse-markup-text 'planner-begin-title level))
517 (goto-char end)
518 (planner-insert-markup (muse-markup-text 'planner-end-title level)))))
520 (defun planner-publish-content-tag (beg end)
521 (save-excursion
522 (goto-char end)
523 (planner-insert-markup (muse-markup-text 'planner-end-content))
524 (goto-char beg)
525 (planner-insert-markup (muse-markup-text 'planner-begin-content))))
527 (defun planner-publish-diary-section-tag (beg end)
528 (save-excursion
529 (goto-char beg)
530 (planner-insert-markup (muse-markup-text 'planner-begin-diary-section))
531 (forward-line 1)
532 (muse-publish-verse-tag (point) end)
533 (goto-char end)
534 (planner-insert-markup (muse-markup-text 'planner-end-diary-section))))
536 (defun planner-publish-tasks-section-tag (beg end)
537 (save-excursion
538 (goto-char beg)
539 (planner-insert-markup (muse-markup-text 'planner-begin-task-section))
540 (forward-line 1)
541 (planner-insert-markup (muse-markup-text 'planner-begin-task-body))
542 (goto-char end)
543 (planner-insert-markup (muse-markup-text 'planner-end-task-body))
544 (planner-insert-markup (muse-markup-text 'planner-end-task-section))))
546 (defun planner-publish-task-tag (beg end attrs)
547 (save-excursion
548 (let ((number (cdr (assoc "id" attrs)))
549 (status (cdr (assoc "status" attrs)))
550 (priority (cdr (assoc "priority" attrs)))
551 (link (cdr (assoc "link" attrs)))
552 (plan (cdr (assoc "plan" attrs)))
553 (date (cdr (assoc "date" attrs))))
554 (goto-char beg)
555 (planner-insert-markup
556 (muse-markup-text 'planner-begin-task
557 status
558 priority
559 (concat priority number " "
560 (planner-publish-task-status-collapse status)
561 " ")))
562 (goto-char end)
563 (when link
564 (insert " (" (planner-make-link link) ")"))
565 (planner-insert-markup (muse-markup-text 'planner-end-task)))))
567 (defun planner-publish-notes-section-tag (beg end)
568 "Replace the region BEG to END with the notes for this page."
569 (save-excursion
570 (planner-insert-markup (muse-markup-text 'planner-begin-note-section))
571 (forward-line 1)
572 (planner-insert-markup (muse-markup-text 'planner-begin-body))
573 (insert ?\n)
574 (goto-char end)
575 (planner-insert-markup (muse-markup-text 'planner-end-body))
576 (planner-insert-markup (muse-markup-text 'planner-end-note-section))))
578 (defun planner-publish-notes-tag (beg end)
579 "Replace the region BEG to END with an index of the notes for this page."
580 (delete-region beg end)
581 (insert "\n")
582 (mapcar
583 (lambda (item)
584 (insert (format " - [[%s%s][%s]]\n"
585 (planner-page-name)
586 (car item)
587 (planner-remove-links (cdr item)))))
588 (save-excursion
589 (find-file muse-publishing-current-file)
590 (planner-notes-get-headlines)))
591 (insert "\n"))
593 (defun planner-publish-past-notes-tag (beg end attrs)
594 "Replace the region BEG to END with an index of past notes.
595 If ATTRS is non-nil, it is an alist containing values for
596 DIRECTORY and START."
597 (let ((files (save-excursion
598 (find-file muse-publishing-current-file)
599 (planner-get-day-pages nil nil t)))
600 (earliest (cdr (assoc "start" attrs))))
601 (while files
602 (when (or (null earliest)
603 (not (string-lessp (caar files) earliest)))
604 (let ((title-lines (list t)))
605 (with-temp-buffer
606 (insert-file-contents (cdar files))
607 (while (re-search-forward "^\\.#\\([0-9]+\\)\\s-+\\(.+\\)" nil t)
608 (nconc title-lines (list (cons (match-string 1)
609 (match-string 2))))))
610 (setq title-lines (cdr title-lines))
611 (when title-lines
612 (insert (planner-make-link (planner-page-name (caar files)))
613 " ::\n")
614 (planner-insert-markup " <dl class=\"contents\">\n")
615 (while title-lines
616 (planner-insert-markup " <dt class=\"contents\">")
617 (insert (format "[[%s#%s][%s]]"
618 (planner-page-name (caar files))
619 (caar title-lines) (cdar title-lines)))
620 (planner-insert-markup "</dt>\n")
621 (setq title-lines (cdr title-lines)))
622 (planner-insert-markup " </dl>\n\n"))))
623 (setq files (cdr files)))))
625 (defun planner-publish-note-tag (beg end attrs)
626 (save-excursion
627 (let ((anchor (or (cdr (assoc "anchor" attrs)) ""))
628 (timestamp (or (cdr (assoc "timestamp" attrs)) ""))
629 (link (or (cdr (assoc "link" attrs)) ""))
630 (categories (or (cdr (assoc "categories" attrs)) "")))
632 (goto-char beg)
633 (planner-insert-markup (muse-markup-text 'planner-begin-note
634 anchor
635 (concat "#" anchor)))
636 (goto-char end)
637 (planner-insert-markup (muse-markup-text 'planner-begin-note-details
638 timestamp)
639 (muse-markup-text 'planner-begin-note-link))
640 (insert link)
641 (planner-insert-markup (muse-markup-text 'planner-end-note-link))
642 ;; remove link item from categories to avoid duplicates
643 (setq categories (planner-replace-regexp-in-string (regexp-quote link)
644 categories "" t t))
645 (planner-insert-markup (muse-markup-text 'planner-begin-note-categories))
646 (insert categories)
647 (planner-insert-markup (muse-markup-text 'planner-end-note-categories))
648 (insert ?\n)
649 (planner-insert-markup (muse-markup-text 'planner-end-note-details))
650 (planner-insert-markup (muse-markup-text 'planner-end-note)))))
652 ;;;_ + helper routine
654 (defun planner-publish-task-status-expand (status)
655 (cond
656 ((string= status "_") "open")
657 ((string= status "o") "in-progress")
658 ((string= status "D") "delegated")
659 ((string= status "P") "pending")
660 ((string= status "X") "done")
661 ((string= status "C") "cancelled")
662 (t "unknown")))
664 (defun planner-publish-task-status-collapse (status)
665 (cond
666 ((string= status "open") "_")
667 ((string= status "in-progress") "o")
668 ((string= status "delegated") "D")
669 ((string= status "pending") "P")
670 ((string= status "done") "X")
671 ((string= status "cancelled") "C")
672 (t "?")))
674 (defun planner-publish-section-close (depth text)
675 "Find where the closing tag of DEPTH should go, and insert TEXT."
676 (let (not-end)
677 (save-excursion
678 (while (and (setq not-end (re-search-forward
679 (concat "^\\*\\{1," (number-to-string depth)
680 "\\}\\s-+")
681 nil t))
682 (get-text-property (match-beginning 0) 'read-only)))
683 (if not-end
684 (forward-line 0)
685 (goto-char (point-max)))
686 (cond ((not (eq (char-before) ?\n))
687 (insert "\n\n"))
688 ((not (eq (char-before (1- (point))) ?\n))
689 (insert "\n")))
690 (insert text)
691 (insert "\n"))))
693 (defvar planner-section-tagnames
694 '(("Diary" . "diary-section")
695 ("Tasks" . "tasks-section")
696 ("Notes" . "notes-section"))
697 "Alist of sections and their tag name.")
699 (defun planner-publish-section-tagname (text)
700 "A routine that checks `planner-section-tagnames' for tagname."
701 (let ((tagname (cdr (assoc text planner-section-tagnames))))
702 (if tagname
703 tagname
704 "nested-section")))
706 (defun planner-publish-section ()
707 "Publish the current heading as a section."
708 (let* ((depth (length (match-string 1)))
709 (title (buffer-substring (match-end 0) (planner-line-end-position)))
710 (tagname (planner-publish-section-tagname title)))
711 (delete-region (match-beginning 0) (match-end 0))
712 (insert (format "<%s level=\"%s\"><title level=\"%s\">"
713 tagname depth (1+ depth)))
714 (end-of-line)
715 (insert "</title>")
716 (planner-publish-section-close depth (format "</%s>" tagname))))
718 ;;;_ + Planner Style Definitions
720 (unless (assoc "planner-xml" muse-publishing-styles)
721 (muse-derive-style "planner-xml" "xml"
722 :regexps 'planner-publish-markup-regexps
723 :functions 'planner-publish-markup-functions
724 :tags 'planner-publish-markup-tags
725 :strings 'planner-xml-markup-strings
726 :before 'planner-publish-prepare-buffer
727 :after 'planner-publish-finalize-buffer
728 :header 'planner-xml-header
729 :footer 'planner-xml-footer)
730 (muse-derive-style "planner-html" "html"
731 :regexps 'planner-publish-markup-regexps
732 :functions 'planner-publish-markup-functions
733 :tags 'planner-publish-markup-tags
734 :strings 'planner-html-markup-strings
735 :before 'planner-publish-prepare-buffer
736 :after 'planner-publish-finalize-buffer
737 :header 'planner-html-header
738 :footer 'planner-html-footer)
739 (muse-derive-style "planner-xhtml" "xhtml"
740 :regexps 'planner-publish-markup-regexps
741 :functions 'planner-publish-markup-functions
742 :tags 'planner-publish-markup-tags
743 :strings 'planner-html-markup-strings
744 :before 'planner-publish-prepare-buffer
745 :after 'planner-publish-finalize-buffer
746 :header 'planner-xhtml-header
747 :footer 'planner-xhtml-footer))
749 (provide 'planner-publish)
751 ;;; planner-publish.el ends here