2013-01-27 17:11:34 -05:00
|
|
|
;;; ox-confluence --- Confluence Wiki Back-End for Org Export Engine
|
2012-12-15 01:36:05 -05:00
|
|
|
|
|
|
|
;; Copyright (C) 2012 Sébastien Delafond
|
|
|
|
|
|
|
|
;; Author: Sébastien Delafond <sdelafond at gmx dot net>
|
|
|
|
;; Keywords: outlines, confluence, wiki
|
|
|
|
|
|
|
|
;; This file is not part of GNU Emacs.
|
|
|
|
|
2013-03-10 12:57:47 -04:00
|
|
|
;; This program is free software: you can redistribute it and/or modify
|
2012-12-15 01:36:05 -05:00
|
|
|
;; it under the terms of the GNU General Public License as published by
|
|
|
|
;; the Free Software Foundation, either version 3 of the License, or
|
|
|
|
;; (at your option) any later version.
|
|
|
|
|
2013-03-10 12:57:47 -04:00
|
|
|
;; This program is distributed in the hope that it will be useful,
|
2012-12-15 01:36:05 -05:00
|
|
|
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
;; GNU General Public License for more details.
|
|
|
|
|
|
|
|
;; You should have received a copy of the GNU General Public License
|
|
|
|
;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
;;; Commentary:
|
|
|
|
;;
|
2013-01-27 17:11:34 -05:00
|
|
|
;; ox-confluence.el lets you convert Org files to confluence files
|
|
|
|
;; using the ox.el export engine.
|
2012-12-15 01:36:05 -05:00
|
|
|
;;
|
|
|
|
;; Put this file into your load-path and the following into your ~/.emacs:
|
2013-01-27 17:11:34 -05:00
|
|
|
;; (require 'ox-confluence)
|
2012-12-15 01:36:05 -05:00
|
|
|
;;
|
|
|
|
;; Export Org files to confluence:
|
2013-01-27 17:11:34 -05:00
|
|
|
;; M-x org-confluence-export-as-confluence RET
|
2012-12-15 01:36:05 -05:00
|
|
|
;;
|
|
|
|
;;; Code:
|
|
|
|
|
2013-01-27 17:11:34 -05:00
|
|
|
(require 'ox)
|
|
|
|
(require 'ox-ascii)
|
2012-12-15 01:36:05 -05:00
|
|
|
|
|
|
|
;; Define the backend itself
|
2013-01-27 17:11:34 -05:00
|
|
|
(org-export-define-derived-backend confluence ascii
|
|
|
|
:translate-alist ((bold . org-confluence-bold)
|
|
|
|
(example-block . org-confluence-example-block)
|
|
|
|
(fixed-width . org-confluence-fixed-width)
|
|
|
|
(footnote-definition . org-confluence-empty)
|
|
|
|
(footnote-reference . org-confluence-empty)
|
|
|
|
(headline . org-confluence-headline)
|
|
|
|
(italic . org-confluence-italic)
|
|
|
|
(link . org-confluence-link)
|
|
|
|
(section . org-confluence-section)
|
|
|
|
(src-block . org-confluence-src-block)
|
|
|
|
(strike-through . org-confluence-strike-through)
|
|
|
|
(table . org-confluence-table)
|
|
|
|
(table-cell . org-confluence-table-cell)
|
|
|
|
(table-row . org-confluence-table-row)
|
|
|
|
(template . org-confluence-template)
|
|
|
|
(underline . org-confluence-underline)))
|
2012-12-15 01:36:05 -05:00
|
|
|
|
|
|
|
;; All the functions we use
|
2013-01-27 17:11:34 -05:00
|
|
|
(defun org-confluence-bold (bold contents info)
|
2012-12-15 01:36:05 -05:00
|
|
|
(format "*%s*" contents))
|
|
|
|
|
2013-01-27 17:11:34 -05:00
|
|
|
(defun org-confluence-empty (empy contents info)
|
2012-12-15 01:36:05 -05:00
|
|
|
"")
|
|
|
|
|
2013-01-27 17:11:34 -05:00
|
|
|
(defun org-confluence-example-block (example-block contents info)
|
2012-12-15 01:36:05 -05:00
|
|
|
;; FIXME: provide a user-controlled variable for theme
|
|
|
|
(let ((content (org-export-format-code-default example-block info)))
|
2013-01-27 17:11:34 -05:00
|
|
|
(org-confluence--block "none" "Confluence" content)))
|
2012-12-15 01:36:05 -05:00
|
|
|
|
2013-01-27 17:11:34 -05:00
|
|
|
(defun org-confluence-italic (italic contents info)
|
2012-12-15 01:36:05 -05:00
|
|
|
(format "_%s_" contents))
|
|
|
|
|
2013-01-27 17:11:34 -05:00
|
|
|
(defun org-confluence-fixed-width (fixed-width contents info)
|
2012-12-15 01:36:05 -05:00
|
|
|
(format "\{\{%s\}\}" contents))
|
|
|
|
|
2013-01-27 17:11:34 -05:00
|
|
|
(defun org-confluence-headline (headline contents info)
|
2012-12-15 01:36:05 -05:00
|
|
|
(let ((low-level-rank (org-export-low-level-p headline info))
|
|
|
|
(text (org-export-data (org-element-property :title headline)
|
|
|
|
info))
|
|
|
|
(level (org-export-get-relative-level headline info)))
|
|
|
|
;; Else: Standard headline.
|
|
|
|
(format "h%s. %s\n%s" level text
|
|
|
|
(if (org-string-nw-p contents) contents
|
|
|
|
""))))
|
|
|
|
|
2013-01-27 17:11:34 -05:00
|
|
|
(defun org-confluence-link (link desc info)
|
2012-12-15 01:36:05 -05:00
|
|
|
(let ((raw-link (org-element-property :raw-link link)))
|
|
|
|
(concat "["
|
|
|
|
(when (org-string-nw-p desc) (format "%s|" desc))
|
|
|
|
(cond
|
|
|
|
((string-match "^confluence:" raw-link)
|
|
|
|
(replace-regexp-in-string "^confluence:" "" raw-link))
|
|
|
|
(t
|
|
|
|
raw-link))
|
|
|
|
"]")))
|
2013-01-27 17:11:34 -05:00
|
|
|
(defun org-confluence-section (section contents info)
|
2012-12-15 01:36:05 -05:00
|
|
|
contents)
|
|
|
|
|
2013-01-27 17:11:34 -05:00
|
|
|
(defun org-confluence-src-block (src-block contents info)
|
2012-12-15 01:36:05 -05:00
|
|
|
;; FIXME: provide a user-controlled variable for theme
|
|
|
|
(let* ((lang (org-element-property :language src-block))
|
|
|
|
(language (if (string= lang "sh") "bash" ;; FIXME: provide a mapping of some sort
|
|
|
|
lang))
|
|
|
|
(content (org-export-format-code-default src-block info)))
|
2013-01-27 17:11:34 -05:00
|
|
|
(org-confluence--block language "Emacs" content)))
|
2012-12-15 01:36:05 -05:00
|
|
|
|
2013-01-27 17:11:34 -05:00
|
|
|
(defun org-confluence-strike-through (strike-through contents info)
|
2012-12-15 01:36:05 -05:00
|
|
|
(format "-%s-" contents))
|
|
|
|
|
2013-01-27 17:11:34 -05:00
|
|
|
(defun org-confluence-table (table contents info)
|
2012-12-15 01:36:05 -05:00
|
|
|
contents)
|
|
|
|
|
2013-01-27 17:11:34 -05:00
|
|
|
(defun org-confluence-table-row (table-row contents info)
|
2012-12-15 01:36:05 -05:00
|
|
|
(concat
|
|
|
|
(if (org-string-nw-p contents) (format "|%s" contents)
|
|
|
|
"")
|
|
|
|
(when (org-export-table-row-ends-header-p table-row info)
|
|
|
|
"|")))
|
|
|
|
|
2013-01-27 17:11:34 -05:00
|
|
|
(defun org-confluence-table-cell (table-cell contents info)
|
2012-12-15 01:36:05 -05:00
|
|
|
(let ((table-row (org-export-get-parent table-cell)))
|
|
|
|
(concat
|
|
|
|
(when (org-export-table-row-starts-header-p table-row info)
|
|
|
|
"|")
|
|
|
|
contents "|")))
|
|
|
|
|
2013-01-27 17:11:34 -05:00
|
|
|
(defun org-confluence-template (contents info)
|
2012-12-15 01:36:05 -05:00
|
|
|
(let ((depth (plist-get info :with-toc)))
|
|
|
|
(concat (when depth "\{toc\}\n\n") contents)))
|
|
|
|
|
2013-01-27 17:11:34 -05:00
|
|
|
(defun org-confluence-underline (underline contents info)
|
2012-12-15 01:36:05 -05:00
|
|
|
(format "+%s+" contents))
|
|
|
|
|
2013-01-27 17:11:34 -05:00
|
|
|
(defun org-confluence--block (language theme contents)
|
2012-12-15 01:36:05 -05:00
|
|
|
(concat "\{code:theme=" theme
|
|
|
|
(when language (format "|language=%s" language))
|
|
|
|
"}\n"
|
|
|
|
contents
|
|
|
|
"\{code\}\n"))
|
|
|
|
|
|
|
|
;; main interactive entrypoint
|
2013-01-27 17:11:34 -05:00
|
|
|
(defun org-confluence-export-as-confluence
|
2012-12-15 14:22:46 -05:00
|
|
|
(&optional async subtreep visible-only body-only ext-plist)
|
2012-12-15 01:36:05 -05:00
|
|
|
"Export current buffer to a text buffer.
|
|
|
|
|
|
|
|
If narrowing is active in the current buffer, only export its
|
|
|
|
narrowed part.
|
|
|
|
|
|
|
|
If a region is active, export that region.
|
|
|
|
|
2012-12-15 14:22:46 -05:00
|
|
|
A non-nil optional argument ASYNC means the process should happen
|
|
|
|
asynchronously. The resulting buffer should be accessible
|
|
|
|
through the `org-export-stack' interface.
|
|
|
|
|
2012-12-15 01:36:05 -05:00
|
|
|
When optional argument SUBTREEP is non-nil, export the sub-tree
|
|
|
|
at point, extracting information from the headline properties
|
|
|
|
first.
|
|
|
|
|
|
|
|
When optional argument VISIBLE-ONLY is non-nil, don't export
|
|
|
|
contents of hidden elements.
|
|
|
|
|
|
|
|
When optional argument BODY-ONLY is non-nil, strip title, table
|
|
|
|
of contents and footnote definitions from output.
|
|
|
|
|
|
|
|
EXT-PLIST, when provided, is a property list with external
|
|
|
|
parameters overriding Org default settings, but still inferior to
|
|
|
|
file-local settings.
|
|
|
|
|
|
|
|
Export is done in a buffer named \"*Org E-Confluence Export*\", which
|
|
|
|
will be displayed when `org-export-show-temporary-export-buffer'
|
|
|
|
is non-nil."
|
|
|
|
(interactive)
|
2012-12-15 14:22:46 -05:00
|
|
|
(if async
|
|
|
|
(org-export-async-start
|
|
|
|
(lambda (output)
|
|
|
|
(with-current-buffer (get-buffer-create "*Org E-Confluence Export*")
|
|
|
|
(erase-buffer)
|
|
|
|
(insert output)
|
|
|
|
(goto-char (point-min))
|
|
|
|
(text-mode)
|
2013-01-27 17:11:34 -05:00
|
|
|
(org-export-add-to-stack (current-buffer) 'confluence)))
|
|
|
|
`(org-export-as 'confluence ,subtreep ,visible-only ,body-only
|
2012-12-15 14:22:46 -05:00
|
|
|
',ext-plist))
|
|
|
|
(let ((outbuf (org-export-to-buffer
|
2013-01-27 17:11:34 -05:00
|
|
|
'confluence "*Org E-Confluence Export*"
|
2012-12-15 14:22:46 -05:00
|
|
|
subtreep visible-only body-only ext-plist)))
|
|
|
|
(with-current-buffer outbuf (text-mode))
|
|
|
|
(when org-export-show-temporary-export-buffer
|
|
|
|
(switch-to-buffer-other-window outbuf)))))
|
2012-12-15 01:36:05 -05:00
|
|
|
|
2013-01-27 17:11:34 -05:00
|
|
|
(provide 'ox-confluence)
|