From c93a17dd8ade3a3feb13d89b663006d04f4f2c5a Mon Sep 17 00:00:00 2001 From: Nicolas Goaziou Date: Fri, 11 Nov 2016 10:05:20 +0100 Subject: [PATCH] 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. --- lisp/ox.el | 6 ++-- testing/lisp/test-ox.el | 70 ++++++++++++++++++++++++----------------- 2 files changed, 45 insertions(+), 31 deletions(-) diff --git a/lisp/ox.el b/lisp/ox.el index d3d1a0ed8..b6d844ae3 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 6a0123a27..e6bdb1d9e 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** 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\ntext\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 " +* Head1 #+BEGIN_SRC emacs-lisp :noweb yes :exports results <> #+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 " +* 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\ntext\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)