emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [O] Generate a table of contents without exporting


From: Charles Berry
Subject: Re: [O] Generate a table of contents without exporting
Date: Tue, 1 Apr 2014 21:03:04 +0000 (UTC)
User-agent: Loom/3.14 (http://gmane.org/)

RG Williams <rgwills <at> gmail.com> writes:

> 
> Hi,
> I know you can generate a table of contents when exporting, but can you do
> it just within org? For context, I'm uploading an .org file to github and I
> don't need to export it to another format because github recognizes and
> displays it just fine. It's long so a ToC would be nice. Do I just have to
> write it myself?
> 
> 

AFAIK, you do have to write it yourself, but org-mode provides decent tools
for doing it. Here is an example. Run the src-block and a table of contents
will appear near the top. Change the content and rerun the src-block and
the t-o-c will change accordingly.

It doesn't deal with rules for omitting headlines like
COMMENT, :noexport:, etc, but if you are simply copying the .org file,
maybe it is good enough.


--8<---------------cut here---------------start------------->8---
#+RESULTS: Table_of_Contents

* h
lower H
* i
lower I
* j
lower J
** 1
one
** 2
two

#+NAME: Table_of_Contents
#+BEGIN_SRC emacs-lisp :wrap example
  (mapconcat 'identity
   (org-element-map 
       (org-element-parse-buffer 'headline) 'headline 
     (lambda (hl) (let
                      ((lev
                        (org-element-property :level hl)) 
                       (htitle (org-element-property :title hl)))
                    (concat (make-string  lev ? ) "- " htitle )))) "\n")
#+END_SRC
--8<---------------cut here---------------end--------------->8---


HTH,

Chuck




reply via email to

[Prev in Thread] Current Thread [Next in Thread]