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