summaryrefslogtreecommitdiff
path: root/lisp/ox-org.el
diff options
context:
space:
mode:
Diffstat (limited to 'lisp/ox-org.el')
-rw-r--r--lisp/ox-org.el94
1 files changed, 70 insertions, 24 deletions
diff --git a/lisp/ox-org.el b/lisp/ox-org.el
index 195b9d7..82262e0 100644
--- a/lisp/ox-org.el
+++ b/lisp/ox-org.el
@@ -1,6 +1,6 @@
;;; ox-org.el --- Org Back-End for Org Export Engine
-;; Copyright (C) 2013-2014 Free Software Foundation, Inc.
+;; Copyright (C) 2013-2015 Free Software Foundation, Inc.
;; Author: Nicolas Goaziou <n.goaziou@gmail.com>
;; Keywords: org, wp
@@ -57,8 +57,6 @@ setting of `org-html-htmlize-output-type' is 'css."
(center-block . org-org-identity)
(clock . org-org-identity)
(code . org-org-identity)
- (comment . (lambda (&rest args) ""))
- (comment-block . (lambda (&rest args) ""))
(diary-sexp . org-org-identity)
(drawer . org-org-identity)
(dynamic-block . org-org-identity)
@@ -78,14 +76,14 @@ setting of `org-html-htmlize-output-type' is 'css."
(latex-environment . org-org-identity)
(latex-fragment . org-org-identity)
(line-break . org-org-identity)
- (link . org-org-identity)
+ (link . org-org-link)
(node-property . org-org-identity)
+ (template . org-org-template)
(paragraph . org-org-identity)
(plain-list . org-org-identity)
(planning . org-org-identity)
(property-drawer . org-org-identity)
(quote-block . org-org-identity)
- (quote-section . org-org-identity)
(radio-target . org-org-identity)
(section . org-org-section)
(special-block . org-org-identity)
@@ -135,15 +133,52 @@ CONTENTS is its contents, as a string or nil. INFO is ignored."
(defun org-org-keyword (keyword contents info)
"Transcode KEYWORD element back into Org syntax.
-CONTENTS is nil. INFO is ignored. This function ignores
-keywords targeted at other export back-ends."
- (unless (member (org-element-property :key keyword)
- (mapcar
- (lambda (block-cons)
- (and (eq (cdr block-cons) 'org-element-export-block-parser)
- (car block-cons)))
- org-element-block-name-alist))
- (org-element-keyword-interpreter keyword nil)))
+CONTENTS is nil. INFO is ignored."
+ (let ((key (org-element-property :key keyword)))
+ (unless (member key
+ '("AUTHOR" "CREATOR" "DATE" "EMAIL" "OPTIONS" "TITLE"))
+ (org-element-keyword-interpreter keyword nil))))
+
+(defun org-org-link (link contents info)
+ "Transcode LINK object back into Org syntax.
+CONTENTS is the description of the link, as a string, or nil.
+INFO is a plist containing current export state."
+ (or (org-export-custom-protocol-maybe link contents 'org)
+ (org-element-link-interpreter link contents)))
+
+(defun org-org-template (contents info)
+ "Return Org document template with document keywords.
+CONTENTS is the transcoded contents string. INFO is a plist used
+as a communication channel."
+ (concat
+ (and (plist-get info :time-stamp-file)
+ (format-time-string "# Created %Y-%m-%d %a %H:%M\n"))
+ (org-element-normalize-string
+ (mapconcat #'identity
+ (org-element-map (plist-get info :parse-tree) 'keyword
+ (lambda (k)
+ (and (string-equal (org-element-property :key k) "OPTIONS")
+ (concat "#+OPTIONS: "
+ (org-element-property :value k)))))
+ "\n"))
+ (and (plist-get info :with-title)
+ (format "#+TITLE: %s\n" (org-export-data (plist-get info :title) info)))
+ (and (plist-get info :with-date)
+ (let ((date (org-export-data (org-export-get-date info) info)))
+ (and (org-string-nw-p date)
+ (format "#+DATE: %s\n" date))))
+ (and (plist-get info :with-author)
+ (let ((author (org-export-data (plist-get info :author) info)))
+ (and (org-string-nw-p author)
+ (format "#+AUTHOR: %s\n" author))))
+ (and (plist-get info :with-email)
+ (let ((email (org-export-data (plist-get info :email) info)))
+ (and (org-string-nw-p email)
+ (format "#+EMAIL: %s\n" email))))
+ (and (plist-get info :with-creator)
+ (org-string-nw-p (plist-get info :creator))
+ (format "#+CREATOR: %s\n" (plist-get info :creator)))
+ contents))
(defun org-org-section (section contents info)
"Transcode SECTION element back into Org syntax.
@@ -173,7 +208,8 @@ a communication channel."
(make-string (or (org-element-property :post-blank section) 0) ?\n)))
;;;###autoload
-(defun org-org-export-as-org (&optional async subtreep visible-only ext-plist)
+(defun org-org-export-as-org
+ (&optional async subtreep visible-only body-only ext-plist)
"Export current buffer to an Org buffer.
If narrowing is active in the current buffer, only export its
@@ -192,6 +228,9 @@ 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 document
+keywords from output.
+
EXT-PLIST, when provided, is a property list with external
parameters overriding Org default settings, but still inferior to
file-local settings.
@@ -201,10 +240,11 @@ be displayed when `org-export-show-temporary-export-buffer' is
non-nil."
(interactive)
(org-export-to-buffer 'org "*Org ORG Export*"
- async subtreep visible-only nil ext-plist (lambda () (org-mode))))
+ async subtreep visible-only body-only ext-plist (lambda () (org-mode))))
;;;###autoload
-(defun org-org-export-to-org (&optional async subtreep visible-only ext-plist)
+(defun org-org-export-to-org
+ (&optional async subtreep visible-only body-only ext-plist)
"Export current buffer to an org file.
If narrowing is active in the current buffer, only export its
@@ -223,6 +263,9 @@ 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 document
+keywords from output.
+
EXT-PLIST, when provided, is a property list with external
parameters overriding Org default settings, but still inferior to
file-local settings.
@@ -231,7 +274,7 @@ Return output file name."
(interactive)
(let ((outfile (org-export-output-file-name ".org" subtreep)))
(org-export-to-file 'org outfile
- async subtreep visible-only nil ext-plist)))
+ async subtreep visible-only body-only ext-plist)))
;;;###autoload
(defun org-org-publish-to-org (plist filename pub-dir)
@@ -251,12 +294,13 @@ Return output file name."
(html-ext (concat "." (or (plist-get plist :html-extension)
org-html-extension "html")))
(visitingp (find-buffer-visiting filename))
- (work-buffer (or visitingp (find-file filename)))
+ (work-buffer (or visitingp (find-file-noselect filename)))
newbuf)
- (font-lock-fontify-buffer)
- (show-all)
- (org-show-block-all)
- (setq newbuf (htmlize-buffer))
+ (with-current-buffer work-buffer
+ (font-lock-ensure)
+ (show-all)
+ (org-show-block-all)
+ (setq newbuf (htmlize-buffer)))
(with-current-buffer newbuf
(when org-org-htmlized-css-url
(goto-char (point-min))
@@ -265,10 +309,12 @@ Return output file name."
(replace-match
(format
"<link rel=\"stylesheet\" type=\"text/css\" href=\"%s\">"
- org-org-htmlized-css-url) t t)))
+ org-org-htmlized-css-url)
+ t t)))
(write-file (concat pub-dir (file-name-nondirectory filename) html-ext)))
(kill-buffer newbuf)
(unless visitingp (kill-buffer work-buffer)))
+ ;; FIXME: Why? Which buffer is this supposed to apply to?
(set-buffer-modified-p nil)))