1 ;;; org-e-confluence --- Confluence Wiki Back-End for Org Export Engine
3 ;; Copyright (C) 2012 Sébastien Delafond
5 ;; Author: Sébastien Delafond <sdelafond at gmx dot net>
6 ;; Keywords: outlines, confluence, wiki
8 ;; This file is not part of GNU Emacs.
10 ;; GNU Emacs is free software: you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation, either version 3 of the License, or
13 ;; (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.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
25 ;; org-confluence.el lets you convert Org files to confluence files using
26 ;; the org-export.el experimental engine.
28 ;; Put this file into your load-path and the following into your ~/.emacs:
29 ;; (require 'org-confluence)
31 ;; Export Org files to confluence:
32 ;; M-x org-e-confluence-export-as-confluence RET
37 (require 'org-e-ascii
)
39 ;; Define the backend itself
40 (org-export-define-derived-backend e-confluence e-ascii
41 :translate-alist
((bold . org-e-confluence-bold
)
42 (example-block . org-e-confluence-example-block
)
43 (fixed-width . org-e-confluence-fixed-width
)
44 (footnote-definition . org-e-confluence-empty
)
45 (footnote-reference . org-e-confluence-empty
)
46 (headline . org-e-confluence-headline
)
47 (italic . org-e-confluence-italic
)
48 (link . org-e-confluence-link
)
49 (section . org-e-confluence-section
)
50 (src-block . org-e-confluence-src-block
)
51 (strike-through . org-e-confluence-strike-through
)
52 (table . org-e-confluence-table
)
53 (table-cell . org-e-confluence-table-cell
)
54 (table-row . org-e-confluence-table-row
)
55 (template . org-e-confluence-template
)
56 (underline . org-e-confluence-underline
)))
58 ;; All the functions we use
59 (defun org-e-confluence-bold (bold contents info
)
60 (format "*%s*" contents
))
62 (defun org-e-confluence-empty (empy contents info
)
65 (defun org-e-confluence-example-block (example-block contents info
)
66 ;; FIXME: provide a user-controlled variable for theme
67 (let ((content (org-export-format-code-default example-block info
)))
68 (org-e-confluence--block "none" "Confluence" content
)))
70 (defun org-e-confluence-italic (italic contents info
)
71 (format "_%s_" contents
))
73 (defun org-e-confluence-fixed-width (fixed-width contents info
)
74 (format "\{\{%s\}\}" contents
))
76 (defun org-e-confluence-headline (headline contents info
)
77 (let ((low-level-rank (org-export-low-level-p headline info
))
78 (text (org-export-data (org-element-property :title headline
)
80 (level (org-export-get-relative-level headline info
)))
81 ;; Else: Standard headline.
82 (format "h%s. %s\n%s" level text
83 (if (org-string-nw-p contents
) contents
86 (defun org-e-confluence-link (link desc info
)
87 (let ((raw-link (org-element-property :raw-link link
)))
89 (when (org-string-nw-p desc
) (format "%s|" desc
))
91 ((string-match "^confluence:" raw-link
)
92 (replace-regexp-in-string "^confluence:" "" raw-link
))
96 (defun org-e-confluence-section (section contents info
)
99 (defun org-e-confluence-src-block (src-block contents info
)
100 ;; FIXME: provide a user-controlled variable for theme
101 (let* ((lang (org-element-property :language src-block
))
102 (language (if (string= lang
"sh") "bash" ;; FIXME: provide a mapping of some sort
104 (content (org-export-format-code-default src-block info
)))
105 (org-e-confluence--block language
"Emacs" content
)))
107 (defun org-e-confluence-strike-through (strike-through contents info
)
108 (format "-%s-" contents
))
110 (defun org-e-confluence-table (table contents info
)
113 (defun org-e-confluence-table-row (table-row contents info
)
115 (if (org-string-nw-p contents
) (format "|%s" contents
)
117 (when (org-export-table-row-ends-header-p table-row info
)
120 (defun org-e-confluence-table-cell (table-cell contents info
)
121 (let ((table-row (org-export-get-parent table-cell
)))
123 (when (org-export-table-row-starts-header-p table-row info
)
127 (defun org-e-confluence-template (contents info
)
128 (let ((depth (plist-get info
:with-toc
)))
129 (concat (when depth
"\{toc\}\n\n") contents
)))
131 (defun org-e-confluence-underline (underline contents info
)
132 (format "+%s+" contents
))
134 (defun org-e-confluence--block (language theme contents
)
135 (concat "\{code:theme=" theme
136 (when language
(format "|language=%s" language
))
141 ;; main interactive entrypoint
142 (defun org-e-confluence-export-as-confluence
143 (&optional async subtreep visible-only body-only ext-plist
)
144 "Export current buffer to a text buffer.
146 If narrowing is active in the current buffer, only export its
149 If a region is active, export that region.
151 A non-nil optional argument ASYNC means the process should happen
152 asynchronously. The resulting buffer should be accessible
153 through the `org-export-stack' interface.
155 When optional argument SUBTREEP is non-nil, export the sub-tree
156 at point, extracting information from the headline properties
159 When optional argument VISIBLE-ONLY is non-nil, don't export
160 contents of hidden elements.
162 When optional argument BODY-ONLY is non-nil, strip title, table
163 of contents and footnote definitions from output.
165 EXT-PLIST, when provided, is a property list with external
166 parameters overriding Org default settings, but still inferior to
169 Export is done in a buffer named \"*Org E-Confluence Export*\", which
170 will be displayed when `org-export-show-temporary-export-buffer'
174 (org-export-async-start
176 (with-current-buffer (get-buffer-create "*Org E-Confluence Export*")
179 (goto-char (point-min))
181 (org-export-add-to-stack (current-buffer) 'e-confluence
)))
182 `(org-export-as 'e-confluence
,subtreep
,visible-only
,body-only
184 (let ((outbuf (org-export-to-buffer
185 'e-confluence
"*Org E-Confluence Export*"
186 subtreep visible-only body-only ext-plist
)))
187 (with-current-buffer outbuf
(text-mode))
188 (when org-export-show-temporary-export-buffer
189 (switch-to-buffer-other-window outbuf
)))))
191 (provide 'org-e-confluence
)