1 ;;; ox-confluence --- Confluence Wiki Back-End for Org Export Engine
3 ;; Copyright (C) 2012, 2014 Sébastien Delafond
5 ;; Author: Sébastien Delafond <sdelafond@gmail.com>
6 ;; Keywords: outlines, confluence, wiki
8 ;; This file is not part of GNU Emacs.
10 ;; This program 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 ;; This program 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 ;; ox-confluence.el lets you convert Org files to confluence files
26 ;; using the ox.el export engine.
28 ;; Put this file into your load-path and the following into your ~/.emacs:
29 ;; (require 'ox-confluence)
31 ;; Export Org files to confluence:
32 ;; M-x org-confluence-export-as-confluence RET
39 ;; Define the backend itself
40 (org-export-define-derived-backend 'confluence
'ascii
41 :translate-alist
'((bold . org-confluence-bold
)
42 (example-block . org-confluence-example-block
)
43 (fixed-width . org-confluence-fixed-width
)
44 (footnote-definition . org-confluence-empty
)
45 (footnote-reference . org-confluence-empty
)
46 (headline . org-confluence-headline
)
47 (italic . org-confluence-italic
)
48 (item . org-confluence-item
)
49 (link . org-confluence-link
)
50 (property-drawer . org-confluence-property-drawer
)
51 (section . org-confluence-section
)
52 (src-block . org-confluence-src-block
)
53 (strike-through . org-confluence-strike-through
)
54 (table . org-confluence-table
)
55 (table-cell . org-confluence-table-cell
)
56 (table-row . org-confluence-table-row
)
57 (template . org-confluence-template
)
58 (underline . org-confluence-underline
)))
60 ;; All the functions we use
61 (defun org-confluence-bold (bold contents info
)
62 (format "*%s*" contents
))
64 (defun org-confluence-empty (empty contents info
)
67 (defun org-confluence-example-block (example-block contents info
)
68 ;; FIXME: provide a user-controlled variable for theme
69 (let ((content (org-export-format-code-default example-block info
)))
70 (org-confluence--block "none" "Confluence" content
)))
72 (defun org-confluence-italic (italic contents info
)
73 (format "_%s_" contents
))
75 (defun org-confluence-item (item contents info
)
76 (concat (make-string (1+ (org-confluence--li-depth item
)) ?\-
)
80 (defun org-confluence-fixed-width (fixed-width contents info
)
81 (format "\{\{%s\}\}" contents
))
83 (defun org-confluence-headline (headline contents info
)
84 (let ((low-level-rank (org-export-low-level-p headline info
))
85 (text (org-export-data (org-element-property :title headline
)
87 (level (org-export-get-relative-level headline info
)))
88 ;; Else: Standard headline.
89 (format "h%s. %s\n%s" level text
90 (if (org-string-nw-p contents
) contents
93 (defun org-confluence-link (link desc info
)
94 (let ((raw-link (org-element-property :raw-link link
)))
96 (when (org-string-nw-p desc
) (format "%s|" desc
))
98 ((string-match "^confluence:" raw-link
)
99 (replace-regexp-in-string "^confluence:" "" raw-link
))
104 (defun org-confluence-property-drawer (property-drawer contents info
)
105 (and (org-string-nw-p contents
)
106 (format "\{\{%s\}\}" contents
)))
108 (defun org-confluence-section (section contents info
)
111 (defun org-confluence-src-block (src-block contents info
)
112 ;; FIXME: provide a user-controlled variable for theme
113 (let* ((lang (org-element-property :language src-block
))
114 (language (if (string= lang
"sh") "bash" ;; FIXME: provide a mapping of some sort
116 (content (org-export-format-code-default src-block info
)))
117 (org-confluence--block language
"Emacs" content
)))
119 (defun org-confluence-strike-through (strike-through contents info
)
120 (format "-%s-" contents
))
122 (defun org-confluence-table (table contents info
)
125 (defun org-confluence-table-row (table-row contents info
)
127 (if (org-string-nw-p contents
) (format "|%s" contents
)
129 (when (org-export-table-row-ends-header-p table-row info
)
132 (defun org-confluence-table-cell (table-cell contents info
)
133 (let ((table-row (org-export-get-parent table-cell
)))
135 (when (org-export-table-row-starts-header-p table-row info
)
139 (defun org-confluence-template (contents info
)
140 (let ((depth (plist-get info
:with-toc
)))
141 (concat (when depth
"\{toc\}\n\n") contents
)))
143 (defun org-confluence-underline (underline contents info
)
144 (format "+%s+" contents
))
146 (defun org-confluence--block (language theme contents
)
147 (concat "\{code:theme=" theme
148 (when language
(format "|language=%s" language
))
153 (defun org-confluence--li-depth (item)
154 "Return depth of a list item; -1 means not a list item"
155 ;; FIXME check whether it's worth it to cache depth
156 ;; (it gets recalculated quite a few times while
157 ;; traversing a list)
161 (setq tag
(car item
))
162 (or (eq tag
'item
) ; list items interleave with plain-list
163 (eq tag
'plain-list
)))
166 (setq item
(org-export-get-parent item
)))
169 ;; main interactive entrypoint
170 (defun org-confluence-export-as-confluence
171 (&optional async subtreep visible-only body-only ext-plist
)
172 "Export current buffer to a text buffer.
174 If narrowing is active in the current buffer, only export its
177 If a region is active, export that region.
179 A non-nil optional argument ASYNC means the process should happen
180 asynchronously. The resulting buffer should be accessible
181 through the `org-export-stack' interface.
183 When optional argument SUBTREEP is non-nil, export the sub-tree
184 at point, extracting information from the headline properties
187 When optional argument VISIBLE-ONLY is non-nil, don't export
188 contents of hidden elements.
190 When optional argument BODY-ONLY is non-nil, strip title, table
191 of contents and footnote definitions from output.
193 EXT-PLIST, when provided, is a property list with external
194 parameters overriding Org default settings, but still inferior to
197 Export is done in a buffer named \"*Org CONFLUENCE Export*\", which
198 will be displayed when `org-export-show-temporary-export-buffer'
201 (org-export-to-buffer 'confluence
"*org CONFLUENCE Export*"
202 async subtreep visible-only body-only ext-plist
(lambda () (text-mode))))
204 (provide 'ox-confluence
)