org-e-freemind.el 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298
  1. ;;; org-e-odt.el --- OpenDocument Text exporter for Org-mode
  2. ;; Copyright (C) 2010-2012 Free Software Foundation, Inc.
  3. ;; Author: Jambunathan K <kjambunathan at gmail dot com>
  4. ;; Keywords: outlines, hypermedia, calendar, wp
  5. ;; Homepage: http://orgmode.org
  6. ;; This file is not part of GNU Emacs.
  7. ;; GNU Emacs is free software: you can redistribute it and/or modify
  8. ;; it under the terms of the GNU General Public License as published by
  9. ;; the Free Software Foundation, either version 3 of the License, or
  10. ;; (at your option) any later version.
  11. ;; GNU Emacs is distributed in the hope that it will be useful,
  12. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. ;; GNU General Public License for more details.
  15. ;; You should have received a copy of the GNU General Public License
  16. ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
  17. ;;; Commentary:
  18. ;;; Code:
  19. ;;; Define Back-End
  20. (require 'org-e-html)
  21. (setq org-e-freemind-toplevel-hlevel 1)
  22. (defcustom org-e-freemind-node-styles
  23. '((0 . (:node-attrs
  24. "COLOR=\"#000000\""
  25. :node-elements
  26. "<font NAME=\"SansSerif\" SIZE=\"20\"/>"))
  27. (1 . (:node-attrs
  28. "COLOR=\"#0033ff\""
  29. :node-elements
  30. "<edge STYLE=\"sharp_bezier\" WIDTH=\"8\"/>
  31. <font NAME=\"SansSerif\" SIZE=\"18\"/>"))
  32. (2 . (:node-attrs
  33. "COLOR=\"#00b439\""
  34. :node-elements
  35. "<edge STYLE=\"bezier\" WIDTH=\"thin\"/>
  36. <font NAME=\"SansSerif\" SIZE=\"16\"/>"))
  37. (3 . (:node-attrs
  38. "COLOR=\"#990000\""
  39. :node-elements
  40. "<font NAME=\"SansSerif\" SIZE=\"14\"/>"))
  41. (default . (:node-attrs
  42. "COLOR=\"#111111\""
  43. :node-elements
  44. nil)))
  45. "Styles to apply to node.
  46. NOT READY YET."
  47. :type '(alist :options (0 1 2 3 default)
  48. :key-type (choice :tag "Node selector"
  49. (integer :tag "Outline level")
  50. (const :tag "Default value" default)
  51. (string :tag "Node style"))
  52. :value-type (plist :options (:node-attrs :node-elements)
  53. :value-type
  54. (choice
  55. (string :tag "Value")
  56. (const :tag "None" nil))))
  57. :group 'org-freemind)
  58. (org-export-define-derived-backend e-freemind e-html
  59. :export-block "FREEMIND"
  60. :options-alist nil
  61. :translate-alist ((headline . org-e-freemind-headline)
  62. (template . org-e-freemind-template)
  63. (section . org-e-freemind-section)))
  64. ;;; Transcoders
  65. ;;;; Template
  66. (defun org-e-freemind-template (contents info)
  67. "Return complete document string after HTML conversion.
  68. CONTENTS is the transcoded contents string. RAW-DATA is the
  69. original parsed data. INFO is a plist holding export options."
  70. (format
  71. "<map version=\"0.9.0\">\n%s\n</map>"
  72. (format
  73. "<node COLOR=\"#407000\" STYLE=\"fork\" POSITION=\"%s\" TEXT=\"%s\">%s</node>"
  74. (if t "left" "right")
  75. (org-export-data (plist-get info :title) info)
  76. (concat
  77. contents
  78. "\n<edge COLOR=\"#808080\" STYLE=\"bezier\" WIDTH=\"thin\"/>\n<font NAME=\"SansSerif\" SIZE=\"12\"/>
  79. "))))
  80. ;;;; Headline
  81. (defun org-e-freemind-format-headline (todo todo-type priority text tags)
  82. (let ((todo (org-e-html--todo todo))
  83. (tags (org-e-html--tags tags)))
  84. (concat todo (and todo " ") text
  85. (and tags "&nbsp;&nbsp;&nbsp;") tags)))
  86. (defun org-e-freemind-headline (headline contents info)
  87. "Transcode an HEADLINE element from Org to HTML.
  88. CONTENTS holds the contents of the headline. INFO is a plist
  89. holding contextual information."
  90. ;; Empty contents?
  91. (setq contents (or contents ""))
  92. (let* ((numberedp (org-export-numbered-headline-p headline info))
  93. (level (org-export-get-relative-level headline info))
  94. (text (org-export-data (org-element-property :title headline) info))
  95. (todo (and (plist-get info :with-todo-keywords)
  96. (let ((todo (org-element-property :todo-keyword headline)))
  97. (and todo (org-export-data todo info)))))
  98. (todo-type (and todo (org-element-property :todo-type headline)))
  99. (tags (and (plist-get info :with-tags)
  100. (org-export-get-tags headline info)))
  101. (priority (and (plist-get info :with-priority)
  102. (org-element-property :priority headline)))
  103. (section-number (and (org-export-numbered-headline-p headline info)
  104. (mapconcat 'number-to-string
  105. (org-export-get-headline-number
  106. headline info) ".")))
  107. ;; Create the headline text.
  108. (full-text (org-e-html-format-headline--wrap headline info))
  109. ;; Headline order.
  110. (headline-order
  111. ;; (car (last (org-export-get-headline-number headline info)))
  112. (car (org-export-get-headline-number headline info)))
  113. (left-p (zerop (% headline-order 2))))
  114. (cond
  115. ;; Case 1: This is a footnote section: ignore it.
  116. ((org-element-property :footnote-section-p headline) nil)
  117. ;; Case 2. This is a deep sub-tree: export it as a list item.
  118. ;; Also export as items headlines for which no section
  119. ;; format has been found.
  120. ((org-export-low-level-p headline info) ; FIXME (or (not section-fmt))
  121. ;; Build the real contents of the sub-tree.
  122. (let* ((type (if numberedp 'unordered 'unordered)) ; FIXME
  123. (itemized-body (org-e-freemind-format-list-item
  124. contents type nil nil full-text)))
  125. (concat
  126. (and (org-export-first-sibling-p headline info)
  127. (org-e-freemind-begin-plain-list type))
  128. itemized-body
  129. (and (org-export-last-sibling-p headline info)
  130. (org-e-freemind-end-plain-list type)))))
  131. ;; Case 3. Standard headline. Export it as a section.
  132. (t
  133. (let* ((section-number (mapconcat 'number-to-string
  134. (org-export-get-headline-number
  135. headline info) "-"))
  136. (ids (remove 'nil
  137. (list (org-element-property :custom-id headline)
  138. (concat "sec-" section-number)
  139. (org-element-property :id headline))))
  140. (preferred-id (car ids))
  141. (extra-ids (cdr ids))
  142. (extra-class (org-element-property :html-container-class headline))
  143. (level1 level))
  144. (concat
  145. (format "<node %s STYLE=\"bubble\" POSITION=\"%s\" FOLDED=\"%s\" TEXT=\"%s\">%s</node>"
  146. (or (plist-get (assoc-default level org-e-freemind-node-styles)
  147. :node-attrs)
  148. (plist-get (assoc-default 'default org-e-freemind-node-styles)
  149. :node-attrs)
  150. "")
  151. (if left-p "left" "right")
  152. (if (= level 1) "true" "false")
  153. full-text
  154. (concat
  155. contents
  156. (or
  157. (plist-get (assoc-default level org-e-freemind-node-styles)
  158. :node-elements)
  159. (plist-get (assoc-default 'default org-e-freemind-node-styles)
  160. :node-elements)
  161. ""))))
  162. ;; (format "<div id=\"%s\" class=\"%s\">%s%s</div>\n"
  163. ;; (format "outline-container-%s"
  164. ;; (or (org-element-property :custom-id headline)
  165. ;; section-number))
  166. ;; (concat (format "outline-%d" level1) (and extra-class " ")
  167. ;; extra-class)
  168. ;; (format "\n<h%d id=\"%s\">%s%s</h%d>\n"
  169. ;; level1
  170. ;; preferred-id
  171. ;; (mapconcat
  172. ;; (lambda (x)
  173. ;; (let ((id (org-export-solidify-link-text
  174. ;; (if (org-uuidgen-p x) (concat "ID-" x)
  175. ;; x))))
  176. ;; (org-e-freemind--anchor id)))
  177. ;; extra-ids "")
  178. ;; full-text
  179. ;; level1)
  180. ;; contents)
  181. )))))
  182. (defun org-e-freemind-section (section contents info)
  183. "Transcode a SECTION element from Org to HTML.
  184. CONTENTS holds the contents of the section. INFO is a plist
  185. holding contextual information."
  186. (let ( ;; (type "NOTE")
  187. (type "NODE"))
  188. (if (string= (org-trim contents) "") ""
  189. (format "<node style=\"bubble\" background_color=\"#eeee00\">%s</node>"
  190. (format "\n<richcontent TYPE=\"%s\">\n%s\n</richcontent>"
  191. type
  192. (format "\n<html>\n<head>\n</head>\n%s\n</html>"
  193. (format "<body>\n%s\n</body>"
  194. contents)))))))
  195. ;;; Interactive functions
  196. ;;;###autoload
  197. (defun org-e-freemind-export-as-freemind
  198. (&optional subtreep visible-only body-only ext-plist)
  199. "Export current buffer to an HTML buffer.
  200. If narrowing is active in the current buffer, only export its
  201. narrowed part.
  202. If a region is active, export that region.
  203. When optional argument SUBTREEP is non-nil, export the sub-tree
  204. at point, extracting information from the headline properties
  205. first.
  206. When optional argument VISIBLE-ONLY is non-nil, don't export
  207. contents of hidden elements.
  208. When optional argument BODY-ONLY is non-nil, only write code
  209. between \"<body>\" and \"</body>\" tags.
  210. EXT-PLIST, when provided, is a property list with external
  211. parameters overriding Org default settings, but still inferior to
  212. file-local settings.
  213. Export is done in a buffer named \"*Org E-FREEMIND Export*\", which
  214. will be displayed when `org-export-show-temporary-export-buffer'
  215. is non-nil."
  216. (interactive)
  217. (let ((outbuf
  218. (org-export-to-buffer
  219. 'e-freemind "*Org E-FREEMIND Export*"
  220. subtreep visible-only body-only ext-plist)))
  221. ;; Set major mode.
  222. (with-current-buffer outbuf (nxml-mode))
  223. (when org-export-show-temporary-export-buffer
  224. (switch-to-buffer-other-window outbuf))))
  225. ;;;###autoload
  226. (defun org-e-freemind-export-to-freemind
  227. (&optional subtreep visible-only body-only ext-plist pub-dir)
  228. "Export current buffer to a HTML file.
  229. If narrowing is active in the current buffer, only export its
  230. narrowed part.
  231. If a region is active, export that region.
  232. When optional argument SUBTREEP is non-nil, export the sub-tree
  233. at point, extracting information from the headline properties
  234. first.
  235. When optional argument VISIBLE-ONLY is non-nil, don't export
  236. contents of hidden elements.
  237. When optional argument BODY-ONLY is non-nil, only write code
  238. between \"<body>\" and \"</body>\" tags.
  239. EXT-PLIST, when provided, is a property list with external
  240. parameters overriding Org default settings, but still inferior to
  241. file-local settings.
  242. When optional argument PUB-DIR is set, use it as the publishing
  243. directory.
  244. Return output file's name."
  245. (interactive)
  246. (let* ((extension ".mm")
  247. (file (org-export-output-file-name extension subtreep pub-dir))
  248. (org-export-coding-system 'utf-8))
  249. (org-export-to-file
  250. 'e-freemind file subtreep visible-only body-only ext-plist)))
  251. (provide 'org-e-freemind.el)