summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Goaziou <n.goaziou@gmail.com>2012-06-18 01:34:57 +0200
committerNicolas Goaziou <n.goaziou@gmail.com>2012-06-18 01:34:57 +0200
commit04ad4ab4171c17fb13e8e8210f250ecd3aabb4b6 (patch)
tree9ad8c11ad1d7fd8a02e3266fd7193ddc17ee96c8
parenta975751527096cf778f321843166b53c70e56c24 (diff)
downloadorg-mode-04ad4ab4171c17fb13e8e8210f250ecd3aabb4b6.tar.gz
org-export: Follow EXPORT_TITLE property when exporting subtree
* contrib/lisp/org-export.el (org-export-get-subtree-options): Make sure point is at an headline and buffer isn't narrowed before looking for EXPORT_TITLE property. * testing/lisp/test-org-export.el: Add test.
-rw-r--r--contrib/lisp/org-export.el44
-rw-r--r--testing/lisp/test-org-export.el16
2 files changed, 37 insertions, 23 deletions
diff --git a/contrib/lisp/org-export.el b/contrib/lisp/org-export.el
index 8e9374f..03d8c01 100644
--- a/contrib/lisp/org-export.el
+++ b/contrib/lisp/org-export.el
@@ -1111,29 +1111,29 @@ specific items to read, if any."
(defun org-export-get-subtree-options ()
"Get export options in subtree at point.
-
-Assume point is at subtree's beginning.
-
Return options as a plist."
- (let (prop plist)
- (when (setq prop (progn (looking-at org-todo-line-regexp)
- (or (save-match-data
- (org-entry-get (point) "EXPORT_TITLE"))
- (org-match-string-no-properties 3))))
- (setq plist
- (plist-put
- plist :title
- (org-element-parse-secondary-string
- prop (org-element-restriction 'keyword)))))
- (when (setq prop (org-entry-get (point) "EXPORT_TEXT"))
- (setq plist (plist-put plist :text prop)))
- (when (setq prop (org-entry-get (point) "EXPORT_AUTHOR"))
- (setq plist (plist-put plist :author prop)))
- (when (setq prop (org-entry-get (point) "EXPORT_DATE"))
- (setq plist (plist-put plist :date prop)))
- (when (setq prop (org-entry-get (point) "EXPORT_OPTIONS"))
- (setq plist (org-export-add-options-to-plist plist prop)))
- plist))
+ (org-with-wide-buffer
+ (let (prop plist)
+ ;; Make sure point is at an heading.
+ (unless (org-at-heading-p) (org-back-to-heading t))
+ (when (setq prop (progn (looking-at org-todo-line-regexp)
+ (or (save-match-data
+ (org-entry-get (point) "EXPORT_TITLE"))
+ (org-match-string-no-properties 3))))
+ (setq plist
+ (plist-put
+ plist :title
+ (org-element-parse-secondary-string
+ prop (org-element-restriction 'keyword)))))
+ (when (setq prop (org-entry-get (point) "EXPORT_TEXT"))
+ (setq plist (plist-put plist :text prop)))
+ (when (setq prop (org-entry-get (point) "EXPORT_AUTHOR"))
+ (setq plist (plist-put plist :author prop)))
+ (when (setq prop (org-entry-get (point) "EXPORT_DATE"))
+ (setq plist (plist-put plist :date prop)))
+ (when (setq prop (org-entry-get (point) "EXPORT_OPTIONS"))
+ (setq plist (org-export-add-options-to-plist plist prop)))
+ plist)))
(defun org-export-get-inbuffer-options (&optional backend files)
"Return current buffer export options, as a plist.
diff --git a/testing/lisp/test-org-export.el b/testing/lisp/test-org-export.el
index cb60db6..901eac5 100644
--- a/testing/lisp/test-org-export.el
+++ b/testing/lisp/test-org-export.el
@@ -253,6 +253,7 @@ text
(should (equal (org-export-as 'test nil 'visible) "* Head1\n"))
;; Body only.
(flet ((org-test-template (body info) (format "BEGIN\n%sEND" body)))
+ (push '(template . org-test-template) org-test-translate-alist)
(should (equal (org-export-as 'test nil nil 'body-only)
"* Head1\n** Head2\ntext\n*** Head3\n"))
(should (equal (org-export-as 'test)
@@ -277,7 +278,20 @@ text
#+END_SRC"
(org-test-with-backend test
(forward-line 1)
- (should (equal (org-export-as 'test 'subtree) ": 3\n")))))
+ (should (equal (org-export-as 'test 'subtree) ": 3\n"))))
+ ;; Subtree's EXPORT_TITLE property.
+ (org-test-with-backend test
+ (flet ((org-test-template (body info)
+ (org-export-data (plist-get info :title) info)))
+ (push '(template . org-test-template) org-test-translate-alist)
+ (org-test-with-temp-text "
+* Headline
+ :PROPERTIES:
+ :EXPORT_TITLE: subtree-title
+ :END:
+Paragraph"
+ (forward-line)
+ (should (equal "subtree-title" (org-export-as 'test 'subtree)))))))
(ert-deftest test-org-export/export-snippet ()
"Test export snippets transcoding."