Browse Source

org-export: Add `org-export-headline-numbered-p' predicate

* contrib/lisp/org-export.el (org-export-numbered-headline-p): New function.
* EXPERIMENTAL/org-e-ascii.el: Apply new function.
* EXPERIMENTAL/org-e-latex.el: Apply new function.
* testing/lisp/test-org-export.el: Add a test.
Nicolas Goaziou 13 years ago
parent
commit
73c5044963

+ 1 - 6
EXPERIMENTAL/org-e-ascii.el

@@ -585,12 +585,7 @@ title."
   (let* ((headlinep (eq (org-element-type element) 'headline))
 	 (numbers
 	  ;; Numbering is specific to headlines.
-	  (and headlinep
-	       ;; Section numbering must be active, and headline's
-	       ;; level should be above specified limit, if any.
-	       (let ((sec-num (plist-get info :section-numbers)))
-		 (if (not (wholenump sec-num)) sec-num
-		   (<= (org-export-get-relative-level headline info) sec-num)))
+	  (and headlinep (org-export-numbered-headline-p element info)
 	       ;; All tests passed: build numbering string.
 	       (concat
 		(mapconcat

+ 10 - 12
EXPERIMENTAL/org-e-latex.el

@@ -1072,8 +1072,7 @@ CONTENTS holds the contents of the headline.  INFO is a plist
 holding contextual information."
   (let* ((class (plist-get info :latex-class))
 	 (level (org-export-get-relative-level headline info))
-	 (numberedp (let ((sec-num (plist-get info :section-numbers)))
-		      (if (wholenump sec-num) (<= level sec-num) sec-num)))
+	 (numberedp (org-export-numbered-headline-p headline info))
 	 (class-sectionning (assoc class org-e-latex-classes))
 	 ;; Section formatting will set two placeholders: one for the
 	 ;; title and the other for the contents.
@@ -1095,8 +1094,7 @@ holding contextual information."
 	      (when numberedp (concat (car sec) "\n%s" (nth 1 sec))))
 	     ;; (num-in num-out no-num-in no-num-out)
 	     ((= (length sec) 4)
-	      (if numberedp
-		  (concat (car sec) "\n%s" (nth 1 sec))
+	      (if numberedp (concat (car sec) "\n%s" (nth 1 sec))
 		(concat (nth 2 sec) "\n%s" (nth 3 sec)))))))
 	 (text (org-export-secondary-string
 		(org-element-property :title headline) 'e-latex info))
@@ -1144,14 +1142,14 @@ holding contextual information."
 		(format "\\begin{%s}\n" (if numberedp 'enumerate 'itemize)))
 	      ;; Itemize headline
 	      "\\item " full-text "\n" headline-label pre-blanks contents)))
-	;; If headline in the last sibling, close the list, before any
-	;; blank line.  Otherwise, simply return LOW-LEVEL-BODY.
-	(if (org-export-last-sibling-p headline info)
-	    (replace-regexp-in-string
-	     "[ \t\n]*\\'"
-	     (format "\n\\\\end{%s}" (if numberedp 'enumerate 'itemize))
-	     low-level-body)
-	  low-level-body)))
+	;; If headline is not the last sibling simply return
+	;; LOW-LEVEL-BODY.  Otherwise, also close the list, before any
+	;; blank line.
+	(if (not (org-export-last-sibling-p headline info)) low-level-body
+	  (replace-regexp-in-string
+	   "[ \t\n]*\\'"
+	   (format "\n\\\\end{%s}" (if numberedp 'enumerate 'itemize))
+	   low-level-body))))
      ;; Case 3. Standard headline.  Export it as a section.
      (t (format section-fmt full-text
 		(concat headline-label pre-blanks contents))))))

+ 7 - 0
contrib/lisp/org-export.el

@@ -2601,6 +2601,13 @@ and the last level being considered as high enough, or nil."
 INFO is a plist holding contextual information."
   (cdr (assoc headline (plist-get info :headline-numbering))))
 
+(defun org-export-numbered-headline-p (headline info)
+  "Return a non-nil value if HEADLINE element should be numbered.
+INFO is a plist used as a communication channel."
+  (let ((sec-num (plist-get info :section-numbers))
+	(level (org-export-get-relative-level headline info)))
+    (if (wholenump sec-num) (<= level sec-num) sec-num)))
+
 (defun org-export-number-to-roman (n)
   "Convert integer N into a roman numeral."
   (let ((roman '((1000 . "M") (900 . "CM") (500 . "D") (400 . "CD")

+ 7 - 8
testing/lisp/test-org-export.el

@@ -57,11 +57,12 @@ as Org syntax."
    (equal
     (org-export-parse-option-keyword
      "arch:headline creator:comment d:(\"TEST\")
- ^:{} toc:1 tags:not-in-toc tasks:todo")
-    '(:with-archived-trees
-      headline :with-creator comment :with-drawers ("TEST")
-      :with-sub-superscript {} :with-toc 1 :with-tags not-in-toc
-      :with-tasks todo))))
+ ^:{} toc:1 tags:not-in-toc tasks:todo num:2")
+    '( :section-numbers
+       2
+       :with-archived-trees headline :with-creator comment
+       :with-drawers ("TEST") :with-sub-superscript {} :with-toc 1
+       :with-tags not-in-toc :with-tasks todo))))
 
 (ert-deftest test-org-export/get-inbuffer-options ()
   "Test reading all standard export keywords."
@@ -253,9 +254,7 @@ text
     (should (equal (buffer-string)
 		   "Small Org file with an include keyword.
 
-#+BEGIN_SRC emacs-lisp :exports results
-(+ 2 1)
-#+END_SRC
+#+BEGIN_SRC emacs-lisp :exports results\n(+ 2 1)\n#+END_SRC
 
 Success!