Commit | Line | Data |
---|---|---|
c8d0cf5c CD |
1 | ;;; org-xoxo.el --- XOXO export for Org-mode |
2 | ||
5df4f04c | 3 | ;; Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 |
c8d0cf5c CD |
4 | ;; Free Software Foundation, Inc. |
5 | ||
6 | ;; Author: Carsten Dominik <carsten at orgmode dot org> | |
7 | ;; Keywords: outlines, hypermedia, calendar, wp | |
8 | ;; Homepage: http://orgmode.org | |
acedf35c | 9 | ;; Version: 7.4 |
c8d0cf5c CD |
10 | ;; |
11 | ;; This file is part of GNU Emacs. | |
12 | ;; | |
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. | |
17 | ||
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. | |
22 | ||
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 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
26 | ;; | |
27 | ;;; Commentary: | |
86fbb8ca | 28 | ;; XOXO export |
c8d0cf5c | 29 | |
86fbb8ca | 30 | ;;; Code: |
c8d0cf5c | 31 | |
86fbb8ca | 32 | (require 'org-exp) |
c8d0cf5c | 33 | |
8d642074 CD |
34 | (defvar org-export-xoxo-final-hook nil |
35 | "Hook run after XOXO export, in the new buffer.") | |
36 | ||
c8d0cf5c CD |
37 | (defun org-export-as-xoxo-insert-into (buffer &rest output) |
38 | (with-current-buffer buffer | |
39 | (apply 'insert output))) | |
40 | (put 'org-export-as-xoxo-insert-into 'lisp-indent-function 1) | |
41 | ||
42 | ;;;###autoload | |
43 | (defun org-export-as-xoxo (&optional buffer) | |
44 | "Export the org buffer as XOXO. | |
45 | The XOXO buffer is named *xoxo-<source buffer name>*" | |
46 | (interactive (list (current-buffer))) | |
ed21c5c8 | 47 | (run-hooks 'org-export-first-hook) |
c8d0cf5c CD |
48 | ;; A quickie abstraction |
49 | ||
50 | ;; Output everything as XOXO | |
51 | (with-current-buffer (get-buffer buffer) | |
52 | (let* ((pos (point)) | |
53 | (opt-plist (org-combine-plists (org-default-export-plist) | |
54 | (org-infile-export-plist))) | |
55 | (filename (concat (file-name-as-directory | |
56 | (org-export-directory :xoxo opt-plist)) | |
57 | (file-name-sans-extension | |
58 | (file-name-nondirectory buffer-file-name)) | |
59 | ".html")) | |
60 | (out (find-file-noselect filename)) | |
61 | (last-level 1) | |
62 | (hanging-li nil)) | |
63 | (goto-char (point-min)) ;; CD: beginning-of-buffer is not allowed. | |
64 | ;; Check the output buffer is empty. | |
65 | (with-current-buffer out (erase-buffer)) | |
66 | ;; Kick off the output | |
67 | (org-export-as-xoxo-insert-into out "<ol class='xoxo'>\n") | |
68 | (while (re-search-forward "^\\(\\*+\\)[ \t]+\\(.+\\)" (point-max) 't) | |
69 | (let* ((hd (match-string-no-properties 1)) | |
70 | (level (length hd)) | |
71 | (text (concat | |
72 | (match-string-no-properties 2) | |
73 | (save-excursion | |
74 | (goto-char (match-end 0)) | |
75 | (let ((str "")) | |
76 | (catch 'loop | |
77 | (while 't | |
78 | (forward-line) | |
79 | (if (looking-at "^[ \t]\\(.*\\)") | |
80 | (setq str (concat str (match-string-no-properties 1))) | |
81 | (throw 'loop str))))))))) | |
82 | ||
83 | ;; Handle level rendering | |
84 | (cond | |
85 | ((> level last-level) | |
86 | (org-export-as-xoxo-insert-into out "\n<ol>\n")) | |
87 | ||
88 | ((< level last-level) | |
89 | (dotimes (- (- last-level level) 1) | |
90 | (if hanging-li | |
91 | (org-export-as-xoxo-insert-into out "</li>\n")) | |
92 | (org-export-as-xoxo-insert-into out "</ol>\n")) | |
93 | (when hanging-li | |
94 | (org-export-as-xoxo-insert-into out "</li>\n") | |
95 | (setq hanging-li nil))) | |
96 | ||
97 | ((equal level last-level) | |
98 | (if hanging-li | |
99 | (org-export-as-xoxo-insert-into out "</li>\n"))) | |
100 | ) | |
101 | ||
102 | (setq last-level level) | |
103 | ||
104 | ;; And output the new li | |
105 | (setq hanging-li 't) | |
106 | (if (equal ?+ (elt text 0)) | |
107 | (org-export-as-xoxo-insert-into out "<li class='" (substring text 1) "'>") | |
108 | (org-export-as-xoxo-insert-into out "<li>" text)))) | |
109 | ||
110 | ;; Finally finish off the ol | |
111 | (dotimes (- last-level 1) | |
112 | (if hanging-li | |
113 | (org-export-as-xoxo-insert-into out "</li>\n")) | |
114 | (org-export-as-xoxo-insert-into out "</ol>\n")) | |
115 | ||
116 | (goto-char pos) | |
117 | ;; Finish the buffer off and clean it up. | |
118 | (switch-to-buffer-other-window out) | |
119 | (indent-region (point-min) (point-max) nil) | |
8d642074 | 120 | (run-hooks 'org-export-xoxo-final-hook) |
c8d0cf5c CD |
121 | (save-buffer) |
122 | (goto-char (point-min)) | |
123 | ))) | |
124 | ||
125 | (provide 'org-xoxo) | |
126 | ||
127 | ;; arch-tag: 16e6a31f-f4f5-46f1-af18-48dc89faa702 | |
c8d0cf5c | 128 | ;;; org-xoxo.el ends here |