Merged from mwolson@gnu.org--2006 (patch 34)
[planner-el.git] / planner-publish.el
blob24488186a9dc0467ccdde1dc2901d40f759983c5
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 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)
118 function))
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
153 searched."
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>\"?>
159 <PLANNER>
160 <pageinfo>
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>
165 </pageinfo>
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."
169 :type 'string
170 :group 'planner-publish)
172 (defcustom planner-xml-footer "
173 <!-- Page published by Emacs Muse ends here -->
174 </PLANNER>\n"
175 "Footer used for publishing PLANNER XML files.
176 This may be text or a filename."
177 :type 'string
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
212 searched."
213 :type '(alist :key-type symbol :value-type string)
214 :group 'planner-publish)
216 (defcustom planner-html-style-sheet
217 "<style type=\"text/css\">
218 body {
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;
232 background: #e2effa;
233 border: 1px solid #aadeed; }
235 table.muse-table tbody td { border: 1px solid #ccdeed; }
237 .example { margin-left: 5px; padding: 3px;
238 background: #fffffc;
239 border: 1px solid #ccdeed; }
241 /* nested sections */
242 .section { margin: 0; padding: 10px;
243 margin-bottom: 15px;
244 font-size: 12px; }
246 .section .section { margin: 0; margin-left: 5px;
247 font-size: 11px; }
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; }
255 /* Tasks section */
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; }
262 </style>"
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."
269 :type 'string
270 :group 'planner-publish)
272 (defcustom planner-html-header
273 "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\">
274 <html>
275 <head>
276 <title><lisp>
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>\">
284 <lisp>
285 (let ((maintainer (muse-style-element :maintainer)))
286 (when maintainer
287 (concat \"<link rev=\\\"made\\\" href=\\\"\" maintainer \"\\\">\")))
288 </lisp>
289 <lisp>planner-html-style-sheet</lisp>
290 </head>
291 <body>
292 <div id=\"content\">
293 <h1><span><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>
300 </div>
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."
305 :type 'string
306 :group 'planner-publish)
308 (defcustom planner-html-footer "
309 <!-- Page published by Emacs Muse ends here -->
310 </div>
311 <div id=\"inner-footer\">
312 <lisp>planner-html-inner-footer</lisp>
313 </div>
314 </div>
315 </body>
316 </html>\n"
317 "Footer used for publishing PLANNER HTML files.
318 This may be text or a filename."
319 :type 'string
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\">
328 <head>
329 <title><lisp>
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>\" />
337 <lisp>
338 (let ((maintainer (muse-style-element :maintainer)))
339 (when maintainer
340 (concat \"<link rev=\\\"made\\\" href=\\\"\" maintainer \"\\\" />\")))
341 </lisp>
342 <lisp>planner-html-style-sheet</lisp>
343 </head>
344 <body>
345 <div id=\"content\">
346 <h1><span><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>
353 </div>
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."
358 :type 'string
359 :group 'planner-publish)
361 (defcustom planner-xhtml-footer "
362 <!-- Page published by Emacs Muse ends here -->
363 </div>
364 <div id=\"inner-footer\">
365 <lisp>planner-html-inner-footer</lisp>
366 </div>
367 </div>
368 </body>
369 </html>\n"
370 "Footer used for publishing PLANNER XHTML files.
371 This may be text or a filename."
372 :type 'string
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."
378 :type 'string
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."
384 :type 'string
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))))
395 ;;;_ + Markup
397 (defun planner-publish-markup-task ()
398 "Replace tasks with XML representation of task data."
399 (save-restriction
400 (narrow-to-region
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))
406 (forward-line 1)
407 (insert
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
418 "</task>"))))
420 (defun planner-publish-markup-note ()
421 "Replace note with XML representation of note data. Borrowed
422 heavily from Sacha's personal configs."
423 (save-restriction
424 (narrow-to-region
425 (save-excursion (beginning-of-line) (point))
426 (or (save-excursion
427 (and (re-search-forward "^\\(\\.#\\|* \\|</notes-section>\\)" nil t)
428 (match-beginning 0)))
429 (point-max)))
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"
440 "</note>\n"))))
443 ;;;_ + Tags
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
456 of each section."
457 (save-excursion
458 (goto-char beg)
459 (planner-insert-markup (muse-markup-text 'planner-begin-nested-section))
460 (goto-char end)
461 (planner-insert-markup (muse-markup-text 'planner-end-nested-section))))
463 (defun planner-publish-title-tag (beg end)
464 (save-excursion
465 (goto-char beg)
466 (planner-insert-markup (muse-markup-text 'planner-begin-title))
467 (goto-char end)
468 (planner-insert-markup (muse-markup-text 'planner-end-title))))
470 (defun planner-publish-content-tag (beg end)
471 (save-excursion
472 (goto-char end)
473 (planner-insert-markup (muse-markup-text 'planner-end-content))
474 (goto-char beg)
475 (planner-insert-markup (muse-markup-text 'planner-begin-content))))
477 (defun planner-publish-tasks-section-tag (beg end)
478 (save-excursion
479 (goto-char beg)
480 (planner-insert-markup (muse-markup-text 'planner-begin-task-section))
481 (forward-line 1)
482 (planner-insert-markup (muse-markup-text 'planner-begin-task-body))
483 (goto-char end)
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)
488 (save-excursion
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))))
495 (goto-char beg)
496 (planner-insert-markup
497 (muse-markup-text 'planner-begin-task
498 status
499 priority
500 (concat priority number " "
501 (planner-publish-task-status-collapse status)
502 " ")))
503 (goto-char end)
504 (when link
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."
510 (save-excursion
511 (planner-insert-markup (muse-markup-text 'planner-begin-note-section))
512 (forward-line 1)
513 (planner-insert-markup (muse-markup-text 'planner-begin-body))
514 (insert ?\n)
515 (goto-char end)
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)
522 (insert "\n")
523 (mapcar
524 (lambda (item)
525 (insert (format " - [[%s%s][%s]]\n"
526 (planner-page-name)
527 (car item)
528 (planner-remove-links (cdr item)))))
529 (save-excursion
530 (find-file muse-publishing-current-file)
531 (planner-notes-get-headlines)))
532 (insert "\n"))
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))))
542 (while files
543 (when (or (null earliest)
544 (not (string-lessp (caar files) earliest)))
545 (let ((title-lines (list t)))
546 (with-temp-buffer
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))
552 (when title-lines
553 (insert (planner-make-link (planner-page-name (caar files)))
554 " ::\n")
555 (planner-insert-markup " <dl class=\"contents\">\n")
556 (while title-lines
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)
567 (save-excursion
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)) "")))
573 (goto-char beg)
574 (planner-insert-markup (muse-markup-text 'planner-begin-note
575 anchor
576 (concat "#" anchor)))
577 (goto-char end)
578 (planner-insert-markup (muse-markup-text 'planner-begin-note-details
579 timestamp)
580 (muse-markup-text 'planner-begin-note-link))
581 (insert link)
582 (planner-insert-markup (muse-markup-text 'planner-end-note-link)
583 (muse-markup-text 'planner-begin-note-categories))
584 (insert categories)
585 (planner-insert-markup (muse-markup-text 'planner-end-note-categories))
586 (insert ?\n)
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)
593 (cond
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")
600 (t "unknown")))
602 (defun planner-publish-task-status-collapse (status)
603 (cond
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")
610 (t "?")))
612 (defun planner-publish-section-close (depth text)
613 "Find where the closing tag of DEPTH should go, and insert TEXT."
614 (let (not-end)
615 (save-excursion
616 (while (and (setq not-end (re-search-forward
617 (concat "^\\*\\{1," (number-to-string depth)
618 "\\}\\s-+")
619 nil t))
620 (get-text-property (match-beginning 0) 'read-only)))
621 (if not-end
622 (forward-line 0)
623 (goto-char (point-max)))
624 (cond ((not (eq (char-before) ?\n))
625 (insert "\n\n"))
626 ((not (eq (char-before (1- (point))) ?\n))
627 (insert "\n")))
628 (insert text)
629 (insert "\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))))
639 (if tagname
640 tagname
641 "nested-section")))
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))
650 (end-of-line)
651 (insert "</title>")
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