Browse Source

ox-org: Improve keyword handling

* lisp/ox-org.el (org-org-template): New function.
(org-org-keyword): Handle document keywords specially.
Nicolas Goaziou 11 years ago
parent
commit
38a2bd3783
1 changed files with 56 additions and 10 deletions
  1. 56 10
      lisp/ox-org.el

+ 56 - 10
lisp/ox-org.el

@@ -87,6 +87,7 @@ setting of `org-html-htmlize-output-type' is 'css."
     (line-break . org-org-identity)
     (link . org-org-identity)
     (node-property . org-org-identity)
+    (template . org-org-template)
     (paragraph . org-org-identity)
     (plain-list . org-org-identity)
     (planning . org-org-identity)
@@ -140,16 +141,54 @@ CONTENTS is its contents, as a string or nil.  INFO is ignored."
   "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)))
+  (let ((key (org-element-property :key keyword)))
+    (unless (or (member key
+			(mapcar
+			 (lambda (block-cons)
+			   (and (eq (cdr block-cons)
+				    'org-element-export-block-parser)
+				(car block-cons)))
+			 org-element-block-name-alist))
+		(member key
+			'("AUTHOR" "CREATOR" "DATE" "DESCRIPTION" "EMAIL"
+			  "KEYWORDS" "TITLE")))
+      (org-element-keyword-interpreter keyword nil))))
+
+(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"))
+   (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 (eq (plist-get info :with-creator) t)
+	(org-string-nw-p (plist-get info :creator))
+	(format "#+CREATOR: %s\n" (plist-get info :creator)))
+   (and (org-string-nw-p (plist-get info :keywords))
+	(format "#+KEYWORDS: %s\n" (plist-get info :keywords)))
+   (and (org-string-nw-p (plist-get info :description))
+	(format "#+DESCRIPTION: %s\n" (plist-get info :description)))
+   contents
+   (and (eq (plist-get info :with-creator) 'comment)
+	(org-string-nw-p (plist-get info :creator))
+	(format "\n# %s\n" (plist-get info :creator)))))
 
 ;;;###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
@@ -168,6 +207,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.
@@ -177,10 +219,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
@@ -199,6 +242,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.