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
|
|
|
|
2014-01-07 08:18:17 -05:00
|
|
|
;; Copyright (C) 2012, 2014 Sébastien Delafond
|
2012-12-15 01:36:05 -05:00
|
|
|
|
2013-10-27 13:34:57 -04:00
|
|
|
;; Author: Sébastien Delafond <sdelafond@gmail.com>
|
2012-12-15 01:36:05 -05:00
|
|
|
;; 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-03-19 11:26:30 -04:00
|
|
|
(org-export-define-derived-backend 'confluence 'ascii
|
|
|
|
:translate-alist '((bold . org-confluence-bold)
|
2016-12-05 16:22:53 -05:00
|
|
|
(code . org-confluence-code)
|
2013-03-19 11:26:30 -04:00
|
|
|
(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)
|
2016-12-05 16:22:53 -05:00
|
|
|
(item . org-confluence-item)
|
2013-03-19 11:26:30 -04:00
|
|
|
(link . org-confluence-link)
|
2016-03-16 17:35:36 -04:00
|
|
|
(paragraph . org-confluence-paragraph)
|
2013-09-26 10:46:29 -04:00
|
|
|
(property-drawer . org-confluence-property-drawer)
|
2013-03-19 11:26:30 -04:00
|
|
|
(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)
|
2016-12-05 16:22:53 -05:00
|
|
|
(underline . org-confluence-underline)
|
|
|
|
(verbatim . org-confluence-verbatim)))
|
2012-12-15 01:36:05 -05:00
|
|
|
|
2016-03-09 11:38:46 -05:00
|
|
|
(defcustom org-confluence-lang-alist
|
|
|
|
'(("sh" . "bash"))
|
|
|
|
"Map from org-babel language name to confluence wiki language name"
|
|
|
|
:type '(alist :key-type string :value-type string))
|
|
|
|
|
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-03-24 15:04:42 -04:00
|
|
|
(defun org-confluence-empty (empty 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-10-27 13:20:46 -04:00
|
|
|
(defun org-confluence-item (item contents info)
|
2016-12-07 01:26:04 -05:00
|
|
|
(let* ((plain-list (org-export-get-parent item))
|
|
|
|
(type (org-element-property :type plain-list))
|
2016-12-12 18:07:50 -05:00
|
|
|
(bullet (if (eq type 'ordered) ?\# ?\-)))
|
2016-12-07 01:26:04 -05:00
|
|
|
(concat (make-string (1+ (org-confluence--li-depth item)) bullet)
|
|
|
|
" "
|
2016-12-12 18:07:50 -05:00
|
|
|
(if (eq type 'descriptive)
|
|
|
|
(concat "*"
|
|
|
|
(org-export-data (org-element-property :tag item) info)
|
|
|
|
"* - "))
|
2016-12-07 01:26:04 -05:00
|
|
|
(org-trim contents))))
|
2013-10-27 13:20:46 -04:00
|
|
|
|
2013-01-27 17:11:34 -05:00
|
|
|
(defun org-confluence-fixed-width (fixed-width contents info)
|
2016-12-12 23:14:08 -05:00
|
|
|
(format "\{\{%s\}\}"
|
|
|
|
(org-trim (org-element-property :value fixed-width))))
|
2012-12-15 01:36:05 -05:00
|
|
|
|
2016-12-05 16:22:53 -05:00
|
|
|
(defun org-confluence-verbatim (verbatim contents info)
|
|
|
|
(format "\{\{%s\}\}" (org-element-property :value verbatim)))
|
|
|
|
|
|
|
|
(defun org-confluence-code (code contents info)
|
|
|
|
(format "\{\{%s\}\}" (org-element-property :value code)))
|
|
|
|
|
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-09-26 10:46:29 -04:00
|
|
|
|
2016-03-16 17:35:36 -04:00
|
|
|
(defun org-confluence-paragraph (paragraph contents info)
|
|
|
|
"Transcode PARAGRAPH element for Confluence.
|
|
|
|
CONTENTS is the paragraph contents. INFO is a plist used as
|
|
|
|
a communication channel."
|
|
|
|
contents)
|
|
|
|
|
2013-09-26 10:46:29 -04:00
|
|
|
(defun org-confluence-property-drawer (property-drawer contents info)
|
|
|
|
(and (org-string-nw-p contents)
|
|
|
|
(format "\{\{%s\}\}" contents)))
|
|
|
|
|
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))
|
2016-03-09 11:38:46 -05:00
|
|
|
(language (or (cdr (assoc lang org-confluence-lang-alist)) lang))
|
2012-12-15 01:36:05 -05:00
|
|
|
(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"))
|
|
|
|
|
2013-10-27 13:20:46 -04:00
|
|
|
(defun org-confluence--li-depth (item)
|
|
|
|
"Return depth of a list item; -1 means not a list item"
|
|
|
|
;; FIXME check whether it's worth it to cache depth
|
|
|
|
;; (it gets recalculated quite a few times while
|
|
|
|
;; traversing a list)
|
|
|
|
(let ((depth -1)
|
|
|
|
(tag))
|
|
|
|
(while (and item
|
|
|
|
(setq tag (car item))
|
|
|
|
(or (eq tag 'item) ; list items interleave with plain-list
|
|
|
|
(eq tag 'plain-list)))
|
|
|
|
(when (eq tag 'item)
|
|
|
|
(incf depth))
|
|
|
|
(setq item (org-export-get-parent item)))
|
|
|
|
depth))
|
|
|
|
|
2012-12-15 01:36:05 -05:00
|
|
|
;; 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 back-ends: Apply changes to export functions
* contrib/lisp/ox-confluence.el (org-confluence-export-as-confluence):
* contrib/lisp/ox-deck.el (org-deck-export-as-html,
org-deck-export-to-html):
* contrib/lisp/ox-freemind.el (org-freemind-export-to-freemind):
* contrib/lisp/ox-groff.el (org-groff-export-to-groff,
org-groff-export-to-pdf):
* contrib/lisp/ox-koma-letter.el (org-koma-letter-export-as-latex,
org-koma-letter-export-to-latex, org-koma-letter-export-to-pdf):
* contrib/lisp/ox-rss.el (org-rss-export-as-rss,
org-rss-export-to-rss):
* contrib/lisp/ox-s5.el (org-s5-export-as-html,
org-s5-export-to-html):
* contrib/lisp/ox-taskjuggler.el (org-taskjuggler-export):
* lisp/ob-haskell.el:
* lisp/ox-ascii.el (org-ascii-export-as-ascii,
org-ascii-export-to-ascii):
* lisp/ox-beamer.el (org-beamer-export-as-latex,
org-beamer-export-to-latex, org-beamer-export-to-pdf):
* lisp/ox-html.el (org-html-export-as-html, org-html-export-to-html):
* lisp/ox-icalendar.el (org-icalendar-export-to-ics):
* lisp/ox-latex.el (org-latex-export-as-latex,
org-latex-export-to-pdf):
* lisp/ox-man.el (org-man-export-to-man, org-man-export-to-pdf):
* lisp/ox-md.el (org-md-export-as-markdown,
org-md-export-to-markdown):
* lisp/ox-odt.el (org-odt-export-to-odt):
* lisp/ox-org.el (org-org-export-as-org, org-org-export-to-org):
* lisp/ox-publish.el (org-publish-org-to):
* lisp/ox-texinfo.el (org-texinfo-export-to-texinfo,
org-texinfo-export-to-info):
* testing/lisp/test-ob-exp.el (test-ob-exp/org-babel-exp-src-blocks/w-no-file):
2013-08-07 04:35:42 -04:00
|
|
|
Export is done in a buffer named \"*Org CONFLUENCE Export*\", which
|
2012-12-15 01:36:05 -05:00
|
|
|
will be displayed when `org-export-show-temporary-export-buffer'
|
|
|
|
is non-nil."
|
|
|
|
(interactive)
|
Export back-ends: Apply changes to export functions
* contrib/lisp/ox-confluence.el (org-confluence-export-as-confluence):
* contrib/lisp/ox-deck.el (org-deck-export-as-html,
org-deck-export-to-html):
* contrib/lisp/ox-freemind.el (org-freemind-export-to-freemind):
* contrib/lisp/ox-groff.el (org-groff-export-to-groff,
org-groff-export-to-pdf):
* contrib/lisp/ox-koma-letter.el (org-koma-letter-export-as-latex,
org-koma-letter-export-to-latex, org-koma-letter-export-to-pdf):
* contrib/lisp/ox-rss.el (org-rss-export-as-rss,
org-rss-export-to-rss):
* contrib/lisp/ox-s5.el (org-s5-export-as-html,
org-s5-export-to-html):
* contrib/lisp/ox-taskjuggler.el (org-taskjuggler-export):
* lisp/ob-haskell.el:
* lisp/ox-ascii.el (org-ascii-export-as-ascii,
org-ascii-export-to-ascii):
* lisp/ox-beamer.el (org-beamer-export-as-latex,
org-beamer-export-to-latex, org-beamer-export-to-pdf):
* lisp/ox-html.el (org-html-export-as-html, org-html-export-to-html):
* lisp/ox-icalendar.el (org-icalendar-export-to-ics):
* lisp/ox-latex.el (org-latex-export-as-latex,
org-latex-export-to-pdf):
* lisp/ox-man.el (org-man-export-to-man, org-man-export-to-pdf):
* lisp/ox-md.el (org-md-export-as-markdown,
org-md-export-to-markdown):
* lisp/ox-odt.el (org-odt-export-to-odt):
* lisp/ox-org.el (org-org-export-as-org, org-org-export-to-org):
* lisp/ox-publish.el (org-publish-org-to):
* lisp/ox-texinfo.el (org-texinfo-export-to-texinfo,
org-texinfo-export-to-info):
* testing/lisp/test-ob-exp.el (test-ob-exp/org-babel-exp-src-blocks/w-no-file):
2013-08-07 04:35:42 -04:00
|
|
|
(org-export-to-buffer 'confluence "*org CONFLUENCE Export*"
|
2013-09-12 10:48:17 -04:00
|
|
|
async subtreep visible-only body-only ext-plist (lambda () (text-mode))))
|
2012-12-15 01:36:05 -05:00
|
|
|
|
2013-01-27 17:11:34 -05:00
|
|
|
(provide 'ox-confluence)
|