emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Sacha Chua <sacha@sachachua.com>
To: emacs-orgmode@gnu.org
Subject: Re: TOC local for specified heading and its subheadings (in HTML export)?
Date: Fri, 27 Nov 2015 23:58:17 -0500	[thread overview]
Message-ID: <86si3qra8m.fsf@sachachua.com> (raw)
In-Reply-To: CAGN11+1XS5hA8z8Y7AB7ckWy+TRdn5A6K2AP8FAg-1eHcRCY-g@mail.gmail.com

"D. C. Toedt" <dc@toedt.com> writes:

Hello, D. C., all!

> # ============= The next line is the desired feature: Generate a TOC list
> (with links) of all subheadings in the specified heading
> =====================
> #+TOC: headlines 1 local ConfInfoClauses

This is totally a partial implementation since I've only bothered to
make it work for HTML export, but someone can make it work nicely for
everything else. =)

I think it will permit the use of lines like:

#+TOC: headlines 1 id:ConfInfoClauses

diff --git a/lisp/ox-html.el b/lisp/ox-html.el
index effd387..3b0e239 100644
--- a/lisp/ox-html.el
+++ b/lisp/ox-html.el
@@ -2651,8 +2651,18 @@ CONTENTS is nil.  INFO is a plist holding contextual information."
 	 ((string-match "\\<headlines\\>" value)
 	  (let ((depth (and (string-match "\\<[0-9]+\\>" value)
 			    (string-to-number (match-string 0 value))))
-		(localp (org-string-match-p "\\<local\\>" value)))
-	    (org-html-toc depth info (and localp keyword))))
+		(localp (org-string-match-p "\\<local\\>" value))
+		(local-id (and (string-match "\\<id:\\(.+\\)\\>" value)
+			       (match-string 1 value))))
+	    (org-html-toc depth info
+			  (or
+			   (and local-id
+				(car (org-element-map (plist-get info :parse-tree)
+					 'headline
+				       (lambda (element)
+					 (and (string= (org-element-property :CUSTOM_ID element) local-id)
+					      element)))))
+			   (and localp keyword)))))
 	 ((string= "listings" value) (org-html-list-of-listings info))
 	 ((string= "tables" value) (org-html-list-of-tables info))))))))
 
D. C., are you okay with applying patches to your local copy, or do
you need someone to clean it up and merge it into core?

I have copyright assignment papers on file. Feel free to do what you
want with the code!

Sacha

  reply	other threads:[~2015-11-28  4:58 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-11-27 12:02 TOC local for specified heading and its subheadings (in HTML export)? D. C. Toedt
2015-11-28  4:58 ` Sacha Chua [this message]
2015-11-28 17:37   ` Sacha Chua
2015-11-28 19:16   ` Rasmus
2015-11-29 13:05     ` Nicolas Goaziou
2015-11-30  0:46     ` Sacha Chua

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=86si3qra8m.fsf@sachachua.com \
    --to=sacha@sachachua.com \
    --cc=emacs-orgmode@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).