From a15a657bfb44f5b4380a8d69fc56bc4271a27f2e Mon Sep 17 00:00:00 2001 From: Nicolas Goaziou Date: Sun, 24 Feb 2013 09:15:26 +0100 Subject: [PATCH] ox: Better return value for `org-export-get-optional-title' * lisp/ox.el (org-export-get-optional-title): Return regular title when no optional title is found. * lisp/ox-ascii.el (org-ascii--build-title): Apply change to `org-export-get-optional-title'. * lisp/ox-html.el (org-html--format-toc-headline): Apply change to `org-export-get-optional-title'. * lisp/ox-latex.el (org-latex-headline): Apply change to `org-export-get-optional-title'. * testing/lisp/test-ox.el: Add tests. --- lisp/ox-ascii.el | 7 ++++--- lisp/ox-html.el | 4 +--- lisp/ox-latex.el | 4 +--- lisp/ox.el | 7 ++++--- testing/lisp/test-ox.el | 18 ++++++++++++++++++ 5 files changed, 28 insertions(+), 12 deletions(-) diff --git a/lisp/ox-ascii.el b/lisp/ox-ascii.el index dbb6123fa..11c711a5a 100644 --- a/lisp/ox-ascii.el +++ b/lisp/ox-ascii.el @@ -551,7 +551,7 @@ If optional argument NOTAGS is non-nil, no tags will be added to the title. When optional argument TOC is non-nil, use optional title if -possible." +possible. It doesn't apply to `inlinetask' elements." (let* ((headlinep (eq (org-element-type element) 'headline)) (numbers ;; Numbering is specific to headlines. @@ -565,8 +565,9 @@ possible." (text (org-trim (org-export-data - (or (and toc headlinep (org-export-get-optional-title element info)) - (org-element-property :title element)) info))) + (if (and toc headlinep) (org-export-get-optional-title element info) + (org-element-property :title element)) + info))) (todo (and (plist-get info :with-todo-keywords) (let ((todo (org-element-property :todo-keyword element))) diff --git a/lisp/ox-html.el b/lisp/ox-html.el index d9799094e..a76d8960f 100644 --- a/lisp/ox-html.el +++ b/lisp/ox-html.el @@ -1160,9 +1160,7 @@ INFO is a plist used as a communication channel." ;; Body. (concat section-number (org-export-data - (or (org-export-get-optional-title headline info) - (org-element-property :title headline)) - info) + (org-export-get-optional-title headline info) info) (and tags "   ") (org-html--tags tags))))) (defun org-html-toc (depth info) diff --git a/lisp/ox-latex.el b/lisp/ox-latex.el index 116bbeabd..188ce3951 100644 --- a/lisp/ox-latex.el +++ b/lisp/ox-latex.el @@ -1480,9 +1480,7 @@ holding contextual information." (funcall org-latex-format-headline-function todo todo-type priority (org-export-data - (or (org-export-get-optional-title headline info) - (org-element-property :title headline)) - info) + (org-export-get-optional-title headline info) info) (and (eq (plist-get info :with-tags) t) tags)))) (if (and opt-title (string-match "\\`\\\\\\(.*?\\){" section-fmt)) (format (replace-match "\\1[%s]" nil nil section-fmt 1) diff --git a/lisp/ox.el b/lisp/ox.el index 6d80d8789..996106368 100644 --- a/lisp/ox.el +++ b/lisp/ox.el @@ -3550,9 +3550,10 @@ fail, the fall-back value is \"???\"." (defun org-export-get-optional-title (headline info) "Return optional title for HEADLINE, as a secondary string. -INFO is a plist used as a communication channel. If no such -title is defined, return nil." - (org-element-property :optional-title headline)) +INFO is a plist used as a communication channel. If no optional +title is defined, fall-back to the regular title." + (or (org-element-property :optional-title headline) + (org-element-property :title headline))) (defun org-export-first-sibling-p (headline info) "Non-nil when HEADLINE is the first sibling in its sub-tree. diff --git a/testing/lisp/test-ox.el b/testing/lisp/test-ox.el index 1bf21ded9..876829ff1 100644 --- a/testing/lisp/test-ox.el +++ b/testing/lisp/test-ox.el @@ -1018,6 +1018,24 @@ Paragraph[fn:1]" ;; Otherwise, return it as a roman number. (should (equal (org-export-number-to-roman 1449) "MCDXLIX"))) +(ert-deftest test-org-export/get-optional-title () + "Test `org-export-get-optional-title' specifications." + ;; If OPTIONAL_TITLE property is defined, use it. + (should + (equal '("opt") + (org-test-with-parsed-data + "* Headline\n:PROPERTIES:\n:OPTIONAL_TITLE: opt\n:END:" + (org-export-get-optional-title + (org-element-map tree 'headline 'identity info t) + info)))) + ;; Otherwise, fall-back to regular title. + (should + (equal '("Headline") + (org-test-with-parsed-data "* Headline" + (org-export-get-optional-title + (org-element-map tree 'headline 'identity info t) + info))))) + (ert-deftest test-org-export/get-tags () "Test `org-export-get-tags' specifications." (let ((org-export-exclude-tags '("noexport")) -- 2.11.4.GIT