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 at gmx dot net>
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 (link . org-confluence-link
)
49 (section . org-confluence-section
)
50 (src-block . org-confluence-src-block
)
51 (strike-through . org-confluence-strike-through
)
52 (table . org-confluence-table
)
53 (table-cell . org-confluence-table-cell
)
54 (table-row . org-confluence-table-row
)
55 (template . org-confluence-template
)
56 (underline . org-confluence-underline
)))
58 ;; All the functions we use
59 (defun org-confluence-bold (bold contents info
)
60 (format "*%s*" contents
))
62 (defun org-confluence-empty (empty contents info
)
65 (defun org-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-confluence--block "none" "Confluence" content
)))
70 (defun org-confluence-italic (italic contents info
)
71 (format "_%s_" contents
))
73 (defun org-confluence-fixed-width (fixed-width contents info
)
74 (format "\{\{%s\}\}" contents
))
76 (defun org-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-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-confluence-section (section contents info
)
99 (defun org-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-confluence--block language
"Emacs" content
)))
107 (defun org-confluence-strike-through (strike-through contents info
)
108 (format "-%s-" contents
))
110 (defun org-confluence-table (table contents info
)
113 (defun org-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-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-confluence-template (contents info
)
128 (let ((depth (plist-get info
:with-toc
)))
129 (concat (when depth
"\{toc\}\n\n") contents
)))
131 (defun org-confluence-underline (underline contents info
)
132 (format "+%s+" contents
))
134 (defun org-confluence--block (language theme contents
)
135 (concat "\{code:theme=" theme
136 (when language
(format "|language=%s" language
))
141 ;; main interactive entrypoint
142 (defun org-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 CONFLUENCE Export*\", which
170 will be displayed when `org-export-show-temporary-export-buffer'
173 (org-export-to-buffer 'confluence
"*org CONFLUENCE Export*"
174 async subtreep visible-only body-only ext-plist
(lambda () (text-mode))))
176 (provide 'ox-confluence
)