summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Goaziou <mail@nicolasgoaziou.fr>2016-11-11 10:05:20 +0100
committerNicolas Goaziou <mail@nicolasgoaziou.fr>2016-11-11 10:17:15 +0100
commitc93a17dd8ade3a3feb13d89b663006d04f4f2c5a (patch)
tree86ac8b2575c812c4c3a9da4be693546074858d4f
parentefcaff3688105bf2ba6c1ebac4380d67a550d9b6 (diff)
downloadorg-mode-c93a17dd8ade3a3feb13d89b663006d04f4f2c5a.tar.gz
ox: Fix subtree export when starting with meta-data
* lisp/ox.el (org-export-as): Skip planning info and first property drawer when exporting a subtree. * testing/lisp/test-ox.el (test-org-export/export-scope): Add test.
-rw-r--r--lisp/ox.el6
-rw-r--r--testing/lisp/test-ox.el70
2 files changed, 45 insertions, 31 deletions
diff --git a/lisp/ox.el b/lisp/ox.el
index d3d1a0e..b6d844a 100644
--- a/lisp/ox.el
+++ b/lisp/ox.el
@@ -3003,14 +3003,14 @@ Return code as a string."
(save-excursion
(save-restriction
;; Narrow buffer to an appropriate region or subtree for
- ;; parsing. If parsing subtree, be sure to remove main headline
- ;; too.
+ ;; parsing. If parsing subtree, be sure to remove main
+ ;; headline, planning data and property drawer.
(cond ((org-region-active-p)
(narrow-to-region (region-beginning) (region-end)))
(subtreep
(org-narrow-to-subtree)
(goto-char (point-min))
- (forward-line)
+ (org-end-of-meta-data)
(narrow-to-region (point) (point-max))))
;; Initialize communication channel with original buffer
;; attributes, unavailable in its copy.
diff --git a/testing/lisp/test-ox.el b/testing/lisp/test-ox.el
index 6a0123a..e6bdb1d 100644
--- a/testing/lisp/test-ox.el
+++ b/testing/lisp/test-ox.el
@@ -878,34 +878,20 @@ Paragraph <2012-03-29 Thu>[2012-03-29 Thu]"
(ert-deftest test-org-export/export-scope ()
"Test all export scopes."
- (org-test-with-temp-text "
-* Head1
-** Head2
-text
-*** Head3"
- ;; Subtree.
- (forward-line 3)
- (should (equal (org-export-as (org-test-default-backend) 'subtree)
- "text\n*** Head3\n"))
- ;; Visible.
- (goto-char (point-min))
- (forward-line)
- (org-cycle)
- (should (equal (org-export-as (org-test-default-backend) nil 'visible)
- "* Head1\n"))
- ;; Region.
- (goto-char (point-min))
- (forward-line 3)
- (transient-mark-mode 1)
- (push-mark (point) t t)
- (goto-char (point-at-eol))
- (should (equal (org-export-as (org-test-default-backend)) "text\n")))
+ ;; Subtree.
+ (should
+ (equal "text\n*** H3\n"
+ (org-test-with-temp-text "* H1\n<point>** H2\ntext\n*** H3"
+ (org-export-as (org-test-default-backend) 'subtree))))
+ (should
+ (equal "text\n*** H3\n"
+ (org-test-with-temp-text "* H1\n** H2\n<point>text\n*** H3"
+ (org-export-as (org-test-default-backend) 'subtree))))
;; Subtree with a code block calling another block outside.
- (let ((org-export-babel-evaluate t))
- (should
- (equal ": 3\n"
- (org-test-with-temp-text "
-* Head1
+ (should
+ (equal ": 3\n"
+ (org-test-with-temp-text "
+<point>* Head1
#+BEGIN_SRC emacs-lisp :noweb yes :exports results
<<test>>
#+END_SRC
@@ -914,8 +900,36 @@ text
#+BEGIN_SRC emacs-lisp
\(+ 1 2)
#+END_SRC"
- (forward-line 1)
+ (let ((org-export-babel-evaluate t))
(org-export-as (org-test-default-backend) 'subtree)))))
+ ;; Subtree export should ignore leading planning line and property
+ ;; drawer.
+ (should
+ (equal "Text\n"
+ (org-test-with-temp-text "
+<point>* H
+SCHEDULED: <2012-03-29 Thu>
+:PROPERTIES:
+:A: 1
+:END:
+Text"
+ (org-export-as (org-test-default-backend)
+ 'subtree nil nil
+ '(:with-planning t :with-properties t)))))
+ ;; Visible.
+ (should
+ (equal "* H1\n"
+ (org-test-with-temp-text "* H1\n** H2\ntext\n*** H3"
+ (org-cycle)
+ (org-export-as (org-test-default-backend) nil 'visible))))
+ ;; Region.
+ (should
+ (equal "text\n"
+ (org-test-with-temp-text "* H1\n** H2\n<point>text\n*** H3"
+ (transient-mark-mode 1)
+ (push-mark (point) t t)
+ (end-of-line)
+ (org-export-as (org-test-default-backend)))))
;; Body only.
(let ((backend (org-test-default-backend)))
(setf (org-export-backend-transcoders backend)