From mboxrd@z Thu Jan 1 00:00:00 1970 From: Lawrence Mitchell Subject: [PATCH] Allow mixed export of numbered and unnumbered sections in HTML Date: Wed, 23 Mar 2011 09:38:18 +0000 Message-ID: References: <20110322051038.21655c80@kuru.homelinux.net> <80d3lj9wj6.fsf@somewhere.org> <20110322053134.669127e9@kuru.homelinux.net> <8999.1300804510@alphaville.dokosmarshall.org> <20110322160814.227fc53f@bhishma.homelinux.net> <27844.1300836065@alphaville.usa.hp.com> Mime-Version: 1.0 Content-Type: text/plain Return-path: Received: from [140.186.70.92] (port=60761 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Q2Kag-0004k5-FS for emacs-orgmode@gnu.org; Wed, 23 Mar 2011 05:43:00 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Q2Kae-0004Gg-SA for emacs-orgmode@gnu.org; Wed, 23 Mar 2011 05:42:58 -0400 Received: from lo.gmane.org ([80.91.229.12]:53228) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Q2Kae-0004GC-Fd for emacs-orgmode@gnu.org; Wed, 23 Mar 2011 05:42:56 -0400 Received: from list by lo.gmane.org with local (Exim 4.69) (envelope-from ) id 1Q2Kac-00004y-Ec for emacs-orgmode@gnu.org; Wed, 23 Mar 2011 10:42:54 +0100 Received: from e4300lm.epcc.ed.ac.uk ([129.215.63.156]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Wed, 23 Mar 2011 10:42:54 +0100 Received: from wence by e4300lm.epcc.ed.ac.uk with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Wed, 23 Mar 2011 10:42:54 +0100 List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: emacs-orgmode@gnu.org * 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. --- lisp/org-html.el | 24 ++++++++++++++++++------ 1 files changed, 18 insertions(+), 6 deletions(-) Nick Dokos wrote: > Suvayu Ali wrote: >> This works too, but Lawrence's patch makes it much easier and >> probably works for other export formats too. Thanks a lot. :) As Nick points out, each exporter backend needs a similar change. > No doubt Lawrence's patch can be extended to work for other exports, but > it's not there yet: each exporter would need a change similar to the one > that he made to the LaTeX exporter. Here's the matching change to the HTML exporter, which is the only other one I'm familiar with. Maintainers, if you don't want the special-casing on integerp, the change to move from `org-export-with-section-numbers' to (plist-get opt-plist :section-numbers) is the correct one anyway. I can split the patches if required. diff --git a/lisp/org-html.el b/lisp/org-html.el index b13fb93..06305f6 100644 --- a/lisp/org-html.el +++ b/lisp/org-html.el @@ -1150,6 +1150,7 @@ PUB-DIR is set, use this as the publishing directory." (language (plist-get opt-plist :language)) (keywords (plist-get opt-plist :keywords)) (description (plist-get opt-plist :description)) + (num (plist-get opt-plist :section-numbers)) (lang-words nil) (head-count 0) cnt (start 0) @@ -1355,7 +1356,7 @@ lang=\"%s\" xml:lang=\"%s\"> (if (string-match quote-re0 txt) (setq txt (replace-match "" t t txt))) (setq snumber (org-section-number level)) - (if org-export-with-section-numbers + (if (and num (integerp num) (>= num level)) (setq txt (concat snumber " " txt))) (if (<= level (max umax umax-toc)) (setq head-count (+ head-count 1))) @@ -1591,7 +1592,7 @@ lang=\"%s\" xml:lang=\"%s\"> (setq first-heading-pos (or first-heading-pos (point))) (org-html-level-start level txt umax (and org-export-with-toc (<= level umax)) - head-count) + head-count opt-plist) ;; QUOTES (when (string-match quote-re line) @@ -1684,7 +1685,7 @@ lang=\"%s\" xml:lang=\"%s\"> (org-html-level-start 1 nil umax (and org-export-with-toc (<= level umax)) - head-count) + head-count opt-plist) ;; the to close the last text-... div. (when (and (> umax 0) first-heading-pos) (insert "\n")) @@ -2330,7 +2331,7 @@ If there are links in the string, don't modify these." (insert (if (equal type "d") "\n" "\n"))) (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. When TITLE is nil, just close all open levels." (org-close-par-maybe) @@ -2341,6 +2342,7 @@ When TITLE is nil, just close all open levels." (preferred (and target (cdr (assoc target org-export-preferred-target-alist)))) (l org-level-max) + (num (plist-get opt-plist :section-numbers)) snumber snu href suffix) (setq extra-targets (remove (or preferred target) extra-targets)) (setq extra-targets @@ -2395,10 +2397,20 @@ When TITLE is nil, just close all open levels." (setq snumber (org-section-number level) snu (replace-regexp-in-string "\\." "_" snumber)) (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 (format "%s" - 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))) (unless (= head-count 1) (insert "\n\n")) (setq href (cdr (assoc (concat "sec-" snu) org-export-preferred-target-alist))) -- 1.7.4.rc2.18.gb20e9