Delete org-export.el, org-mw.el and org-mm.el.
org-export.el conflicts with contrib/lisp/org-export.el and the two org-mw.el org-mm.el don't work without it. A rewrite of these experimental exporters using Nicolas' org-export.el is necessary.
This commit is contained in:
parent
03066dab8b
commit
b5e15d6fbc
|
@ -1,201 +0,0 @@
|
||||||
;;; org-export.el --- Export engine for Org
|
|
||||||
;;
|
|
||||||
;; Copyright 2008-2011 Free Software Foundation, Inc.
|
|
||||||
;;
|
|
||||||
;; Emacs Lisp Archive Entry
|
|
||||||
;; Filename: org-export.el
|
|
||||||
;; Version: 0.3
|
|
||||||
;; Author: Bastien <bzg AT altern DOT org>
|
|
||||||
;; Maintainer: Bastien <bzg AT altern DOT org>
|
|
||||||
;; Keywords:
|
|
||||||
;; Description:
|
|
||||||
;; URL: [Not distributed yet]
|
|
||||||
;;
|
|
||||||
;; This file is not part of GNU Emacs.
|
|
||||||
;;
|
|
||||||
;; This program is free software; you can redistribute it and/or modify
|
|
||||||
;; it under the terms of the GNU General Public License as published by
|
|
||||||
;; the Free Software Foundation; either version 3, or (at your option)
|
|
||||||
;; any later version.
|
|
||||||
;;
|
|
||||||
;; This program is distributed in the hope that it will be useful,
|
|
||||||
;; 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 this program; if not, write to the Free Software
|
|
||||||
;; Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
||||||
;;
|
|
||||||
;;; Commentary:
|
|
||||||
;;
|
|
||||||
;; org-export.el implements a new experimental export engine for Org.
|
|
||||||
;;
|
|
||||||
;; Put this file into your load-path and the following into your ~/.emacs:
|
|
||||||
;; (require 'org-export)
|
|
||||||
;;
|
|
||||||
;;; Todo:
|
|
||||||
;;
|
|
||||||
;;; Code:
|
|
||||||
|
|
||||||
(eval-when-compile
|
|
||||||
(require 'cl))
|
|
||||||
|
|
||||||
;;; Preparation functions:
|
|
||||||
|
|
||||||
;; Currently needed for `org-export-preprocess-string'
|
|
||||||
(require 'org-exp)
|
|
||||||
|
|
||||||
(defvar org-export-structure nil)
|
|
||||||
(defvar org-export-content nil)
|
|
||||||
(defvar org-export-properties nil)
|
|
||||||
|
|
||||||
(defun org-export-set-backend (suffix)
|
|
||||||
"Set the backend functions names from SUFFIX."
|
|
||||||
(setq org-export-structure
|
|
||||||
`((header ,(intern (concat "org-" suffix "-export-header")))
|
|
||||||
(first-lines ,(intern (concat "org-" suffix "-export-first-lines")))
|
|
||||||
(section-beginning ,(intern (concat "org-" suffix "-export-section-beginning")))
|
|
||||||
(heading ,(intern (concat "org-" suffix "-export-heading")))
|
|
||||||
(section-end ,(intern (concat "org-" suffix "-export-section-end")))
|
|
||||||
(footer ,(intern (concat "org-" suffix "-export-footer")))))
|
|
||||||
(setq org-export-content
|
|
||||||
`((fonts ,(intern (concat "org-" suffix "-export-fonts")))
|
|
||||||
(links ,(intern (concat "org-" suffix "-export-links")))
|
|
||||||
(lists ,(intern (concat "org-" suffix "-export-lists")))
|
|
||||||
(envs ,(intern (concat "org-" suffix "-export-quote-verse-center")))
|
|
||||||
(tables ,(intern (concat "org-" suffix "-export-tables"))))))
|
|
||||||
|
|
||||||
;;; Parsing functions:
|
|
||||||
|
|
||||||
(defun org-export-parse (&optional level)
|
|
||||||
"Recursively parse the current buffer.
|
|
||||||
If LEVEL is set, do the parsing at that level of sectioning.
|
|
||||||
Return a nested list containing the structure of the parsed
|
|
||||||
buffer and information about each section, including its
|
|
||||||
content."
|
|
||||||
(let (output eos)
|
|
||||||
(save-excursion
|
|
||||||
(goto-char (point-min))
|
|
||||||
(while (re-search-forward org-complex-heading-regexp nil t)
|
|
||||||
(let ((heading (match-string 4))
|
|
||||||
(properties (org-entry-properties)))
|
|
||||||
(save-restriction
|
|
||||||
(narrow-to-region (if (looking-at "\n") (1+ (point)) (point))
|
|
||||||
(save-excursion
|
|
||||||
(setq eos (org-end-of-subtree t t))))
|
|
||||||
(setq output
|
|
||||||
(append output
|
|
||||||
(list
|
|
||||||
(list :level (or level 1)
|
|
||||||
:heading heading
|
|
||||||
:properties properties
|
|
||||||
:content (org-export-get-entry-content)
|
|
||||||
:subtree (org-export-parse
|
|
||||||
(if level (1+ level) 2)))))))
|
|
||||||
(goto-char (1- eos)))))
|
|
||||||
output))
|
|
||||||
|
|
||||||
(defun org-export-get-entry-content ()
|
|
||||||
"Extract the content of an entry.
|
|
||||||
The content of a entry is the part before its first subtree or
|
|
||||||
the end of the entry."
|
|
||||||
(save-excursion
|
|
||||||
(goto-char (point-min))
|
|
||||||
;; FIXME The following shouldn't be necessary since we are cleaning
|
|
||||||
;; up the buffer ith org-export-preprocess-string
|
|
||||||
(while (or (looking-at org-property-drawer-re)
|
|
||||||
(looking-at org-clock-drawer-re)
|
|
||||||
(looking-at org-keyword-time-regexp))
|
|
||||||
(move-beginning-of-line 1))
|
|
||||||
(buffer-substring
|
|
||||||
(point)
|
|
||||||
(if (re-search-forward org-complex-heading-regexp nil t)
|
|
||||||
(match-beginning 0) (point-max)))))
|
|
||||||
|
|
||||||
;;; Rendering functions:
|
|
||||||
|
|
||||||
(defun org-export-render (&optional filter)
|
|
||||||
"Render the current Org buffer and export it.
|
|
||||||
First parse the buffer and return it as a nested list. If FILTER
|
|
||||||
is set, use it to filter this list (see `org-export-filter') then
|
|
||||||
export the (filtered) list with `org-export-render-structure'."
|
|
||||||
(setq org-export-properties
|
|
||||||
(org-combine-plists (org-default-export-plist)
|
|
||||||
(org-infile-export-plist)))
|
|
||||||
(let* (first-lines
|
|
||||||
(bstring (buffer-string))
|
|
||||||
(parsed-buffer
|
|
||||||
(with-temp-buffer
|
|
||||||
(org-mode)
|
|
||||||
(insert (apply 'org-export-preprocess-string
|
|
||||||
bstring org-export-properties))
|
|
||||||
(goto-char (point-min))
|
|
||||||
(setq first-lines (org-export-get-entry-content))
|
|
||||||
(org-export-parse))))
|
|
||||||
(switch-to-buffer (get-buffer-create "*Org export*"))
|
|
||||||
(erase-buffer)
|
|
||||||
(funcall (cadr (assoc 'header org-export-structure)))
|
|
||||||
(funcall (cadr (assoc 'first-lines org-export-structure)) first-lines)
|
|
||||||
(org-export-render-structure parsed-buffer filter)
|
|
||||||
(funcall (cadr (assoc 'footer org-export-structure)))))
|
|
||||||
|
|
||||||
(defun org-export-render-structure (parsed-buffer &optional filter)
|
|
||||||
"Render PARSED-BUFFER.
|
|
||||||
An optional argument FILTER specifies a filter to pass to the
|
|
||||||
rendering engine."
|
|
||||||
(mapc (lambda(s)
|
|
||||||
(funcall (cadr (assoc 'section-beginning org-export-structure)) s)
|
|
||||||
(funcall (cadr (assoc 'heading org-export-structure)) s)
|
|
||||||
(insert (org-export-render-content s) "\n\n")
|
|
||||||
(org-export-render-structure (plist-get s :subtree) filter)
|
|
||||||
(funcall (cadr (assoc 'section-end org-export-structure)) s))
|
|
||||||
(org-export-filter parsed-buffer filter)))
|
|
||||||
|
|
||||||
(defun org-export-render-content (section)
|
|
||||||
"Render SECTION.
|
|
||||||
SECTION is either a string or a property list containing
|
|
||||||
informations (including content) for a section."
|
|
||||||
(with-temp-buffer
|
|
||||||
(insert (if (listp section) (plist-get section :content) section))
|
|
||||||
(mapc (lambda(e)
|
|
||||||
(goto-char (point-min))
|
|
||||||
(funcall (cadr (assoc e org-export-content))))
|
|
||||||
'(fonts tables lists envs links))
|
|
||||||
(buffer-string)))
|
|
||||||
|
|
||||||
(defun org-export-filter (parsed-buffer filter)
|
|
||||||
"Filter out PARSED-BUFFER with FILTER.
|
|
||||||
PARSED-BUFFER is a nested list of sections and subsections, as
|
|
||||||
produced by `org-export-parse'. FILTER is an alist of rules to
|
|
||||||
apply to PARSED-BUFFER. For the syntax of a filter, please check
|
|
||||||
the docstring of `org-export-latex-filter'."
|
|
||||||
;; FIXME where is org-export-latex-filter
|
|
||||||
(delete
|
|
||||||
nil
|
|
||||||
(mapcar
|
|
||||||
(lambda(s)
|
|
||||||
(if (delete
|
|
||||||
nil
|
|
||||||
(mapcar
|
|
||||||
(lambda(f)
|
|
||||||
(let ((cnd (car f)) (re (cadr f)) prop-cnd)
|
|
||||||
(or (and (eq cnd 'heading)
|
|
||||||
(string-match re (plist-get s :heading)))
|
|
||||||
(and (eq cnd 'content)
|
|
||||||
(string-match re (plist-get s :content)))
|
|
||||||
(and (setq prop-cnd
|
|
||||||
(assoc cnd (plist-get s :properties)))
|
|
||||||
(string-match re (cadr prop-cnd))))))
|
|
||||||
filter))
|
|
||||||
nil ;; return nil if the section is filtered out
|
|
||||||
(progn (plist-put s :subtree
|
|
||||||
(org-export-filter (plist-get s :subtree) filter))
|
|
||||||
s))) ;; return the section if it isn't filtered out
|
|
||||||
parsed-buffer)))
|
|
||||||
|
|
||||||
(provide 'org-export)
|
|
||||||
|
|
||||||
;;; User Options, Variables
|
|
||||||
|
|
||||||
;;; org-export.el ends here
|
|
|
@ -1,248 +0,0 @@
|
||||||
;;; org-mm.el --- MoinMoin backend for org-export.el
|
|
||||||
;;
|
|
||||||
;; Copyright 2010-2011 Puneeth Chaganti
|
|
||||||
;;
|
|
||||||
;; Emacs Lisp Archive Entry
|
|
||||||
;; Filename: org-mm.el
|
|
||||||
;; Version: 0.2
|
|
||||||
;; Author: Puneeth Chaganti <punchagan [at] gmail [dot] com>
|
|
||||||
;; Keywords: MoinMoin Org export
|
|
||||||
;; Description: MoinMoin exporter for Org
|
|
||||||
;;
|
|
||||||
;; This file is not part of GNU Emacs.
|
|
||||||
;;
|
|
||||||
;; This program is free software; you can redistribute it and/or modify
|
|
||||||
;; it under the terms of the GNU General Public License as published by
|
|
||||||
;; the Free Software Foundation; either version 3, or (at your option)
|
|
||||||
;; any later version.
|
|
||||||
;;
|
|
||||||
;; This program is distributed in the hope that it will be useful,
|
|
||||||
;; 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 this program; if not, write to the Free Software
|
|
||||||
;; Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
||||||
;;
|
|
||||||
;; A portion of this code is based on org-mw.el by Bastien Guerry.
|
|
||||||
;;
|
|
||||||
;;; Commentary:
|
|
||||||
;;
|
|
||||||
;; org-mm.el lets you convert Org files to MoinMoin files using
|
|
||||||
;; the org-export.el experimental engine.
|
|
||||||
;;
|
|
||||||
;; Put this file into your load-path and the following into your ~/.emacs:
|
|
||||||
;; (require 'org-mm)
|
|
||||||
;;
|
|
||||||
;; You also need to fetch Org's git repository and add the EXPERIMENTAL/
|
|
||||||
;; directory in your load path.
|
|
||||||
;;
|
|
||||||
;; Fetch Org's git repository:
|
|
||||||
;;
|
|
||||||
;; ~$ cd ~/install/git/
|
|
||||||
;; ~$ git clone git://repo.or.cz/org-mode.git
|
|
||||||
;;
|
|
||||||
;; Put this in your .emacs.el:
|
|
||||||
;;
|
|
||||||
;; (add-to-list 'load-path "~/install/git/org-mode/EXPERIMENTAL/")
|
|
||||||
;;
|
|
||||||
;; Export Org files to MoinMoin: M-x org-mm-export RET
|
|
||||||
;;
|
|
||||||
;;; Todo:
|
|
||||||
;;
|
|
||||||
;; - handle radio links
|
|
||||||
;; - support caption and attributes in tables
|
|
||||||
;; - better handline of source code and examples
|
|
||||||
;; - handle inline HTML
|
|
||||||
;;
|
|
||||||
;;; Code:
|
|
||||||
|
|
||||||
(require 'org-export)
|
|
||||||
|
|
||||||
(defvar org-mm-emphasis-alist
|
|
||||||
'(("*" "'''%s'''" nil)
|
|
||||||
("/" "''%s''" nil)
|
|
||||||
("_" "__%s__" nil)
|
|
||||||
("+" "--%s--" nil)
|
|
||||||
("=" "`%s`" nil))
|
|
||||||
"The list of fontification expressions for MoinMoin.")
|
|
||||||
|
|
||||||
(defvar org-mm-export-table-table-style "")
|
|
||||||
(defvar org-mm-export-table-header-style "")
|
|
||||||
(defvar org-mm-export-table-cell-style "")
|
|
||||||
|
|
||||||
(defun org-mm-export ()
|
|
||||||
"Export the current buffer to MoinMoin."
|
|
||||||
(interactive)
|
|
||||||
(setq org-export-current-backend 'mm)
|
|
||||||
(org-export-set-backend "mm")
|
|
||||||
;; FIXME see the problem `org-mm-export-footnotes'
|
|
||||||
;; (add-hook 'org-export-preprocess-final-hook 'org-mm-export-footnotes)
|
|
||||||
(add-hook 'org-export-preprocess-before-backend-specifics-hook
|
|
||||||
'org-mm-export-src-example)
|
|
||||||
(org-export-render)
|
|
||||||
;; (remove-hook 'org-export-preprocess-final-hook 'org-mm-export-footnotes)
|
|
||||||
(remove-hook 'org-export-preprocess-before-backend-specifics-hook
|
|
||||||
'org-mm-export-src-example))
|
|
||||||
|
|
||||||
(defun org-mm-export-header ()
|
|
||||||
"Export the header part."
|
|
||||||
(let* ((p (org-combine-plists (org-infile-export-plist)
|
|
||||||
org-export-properties))
|
|
||||||
(title (plist-get p :title))
|
|
||||||
(author (plist-get p :author))
|
|
||||||
(date (plist-get p :date))
|
|
||||||
(level (plist-get p :headline-levels)))
|
|
||||||
(insert (format "= %s by %s =\n\n" title author))
|
|
||||||
(if (plist-get p :table-of-contents)
|
|
||||||
(insert (format "<<TableOfContents(%s)>>\n" level)))))
|
|
||||||
|
|
||||||
(defun org-mm-export-first-lines (first-lines)
|
|
||||||
"Export first lines."
|
|
||||||
(insert (org-export-render-content first-lines) "\n")
|
|
||||||
(goto-char (point-max)))
|
|
||||||
|
|
||||||
(defun org-mm-export-heading (section-properties)
|
|
||||||
"Export MoinMoin heading"
|
|
||||||
(let* ((p section-properties)
|
|
||||||
(h (plist-get p :heading))
|
|
||||||
(s (make-string (1+ (plist-get p :level)) ?=)))
|
|
||||||
(insert (format "%s %s %s\n" s h s))))
|
|
||||||
|
|
||||||
(defun org-mm-export-quote-verse-center ()
|
|
||||||
"Export #+BEGIN_QUOTE/VERSE/CENTER environments."
|
|
||||||
(let (rpl e)
|
|
||||||
(while (re-search-forward "^[ \t]*ORG-\\([A-Z]+\\)-\\(START\\|END\\).*$" nil t)
|
|
||||||
(setq e (if (equal (match-string 2) "END") "/" ""))
|
|
||||||
(setq rpl
|
|
||||||
(cond ((equal (match-string 1) "BLOCKQUOTE") "blockquote>")
|
|
||||||
((equal (match-string 1) "VERSE") "pre>")
|
|
||||||
((equal (match-string 1) "CENTER") "center>")))
|
|
||||||
(replace-match (concat "<" e rpl) t))))
|
|
||||||
|
|
||||||
(defun org-mm-export-fonts ()
|
|
||||||
"Export fontification."
|
|
||||||
(while (re-search-forward org-emph-re nil t)
|
|
||||||
(let* ((emph (assoc (match-string 3) org-mm-emphasis-alist))
|
|
||||||
(beg (match-beginning 0))
|
|
||||||
(begs (match-string 1))
|
|
||||||
(end (match-end 0))
|
|
||||||
(ends (match-string 5))
|
|
||||||
(rpl (format (cadr emph) (match-string 4))))
|
|
||||||
(delete-region beg end)
|
|
||||||
(insert begs rpl ends))))
|
|
||||||
|
|
||||||
(defun org-mm-export-links ()
|
|
||||||
"Replace Org links with MoinMoin links."
|
|
||||||
;; FIXME: This function could be more clever, of course.
|
|
||||||
(while (re-search-forward org-bracket-link-analytic-regexp nil t)
|
|
||||||
(cond ((and (equal (match-string 1) "file:")
|
|
||||||
(save-match-data
|
|
||||||
(string-match (org-image-file-name-regexp) (match-string 3))))
|
|
||||||
(replace-match
|
|
||||||
(concat "{{" (file-name-nondirectory (match-string 3)) "}}")))
|
|
||||||
(t
|
|
||||||
(replace-match
|
|
||||||
(concat "[[\\1\\3|" (if (match-string 5) "\\5]]" "]]")))))))
|
|
||||||
|
|
||||||
;; FIXME this function should test whether [1] is really a footnote.
|
|
||||||
;; `org-footnote-normalize' should add properties to the normalized
|
|
||||||
;; footnotes so that we can recognize them.
|
|
||||||
(defun org-mm-export-footnotes ()
|
|
||||||
"Export footnotes."
|
|
||||||
(goto-char (point-min))
|
|
||||||
(let (refpos rpl begnote begfullnote endnote)
|
|
||||||
(while (re-search-forward "\[[0-9]+\]" nil t)
|
|
||||||
(save-excursion
|
|
||||||
(save-match-data
|
|
||||||
(goto-char (point-max))
|
|
||||||
(search-backward (concat (match-string 0) " ") nil t)
|
|
||||||
(setq begfullnote (match-beginning 0))
|
|
||||||
(setq begnote (match-end 0))
|
|
||||||
(goto-char (match-end 0))
|
|
||||||
(re-search-forward "^\[[0-9]+\]\\|\\'" nil t)
|
|
||||||
(setq endnote (match-beginning 0))
|
|
||||||
(setq rpl (replace-regexp-in-string
|
|
||||||
"\n" " " (buffer-substring endnote begnote)))
|
|
||||||
(setq rpl (replace-regexp-in-string "[ \t]+$" "" rpl))
|
|
||||||
(delete-region begfullnote endnote)))
|
|
||||||
(replace-match (concat "<ref>" rpl "</ref>")))))
|
|
||||||
|
|
||||||
(defun org-mm-export-src-example ()
|
|
||||||
"Export #+BEGIN_EXAMPLE and #+BEGIN_SRC."
|
|
||||||
(goto-char (point-min))
|
|
||||||
(let (start env)
|
|
||||||
(while (re-search-forward "^[ \t]*#\\+BEGIN_\\(EXAMPLE\\|SRC\\).*\n" nil t)
|
|
||||||
(setq env (match-string 1))
|
|
||||||
(replace-match "{{{\n")
|
|
||||||
(setq start (point))
|
|
||||||
(re-search-forward (concat "^[ \t]*#\\+END_" env ".*\n") nil t)
|
|
||||||
(replace-match "}}}\n"))))
|
|
||||||
|
|
||||||
(defun org-mm-export-lists ()
|
|
||||||
"Export lists to MoinMoin syntax."
|
|
||||||
(while (re-search-forward (org-item-beginning-re) nil t)
|
|
||||||
(move-beginning-of-line 1)
|
|
||||||
(insert (org-list-to-generic
|
|
||||||
(org-list-parse-list t)
|
|
||||||
(org-combine-plists
|
|
||||||
'(:splice nil
|
|
||||||
:ostart "" :oend ""
|
|
||||||
:ustart "" :uend ""
|
|
||||||
:dstart "" :dend ""
|
|
||||||
:dtstart "" :dtend " "
|
|
||||||
:istart (concat (make-string (* 2 (1+ depth)) ? )
|
|
||||||
(if (eq type 'unordered)
|
|
||||||
"* " "# "))
|
|
||||||
:iend "\n"
|
|
||||||
:icount nil
|
|
||||||
:csep "\n"
|
|
||||||
:cbon "[X]" :cboff "[ ]"
|
|
||||||
:cbtrans "[-]"))))))
|
|
||||||
|
|
||||||
|
|
||||||
(defun org-mm-export-tables ()
|
|
||||||
"Convert tables in the current buffer to MoinMoin tables."
|
|
||||||
(while (re-search-forward "^\\([ \t]*\\)|" nil t)
|
|
||||||
(org-if-unprotected-at (1- (point))
|
|
||||||
(org-table-align)
|
|
||||||
(let* ((beg (org-table-begin))
|
|
||||||
(end (org-table-end))
|
|
||||||
(raw-table (buffer-substring beg end)) lines)
|
|
||||||
(setq lines (org-split-string raw-table "\n"))
|
|
||||||
(apply 'delete-region (list beg end))
|
|
||||||
(when org-export-table-remove-special-lines
|
|
||||||
(setq lines (org-table-clean-before-export lines 'maybe-quoted)))
|
|
||||||
(setq lines
|
|
||||||
(mapcar
|
|
||||||
(lambda(elem)
|
|
||||||
(or (and (string-match "[ \t]*|-+" elem) 'hline)
|
|
||||||
(org-split-string (org-trim elem) "|")))
|
|
||||||
lines))
|
|
||||||
(insert (orgtbl-to-mm lines nil))))))
|
|
||||||
|
|
||||||
(defun orgtbl-to-mm (table params)
|
|
||||||
"Convert TABLE into a MoinMoin table."
|
|
||||||
(let ((params2 (list
|
|
||||||
:tstart (concat ""
|
|
||||||
org-mm-export-table-table-style)
|
|
||||||
:tend "\n"
|
|
||||||
:lstart "||"
|
|
||||||
:lend "||"
|
|
||||||
:sep "||"
|
|
||||||
:fmt (concat org-mm-export-table-cell-style " %s ")
|
|
||||||
:hfmt (concat org-mm-export-table-cell-style "''' %s '''")
|
|
||||||
:hlsep "||"
|
|
||||||
)))
|
|
||||||
(orgtbl-to-generic table (org-combine-plists params2 params))))
|
|
||||||
|
|
||||||
;; Various empty function for org-export.el to work:
|
|
||||||
(defun org-mm-export-footer () "")
|
|
||||||
(defun org-mm-export-section-beginning (section-properties) "")
|
|
||||||
(defun org-mm-export-section-end (section-properties) "")
|
|
||||||
(defun org-export-mm-preprocess (parameters)
|
|
||||||
"Do extra work for MoinMoin export."
|
|
||||||
nil)
|
|
||||||
|
|
||||||
(provide 'org-mm)
|
|
|
@ -1,248 +0,0 @@
|
||||||
;;; org-mw.el --- Mediawiki backend for org-export.el
|
|
||||||
;;
|
|
||||||
;; Copyright 2010-2011 Free Software Foundation, Inc.
|
|
||||||
;;
|
|
||||||
;; Emacs Lisp Archive Entry
|
|
||||||
;; Filename: org-mw.el
|
|
||||||
;; Version: 0.3b
|
|
||||||
;; Author: Bastien <bzg AT altern DOT org>
|
|
||||||
;; Maintainer: Bastien <bzg AT altern DOT org>
|
|
||||||
;; Keywords: Mediawiki Org export
|
|
||||||
;; Description: Mediawiki exporter for Org
|
|
||||||
;; URL: [Not distributed yet]
|
|
||||||
;;
|
|
||||||
;; This file is not part of GNU Emacs.
|
|
||||||
;;
|
|
||||||
;; This program is free software; you can redistribute it and/or modify
|
|
||||||
;; it under the terms of the GNU General Public License as published by
|
|
||||||
;; the Free Software Foundation; either version 3, or (at your option)
|
|
||||||
;; any later version.
|
|
||||||
;;
|
|
||||||
;; This program is distributed in the hope that it will be useful,
|
|
||||||
;; 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 this program; if not, write to the Free Software
|
|
||||||
;; Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
||||||
;;
|
|
||||||
;;; Commentary:
|
|
||||||
;;
|
|
||||||
;; org-mw.el lets you convert Org files to mediawiki files using
|
|
||||||
;; the org-export.el experimental engine.
|
|
||||||
;;
|
|
||||||
;; Put this file into your load-path and the following into your ~/.emacs:
|
|
||||||
;; (require 'org-mw)
|
|
||||||
;;
|
|
||||||
;; You also need to fetch Org's git repository and add the EXPERIMENTAL/
|
|
||||||
;; directory in your load path.
|
|
||||||
;;
|
|
||||||
;; Fetch Org's git repository:
|
|
||||||
;;
|
|
||||||
;; ~$ cd ~/install/git/
|
|
||||||
;; ~$ git clone git://repo.or.cz/org-mode.git
|
|
||||||
;;
|
|
||||||
;; Put this in your .emacs.el:
|
|
||||||
;;
|
|
||||||
;; (add-to-list 'load-path "~/install/git/org-mode/EXPERIMENTAL/")
|
|
||||||
;;
|
|
||||||
;; Export Org files to mediawiki: M-x org-mw-export RET
|
|
||||||
;;
|
|
||||||
;;; Todo:
|
|
||||||
;;
|
|
||||||
;; - handle radio links
|
|
||||||
;; - support caption and attributes in tables
|
|
||||||
;; - better handline of source code and examples
|
|
||||||
;; - handle inline HTML
|
|
||||||
;;
|
|
||||||
;;; Code:
|
|
||||||
|
|
||||||
(require 'org-export)
|
|
||||||
|
|
||||||
(defvar org-mw-emphasis-alist
|
|
||||||
'(("*" "'''%s'''" nil)
|
|
||||||
("/" "''%s''" nil)
|
|
||||||
("_" "<u>%s</u>" nil)
|
|
||||||
("+" "<s>%s</s>" nil)
|
|
||||||
("=" "<tt>%s</tt>" nil))
|
|
||||||
"The list of fontification expressions for mediawiki.")
|
|
||||||
|
|
||||||
(defvar org-mw-export-table-table-style "")
|
|
||||||
(defvar org-mw-export-table-header-style "")
|
|
||||||
(defvar org-mw-export-table-cell-style "")
|
|
||||||
|
|
||||||
(defun org-mw-export ()
|
|
||||||
"Export the current buffer to Mediawiki."
|
|
||||||
(interactive)
|
|
||||||
(setq org-export-current-backend 'mw)
|
|
||||||
(org-export-set-backend "mw")
|
|
||||||
;; FIXME see the problem `org-mw-export-footnotes'
|
|
||||||
;; (add-hook 'org-export-preprocess-final-hook 'org-mw-export-footnotes)
|
|
||||||
(add-hook 'org-export-preprocess-before-backend-specifics-hook
|
|
||||||
'org-mw-export-src-example)
|
|
||||||
(org-export-render)
|
|
||||||
;; (remove-hook 'org-export-preprocess-final-hook 'org-mw-export-footnotes)
|
|
||||||
(remove-hook 'org-export-preprocess-before-backend-specifics-hook
|
|
||||||
'org-mw-export-src-example))
|
|
||||||
|
|
||||||
(defun org-mw-export-header ()
|
|
||||||
"Export the header part."
|
|
||||||
(let* ((p org-export-properties)
|
|
||||||
(title (plist-get p :title))
|
|
||||||
(author (plist-get p :author))
|
|
||||||
(date (plist-get p :date)))
|
|
||||||
(insert (format "= %s by %s =\n\n" title author))
|
|
||||||
(unless (plist-get p :table-of-contents)
|
|
||||||
(insert "__NOTOC__\n\n"))))
|
|
||||||
|
|
||||||
(defun org-mw-export-first-lines (first-lines)
|
|
||||||
"Export first lines."
|
|
||||||
(insert (org-export-render-content first-lines) "\n")
|
|
||||||
(goto-char (point-max)))
|
|
||||||
|
|
||||||
(defun org-mw-export-heading (section-properties)
|
|
||||||
"Export mediawiki heading"
|
|
||||||
(let* ((p section-properties)
|
|
||||||
(h (plist-get p :heading))
|
|
||||||
(s (make-string (1+ (plist-get p :level)) ?=)))
|
|
||||||
(insert (format "%s %s %s\n" s h s))))
|
|
||||||
|
|
||||||
(defun org-mw-export-quote-verse-center ()
|
|
||||||
"Export #+BEGIN_QUOTE/VERSE/CENTER environments."
|
|
||||||
(let (rpl e)
|
|
||||||
(while (re-search-forward "^[ \t]*ORG-\\([A-Z]+\\)-\\(START\\|END\\).*$" nil t)
|
|
||||||
(setq e (if (equal (match-string 2) "END") "/" ""))
|
|
||||||
(setq rpl
|
|
||||||
(cond ((equal (match-string 1) "BLOCKQUOTE") "blockquote>")
|
|
||||||
((equal (match-string 1) "VERSE") "pre>")
|
|
||||||
((equal (match-string 1) "CENTER") "center>")))
|
|
||||||
(replace-match (concat "<" e rpl) t))))
|
|
||||||
|
|
||||||
(defun org-mw-export-fonts ()
|
|
||||||
"Export fontification."
|
|
||||||
(while (re-search-forward org-emph-re nil t)
|
|
||||||
(let* ((emph (assoc (match-string 3) org-mw-emphasis-alist))
|
|
||||||
(beg (match-beginning 0))
|
|
||||||
(begs (match-string 1))
|
|
||||||
(end (match-end 0))
|
|
||||||
(ends (match-string 5))
|
|
||||||
(rpl (format (cadr emph) (match-string 4))))
|
|
||||||
(delete-region beg end)
|
|
||||||
(insert begs rpl ends))))
|
|
||||||
|
|
||||||
(defun org-mw-export-links ()
|
|
||||||
"Replace Org links with DokiWiki links."
|
|
||||||
;; FIXME: This function could be more clever, of course.
|
|
||||||
(while (re-search-forward org-bracket-link-analytic-regexp nil t)
|
|
||||||
(cond ((and (equal (match-string 1) "file:")
|
|
||||||
(save-match-data
|
|
||||||
(string-match (org-image-file-name-regexp) (match-string 3))))
|
|
||||||
(replace-match
|
|
||||||
(concat "[[Image:" (file-name-nondirectory (match-string 3)) "]]")))
|
|
||||||
(t
|
|
||||||
(replace-match
|
|
||||||
(concat "[\\1\\3" (if (match-string 5) " \\5]" "]")))))))
|
|
||||||
|
|
||||||
;; FIXME this function should test whether [1] is really a footnote.
|
|
||||||
;; `org-footnote-normalize' should add properties to the normalized
|
|
||||||
;; footnotes so that we can recognize them.
|
|
||||||
(defun org-mw-export-footnotes ()
|
|
||||||
"Export footnotes."
|
|
||||||
(goto-char (point-min))
|
|
||||||
(let (refpos rpl begnote begfullnote endnote)
|
|
||||||
(while (re-search-forward "\[[0-9]+\]" nil t)
|
|
||||||
(save-excursion
|
|
||||||
(save-match-data
|
|
||||||
(goto-char (point-max))
|
|
||||||
(search-backward (concat (match-string 0) " ") nil t)
|
|
||||||
(setq begfullnote (match-beginning 0))
|
|
||||||
(setq begnote (match-end 0))
|
|
||||||
(goto-char (match-end 0))
|
|
||||||
(re-search-forward "^\[[0-9]+\]\\|\\'" nil t)
|
|
||||||
(setq endnote (match-beginning 0))
|
|
||||||
(setq rpl (replace-regexp-in-string
|
|
||||||
"\n" " " (buffer-substring endnote begnote)))
|
|
||||||
(setq rpl (replace-regexp-in-string "[ \t]+$" "" rpl))
|
|
||||||
(delete-region begfullnote endnote)))
|
|
||||||
(replace-match (concat "<ref>" rpl "</ref>")))))
|
|
||||||
|
|
||||||
(defun org-mw-export-src-example ()
|
|
||||||
"Export #+BEGIN_EXAMPLE and #+BEGIN_SRC."
|
|
||||||
(goto-char (point-min))
|
|
||||||
(let (start env)
|
|
||||||
(while (re-search-forward "^[ \t]*#\\+BEGIN_\\(EXAMPLE\\|SRC\\).*\n" nil t)
|
|
||||||
(setq env (match-string 1))
|
|
||||||
(replace-match "")
|
|
||||||
(setq start (point))
|
|
||||||
(re-search-forward (concat "^[ \t]*#\\+END_" env ".*\n") nil t)
|
|
||||||
(replace-match "")
|
|
||||||
(string-rectangle start (point) ": ")
|
|
||||||
(delete-char 1))))
|
|
||||||
|
|
||||||
(defun org-mw-export-lists ()
|
|
||||||
"Export lists to mediawiki syntax."
|
|
||||||
(while (re-search-forward (org-item-beginning-re) nil t)
|
|
||||||
(move-beginning-of-line 1)
|
|
||||||
(insert (org-list-to-generic
|
|
||||||
(org-list-parse-list t)
|
|
||||||
(org-combine-plists
|
|
||||||
'(:splice nil
|
|
||||||
:ostart "" :oend ""
|
|
||||||
:ustart "" :uend ""
|
|
||||||
:dstart "" :dend ""
|
|
||||||
:dtstart "" :dtend " "
|
|
||||||
:istart (concat
|
|
||||||
(make-string
|
|
||||||
(1+ depth) (if (eq type 'unordered) ?* ?#)) " ")
|
|
||||||
:iend "\n"
|
|
||||||
:nobr t
|
|
||||||
:icount nil
|
|
||||||
:csep "\n"
|
|
||||||
:cbon "[X]" :cboff "[ ]"
|
|
||||||
:cbtrans "[-]"))))))
|
|
||||||
|
|
||||||
(defun org-mw-export-tables ()
|
|
||||||
"Convert tables in the current buffer to mediawiki tables."
|
|
||||||
(while (re-search-forward "^\\([ \t]*\\)|" nil t)
|
|
||||||
(org-if-unprotected-at (1- (point))
|
|
||||||
(org-table-align)
|
|
||||||
(let* ((beg (org-table-begin))
|
|
||||||
(end (org-table-end))
|
|
||||||
(raw-table (buffer-substring beg end)) lines)
|
|
||||||
(setq lines (org-split-string raw-table "\n"))
|
|
||||||
(apply 'delete-region (list beg end))
|
|
||||||
(when org-export-table-remove-special-lines
|
|
||||||
(setq lines (org-table-clean-before-export lines 'maybe-quoted)))
|
|
||||||
(setq lines
|
|
||||||
(mapcar
|
|
||||||
(lambda(elem)
|
|
||||||
(or (and (string-match "[ \t]*|-+" elem) 'hline)
|
|
||||||
(org-split-string (org-trim elem) "|")))
|
|
||||||
lines))
|
|
||||||
(insert (orgtbl-to-mw lines nil))))))
|
|
||||||
|
|
||||||
(defun orgtbl-to-mw (table params)
|
|
||||||
"Convert TABLE into a mediawiki table."
|
|
||||||
(let ((params2 (list
|
|
||||||
:tstart (concat "{| class=\"wikitable\" "
|
|
||||||
org-mw-export-table-table-style)
|
|
||||||
:tend "|}\n"
|
|
||||||
:lstart "|-\n"
|
|
||||||
:lend ""
|
|
||||||
:sep "\n"
|
|
||||||
:fmt (concat "\| " org-mw-export-table-cell-style " | %s")
|
|
||||||
:hfmt (concat "! scope=row " org-mw-export-table-header-style " | %s")
|
|
||||||
:hlsep "\n"
|
|
||||||
)))
|
|
||||||
(orgtbl-to-generic table (org-combine-plists params2 params))))
|
|
||||||
|
|
||||||
;; Various empty function for org-export.el to work:
|
|
||||||
(defun org-mw-export-footer () "")
|
|
||||||
(defun org-mw-export-section-beginning (section-properties) "")
|
|
||||||
(defun org-mw-export-section-end (section-properties) "")
|
|
||||||
(defun org-export-mw-preprocess (parameters)
|
|
||||||
"Do extra work for Mediawiki export."
|
|
||||||
nil)
|
|
||||||
|
|
||||||
(provide 'org-mw)
|
|
Loading…
Reference in New Issue