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 (paragraph . org-confluence-paragraph
)
51 (property-drawer . org-confluence-property-drawer
)
52 (section . org-confluence-section
)
53 (src-block . org-confluence-src-block
)
54 (strike-through . org-confluence-strike-through
)
55 (table . org-confluence-table
)
56 (table-cell . org-confluence-table-cell
)
57 (table-row . org-confluence-table-row
)
58 (template . org-confluence-template
)
59 (underline . org-confluence-underline
)))
61 (defcustom org-confluence-lang-alist
63 "Map from org-babel language name to confluence wiki language name"
64 :type
'(alist :key-type string
:value-type string
))
66 ;; All the functions we use
67 (defun org-confluence-bold (bold contents info
)
68 (format "*%s*" contents
))
70 (defun org-confluence-empty (empty contents info
)
73 (defun org-confluence-example-block (example-block contents info
)
74 ;; FIXME: provide a user-controlled variable for theme
75 (let ((content (org-export-format-code-default example-block info
)))
76 (org-confluence--block "none" "Confluence" content
)))
78 (defun org-confluence-italic (italic contents info
)
79 (format "_%s_" contents
))
81 (defun org-confluence-item (item contents info
)
82 (concat (make-string (1+ (org-confluence--li-depth item
)) ?\-
)
86 (defun org-confluence-fixed-width (fixed-width contents info
)
87 (format "\{\{%s\}\}" contents
))
89 (defun org-confluence-headline (headline contents info
)
90 (let ((low-level-rank (org-export-low-level-p headline info
))
91 (text (org-export-data (org-element-property :title headline
)
93 (level (org-export-get-relative-level headline info
)))
94 ;; Else: Standard headline.
95 (format "h%s. %s\n%s" level text
96 (if (org-string-nw-p contents
) contents
99 (defun org-confluence-link (link desc info
)
100 (let ((raw-link (org-element-property :raw-link link
)))
102 (when (org-string-nw-p desc
) (format "%s|" desc
))
104 ((string-match "^confluence:" raw-link
)
105 (replace-regexp-in-string "^confluence:" "" raw-link
))
110 (defun org-confluence-paragraph (paragraph contents info
)
111 "Transcode PARAGRAPH element for Confluence.
112 CONTENTS is the paragraph contents. INFO is a plist used as
113 a communication channel."
116 (defun org-confluence-property-drawer (property-drawer contents info
)
117 (and (org-string-nw-p contents
)
118 (format "\{\{%s\}\}" contents
)))
120 (defun org-confluence-section (section contents info
)
123 (defun org-confluence-src-block (src-block contents info
)
124 ;; FIXME: provide a user-controlled variable for theme
125 (let* ((lang (org-element-property :language src-block
))
126 (language (or (cdr (assoc lang org-confluence-lang-alist
)) lang
))
127 (content (org-export-format-code-default src-block info
)))
128 (org-confluence--block language
"Emacs" content
)))
130 (defun org-confluence-strike-through (strike-through contents info
)
131 (format "-%s-" contents
))
133 (defun org-confluence-table (table contents info
)
136 (defun org-confluence-table-row (table-row contents info
)
138 (if (org-string-nw-p contents
) (format "|%s" contents
)
140 (when (org-export-table-row-ends-header-p table-row info
)
143 (defun org-confluence-table-cell (table-cell contents info
)
144 (let ((table-row (org-export-get-parent table-cell
)))
146 (when (org-export-table-row-starts-header-p table-row info
)
150 (defun org-confluence-template (contents info
)
151 (let ((depth (plist-get info
:with-toc
)))
152 (concat (when depth
"\{toc\}\n\n") contents
)))
154 (defun org-confluence-underline (underline contents info
)
155 (format "+%s+" contents
))
157 (defun org-confluence--block (language theme contents
)
158 (concat "\{code:theme=" theme
159 (when language
(format "|language=%s" language
))
164 (defun org-confluence--li-depth (item)
165 "Return depth of a list item; -1 means not a list item"
166 ;; FIXME check whether it's worth it to cache depth
167 ;; (it gets recalculated quite a few times while
168 ;; traversing a list)
172 (setq tag
(car item
))
173 (or (eq tag
'item
) ; list items interleave with plain-list
174 (eq tag
'plain-list
)))
177 (setq item
(org-export-get-parent item
)))
180 ;; main interactive entrypoint
181 (defun org-confluence-export-as-confluence
182 (&optional async subtreep visible-only body-only ext-plist
)
183 "Export current buffer to a text buffer.
185 If narrowing is active in the current buffer, only export its
188 If a region is active, export that region.
190 A non-nil optional argument ASYNC means the process should happen
191 asynchronously. The resulting buffer should be accessible
192 through the `org-export-stack' interface.
194 When optional argument SUBTREEP is non-nil, export the sub-tree
195 at point, extracting information from the headline properties
198 When optional argument VISIBLE-ONLY is non-nil, don't export
199 contents of hidden elements.
201 When optional argument BODY-ONLY is non-nil, strip title, table
202 of contents and footnote definitions from output.
204 EXT-PLIST, when provided, is a property list with external
205 parameters overriding Org default settings, but still inferior to
208 Export is done in a buffer named \"*Org CONFLUENCE Export*\", which
209 will be displayed when `org-export-show-temporary-export-buffer'
212 (org-export-to-buffer 'confluence
"*org CONFLUENCE Export*"
213 async subtreep visible-only body-only ext-plist
(lambda () (text-mode))))
215 (provide 'ox-confluence
)