Release 6.30d
[org-mode.git] / lisp / org-xoxo.el
bloba7e90bade6a970aec57063f055107c0faef8e62f
1 ;;; org-xoxo.el --- XOXO export for Org-mode
3 ;; Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009
4 ;; Free Software Foundation, Inc.
6 ;; Author: Carsten Dominik <carsten at orgmode dot org>
7 ;; Keywords: outlines, hypermedia, calendar, wp
8 ;; Homepage: http://orgmode.org
9 ;; Version: 6.30d
11 ;; This file is part of GNU Emacs.
13 ;; GNU Emacs is free software: you can redistribute it and/or modify
14 ;; it under the terms of the GNU General Public License as published by
15 ;; the Free Software Foundation, either version 3 of the License, or
16 ;; (at your option) any later version.
18 ;; GNU Emacs is distributed in the hope that it will be useful,
19 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 ;; GNU General Public License for more details.
23 ;; You should have received a copy of the GNU General Public License
24 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
25 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
27 ;;; Commentary:
29 (require 'org-exp)
31 ;;; XOXO export
33 (defun org-export-as-xoxo-insert-into (buffer &rest output)
34 (with-current-buffer buffer
35 (apply 'insert output)))
36 (put 'org-export-as-xoxo-insert-into 'lisp-indent-function 1)
38 ;;;###autoload
39 (defun org-export-as-xoxo (&optional buffer)
40 "Export the org buffer as XOXO.
41 The XOXO buffer is named *xoxo-<source buffer name>*"
42 (interactive (list (current-buffer)))
43 ;; A quickie abstraction
45 ;; Output everything as XOXO
46 (with-current-buffer (get-buffer buffer)
47 (let* ((pos (point))
48 (opt-plist (org-combine-plists (org-default-export-plist)
49 (org-infile-export-plist)))
50 (filename (concat (file-name-as-directory
51 (org-export-directory :xoxo opt-plist))
52 (file-name-sans-extension
53 (file-name-nondirectory buffer-file-name))
54 ".html"))
55 (out (find-file-noselect filename))
56 (last-level 1)
57 (hanging-li nil))
58 (goto-char (point-min)) ;; CD: beginning-of-buffer is not allowed.
59 ;; Check the output buffer is empty.
60 (with-current-buffer out (erase-buffer))
61 ;; Kick off the output
62 (org-export-as-xoxo-insert-into out "<ol class='xoxo'>\n")
63 (while (re-search-forward "^\\(\\*+\\)[ \t]+\\(.+\\)" (point-max) 't)
64 (let* ((hd (match-string-no-properties 1))
65 (level (length hd))
66 (text (concat
67 (match-string-no-properties 2)
68 (save-excursion
69 (goto-char (match-end 0))
70 (let ((str ""))
71 (catch 'loop
72 (while 't
73 (forward-line)
74 (if (looking-at "^[ \t]\\(.*\\)")
75 (setq str (concat str (match-string-no-properties 1)))
76 (throw 'loop str)))))))))
78 ;; Handle level rendering
79 (cond
80 ((> level last-level)
81 (org-export-as-xoxo-insert-into out "\n<ol>\n"))
83 ((< level last-level)
84 (dotimes (- (- last-level level) 1)
85 (if hanging-li
86 (org-export-as-xoxo-insert-into out "</li>\n"))
87 (org-export-as-xoxo-insert-into out "</ol>\n"))
88 (when hanging-li
89 (org-export-as-xoxo-insert-into out "</li>\n")
90 (setq hanging-li nil)))
92 ((equal level last-level)
93 (if hanging-li
94 (org-export-as-xoxo-insert-into out "</li>\n")))
97 (setq last-level level)
99 ;; And output the new li
100 (setq hanging-li 't)
101 (if (equal ?+ (elt text 0))
102 (org-export-as-xoxo-insert-into out "<li class='" (substring text 1) "'>")
103 (org-export-as-xoxo-insert-into out "<li>" text))))
105 ;; Finally finish off the ol
106 (dotimes (- last-level 1)
107 (if hanging-li
108 (org-export-as-xoxo-insert-into out "</li>\n"))
109 (org-export-as-xoxo-insert-into out "</ol>\n"))
111 (goto-char pos)
112 ;; Finish the buffer off and clean it up.
113 (switch-to-buffer-other-window out)
114 (indent-region (point-min) (point-max) nil)
115 (save-buffer)
116 (goto-char (point-min))
119 (provide 'org-xoxo)
121 ;; arch-tag: 16e6a31f-f4f5-46f1-af18-48dc89faa702
122 ;;; org-xoxo.el ends here