Browse Source

Allow mixed export of numbered and unnumbered sections in HTML

* lisp/org-html.el (org-export-as-html): Get local value of
org-export-with-section-numbers from the buffer's plist.  Deal
specially with the case the resulting value is an integer.
(org-html-level-start): New optional argument of the option plist used
instead of `org-export-with-section-numbers'.  Also deal specially
with the case that the value is an integer.

When `org-export-with-section-numbers' (or the buffer-local
:section-numbers option) is an integer, we now export the first NUM
levels of headings with numbers and lower-level headings without.
Lawrence Mitchell 14 years ago
parent
commit
9f57b8e85d
1 changed files with 18 additions and 6 deletions
  1. 18 6
      lisp/org-html.el

+ 18 - 6
lisp/org-html.el

@@ -1150,6 +1150,7 @@ PUB-DIR is set, use this as the publishing directory."
 	 (language    (plist-get opt-plist :language))
 	 (language    (plist-get opt-plist :language))
 	 (keywords    (plist-get opt-plist :keywords))
 	 (keywords    (plist-get opt-plist :keywords))
 	 (description (plist-get opt-plist :description))
 	 (description (plist-get opt-plist :description))
+	 (num         (plist-get opt-plist :section-numbers))
 	 (lang-words  nil)
 	 (lang-words  nil)
 	 (head-count  0) cnt
 	 (head-count  0) cnt
 	 (start       0)
 	 (start       0)
@@ -1355,7 +1356,7 @@ lang=\"%s\" xml:lang=\"%s\">
 				   (if (string-match quote-re0 txt)
 				   (if (string-match quote-re0 txt)
 				       (setq txt (replace-match "" t t txt)))
 				       (setq txt (replace-match "" t t txt)))
 				   (setq snumber (org-section-number level))
 				   (setq snumber (org-section-number level))
-				   (if org-export-with-section-numbers
+				   (if (and num (integerp num) (>= num level))
 				       (setq txt (concat snumber " " txt)))
 				       (setq txt (concat snumber " " txt)))
 				   (if (<= level (max umax umax-toc))
 				   (if (<= level (max umax umax-toc))
 				       (setq head-count (+ head-count 1)))
 				       (setq head-count (+ head-count 1)))
@@ -1591,7 +1592,7 @@ lang=\"%s\" xml:lang=\"%s\">
 	    (setq first-heading-pos (or first-heading-pos (point)))
 	    (setq first-heading-pos (or first-heading-pos (point)))
 	    (org-html-level-start level txt umax
 	    (org-html-level-start level txt umax
 				  (and org-export-with-toc (<= level umax))
 				  (and org-export-with-toc (<= level umax))
-				  head-count)
+				  head-count opt-plist)
 
 
 	    ;; QUOTES
 	    ;; QUOTES
 	    (when (string-match quote-re line)
 	    (when (string-match quote-re line)
@@ -1684,7 +1685,7 @@ lang=\"%s\" xml:lang=\"%s\">
 
 
       (org-html-level-start 1 nil umax
       (org-html-level-start 1 nil umax
 			    (and org-export-with-toc (<= level umax))
 			    (and org-export-with-toc (<= level umax))
-			    head-count)
+			    head-count opt-plist)
       ;; the </div> to close the last text-... div.
       ;; the </div> to close the last text-... div.
       (when (and (> umax 0) first-heading-pos) (insert "</div>\n"))
       (when (and (> umax 0) first-heading-pos) (insert "</div>\n"))
 
 
@@ -2330,7 +2331,7 @@ If there are links in the string, don't modify these."
   (insert (if (equal type "d") "</dd>\n" "</li>\n")))
   (insert (if (equal type "d") "</dd>\n" "</li>\n")))
 
 
 (defvar body-only) ; dynamically scoped into this.
 (defvar body-only) ; dynamically scoped into this.
-(defun org-html-level-start (level title umax with-toc head-count)
+(defun org-html-level-start (level title umax with-toc head-count &optional opt-plist)
   "Insert a new level in HTML export.
   "Insert a new level in HTML export.
 When TITLE is nil, just close all open levels."
 When TITLE is nil, just close all open levels."
   (org-close-par-maybe)
   (org-close-par-maybe)
@@ -2341,6 +2342,7 @@ When TITLE is nil, just close all open levels."
 	 (preferred (and target
 	 (preferred (and target
 			 (cdr (assoc target org-export-preferred-target-alist))))
 			 (cdr (assoc target org-export-preferred-target-alist))))
 	 (l org-level-max)
 	 (l org-level-max)
+	 (num (plist-get opt-plist :section-numbers))
 	 snumber snu href suffix)
 	 snumber snu href suffix)
     (setq extra-targets (remove (or preferred target) extra-targets))
     (setq extra-targets (remove (or preferred target) extra-targets))
     (setq extra-targets
     (setq extra-targets
@@ -2395,10 +2397,20 @@ When TITLE is nil, just close all open levels."
 	(setq snumber (org-section-number level)
 	(setq snumber (org-section-number level)
 	      snu (replace-regexp-in-string "\\." "_" snumber))
 	      snu (replace-regexp-in-string "\\." "_" snumber))
 	(setq level (+ level org-export-html-toplevel-hlevel -1))
 	(setq level (+ level org-export-html-toplevel-hlevel -1))
-	(if (and org-export-with-section-numbers (not body-only))
+	(if (and num (not body-only))
 	    (setq title (concat
 	    (setq title (concat
 			 (format "<span class=\"section-number-%d\">%s</span>"
 			 (format "<span class=\"section-number-%d\">%s</span>"
-				 level snumber)
+				 level
+				 (if (and (integerp num)
+					  ;; fix up num to take into
+					  ;; account the top-level
+					  ;; heading value
+					  (>= (+ num
+						 org-export-html-toplevel-hlevel
+						 -1)
+					      level))
+					   snumber
+					 ""))
 			 " " title)))
 			 " " title)))
 	(unless (= head-count 1) (insert "\n</div>\n"))
 	(unless (= head-count 1) (insert "\n</div>\n"))
 	(setq href (cdr (assoc (concat "sec-" snu) org-export-preferred-target-alist)))
 	(setq href (cdr (assoc (concat "sec-" snu) org-export-preferred-target-alist)))