summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Goaziou <mail@nicolasgoaziou.fr>2017-11-20 14:07:03 +0100
committerNicolas Goaziou <mail@nicolasgoaziou.fr>2017-11-20 14:07:03 +0100
commit7455f4bf83635e472104597e67f80c43f70ad051 (patch)
tree5227e1af59000ade78669715f01b6d7002c8439d
parentd788d1b00eaeccba28cce361577c54e13466b94a (diff)
downloadorg-mode-7455f4bf83635e472104597e67f80c43f70ad051.tar.gz
ox: Allow a less strict UNNUMBERED inheritance
* lisp/ox.el (org-export-collect-headlines): (org-export-excluded-from-toc-p): Allow to number headlines in the middle of an otherwise unnumbered tree. * testing/lisp/test-ox.el (test-org-export/collect-headlines): (test-org-export/excluded-from-toc-p): (test-org-export/toc-entry-backend): Update tests. Add more tests. Reported-by: Akater <nuclearspace@gmail.com> <http://lists.gnu.org/archive/html/emacs-orgmode/2017-11/msg00219.html>
-rw-r--r--lisp/ox.el17
-rw-r--r--testing/lisp/test-ox.el30
2 files changed, 30 insertions, 17 deletions
diff --git a/lisp/ox.el b/lisp/ox.el
index d6add0a..7ab4128 100644
--- a/lisp/ox.el
+++ b/lisp/ox.el
@@ -5225,16 +5225,14 @@ Footnote sections are ignored."
(n (if (not (wholenump n)) limit
(min (if (eq (org-element-type scope) 'org-data) n
(+ (org-export-get-relative-level scope info) n))
- limit)))
- (skipped nil))
+ limit))))
(org-element-map (org-element-contents scope) 'headline
(lambda (h)
- (if (or (org-element-property :footnote-section-p h)
- (equal "notoc" (org-element-property :UNNUMBERED h))
- (memq (org-element-property :parent h) skipped)
- (< n (org-export-get-relative-level h info)))
- (progn (push h skipped) nil)
- h))
+ (and (not (org-element-property :footnote-section-p h))
+ (not (equal "notoc"
+ (org-export-get-node-property :UNNUMBERED h t)))
+ (>= n (org-export-get-relative-level h info))
+ h))
info)))
(defun org-export-collect-elements (type info &optional predicate)
@@ -5299,8 +5297,7 @@ contents. However, it is useful if some additional processing is
required on headlines excluded from table of contents."
(or (org-element-property :footnote-section-p headline)
(org-export-low-level-p headline info)
- (cl-some (lambda (h) (equal "notoc" (org-element-property :UNNUMBERED h)))
- (org-element-lineage headline nil t))))
+ (equal "notoc" (org-export-get-node-property :UNNUMBERED headline t))))
(defun org-export-toc-entry-backend (parent &rest transcoders)
"Return an export back-end appropriate for table of contents entries.
diff --git a/testing/lisp/test-ox.el b/testing/lisp/test-ox.el
index 74ac2de..d88d7e3 100644
--- a/testing/lisp/test-ox.el
+++ b/testing/lisp/test-ox.el
@@ -4318,13 +4318,18 @@ Another text. (ref:text)
(org-export-collect-headlines info))))))
;; Do not collect headlines with UNNUMBERED property set to "notoc".
;; Headlines with another value for the property are still
- ;; collected.
+ ;; collected. UNNUMBERED property is inherited.
(should
(equal '("H1")
(org-test-with-parsed-data
"* H1\n* H2\n:PROPERTIES:\n:UNNUMBERED: notoc\n:END:"
(mapcar (lambda (h) (org-element-property :raw-value h))
(org-export-collect-headlines info)))))
+ (should-not
+ (org-test-with-parsed-data
+ "* H1\n:PROPERTIES:\n:UNNUMBERED: notoc\n:END:\n** H2"
+ (mapcar (lambda (h) (org-element-property :raw-value h))
+ (org-export-collect-headlines info))))
(should
(equal '("H1" "H2")
(org-test-with-parsed-data
@@ -4348,17 +4353,28 @@ Another text. (ref:text)
(ert-deftest test-org-export/excluded-from-toc-p ()
"Test `org-export-excluded-from-toc-p' specifications."
+ ;; By default, headlines are not excluded.
(should-not
(org-test-with-parsed-data "* H1"
(org-element-map tree 'headline
(lambda (h) (org-export-excluded-from-toc-p h info)) info t)))
+ ;; Exclude according to a maximum level.
+ (should
+ (equal '(in out)
+ (org-test-with-parsed-data "#+OPTIONS: H:1\n* H1\n** H2"
+ (org-element-map tree 'headline
+ (lambda (h) (if (org-export-excluded-from-toc-p h info) 'out 'in))
+ info))))
+ ;; Exclude according to UNNUMBERED property.
(should
(org-test-with-parsed-data "* H1\n:PROPERTIES:\n:UNNUMBERED: notoc\n:END:"
(org-element-map tree 'headline
(lambda (h) (org-export-excluded-from-toc-p h info)) info t)))
+ ;; UNNUMBERED property is inherited, so is "notoc" value.
(should
- (equal '(in out)
- (org-test-with-parsed-data "#+OPTIONS: H:1\n* H1\n** H2"
+ (equal '(out out)
+ (org-test-with-parsed-data
+ "* H1\n:PROPERTIES:\n:UNNUMBERED: notoc\n:END:\n** H2"
(org-element-map tree 'headline
(lambda (h) (if (org-export-excluded-from-toc-p h info) 'out 'in))
info)))))
@@ -4427,10 +4443,10 @@ Another text. (ref:text)
(let (org-export-registered-backends)
(org-export-define-backend 'test
'((headline . (lambda (h _c i) (org-export-data-with-backend
- (org-element-property :title h)
- (org-export-toc-entry-backend 'test
- '(bold . (lambda (_b c _i) c)))
- i)))))
+ (org-element-property :title h)
+ (org-export-toc-entry-backend 'test
+ '(bold . (lambda (_b c _i) c)))
+ i)))))
(org-export-as 'test))))))