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