org-xoxo.el 3.9 KB

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