public inbox archive for pandoc-discuss@googlegroups.com
 help / color / mirror / Atom feed
From: Cormac Relf <web-v7Sng7lNsVbsQp/K+IV0sw@public.gmane.org>
To: pandoc-discuss <pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
Subject: Re: Chapter TOC via filter?
Date: Wed, 6 Feb 2019 17:40:54 -0800 (PST)	[thread overview]
Message-ID: <05cb8702-be42-4970-9a99-084e920b632b@googlegroups.com> (raw)
In-Reply-To: <CADAJKhDkztkE+k35A4r4XuZJFoy9ivEm3=48YHkbdfNJbMYhrA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>


[-- Attachment #1.1: Type: text/plain, Size: 3655 bytes --]

I have written something very similar that may be helpful. It wasn't for a 
ToC, but it does the visit-and-update-header-contents thing, and you could 
easily build a ToC as you go and insert it in a second pass.

https://github.com/cormacrelf/dotfiles/blob/master/pandoc/filters/aglc-headers.lua

On Saturday, January 12, 2019 at 4:21:40 AM UTC+11, BP wrote:
>
> You need to keep a counter for the chapter numbers, basically a variable 
> holding a number to which you add 1 each time you encounter a new chapter 
> and then replace the "local" number at the chapter level with the value of 
> this variable for each heading.
>
> BTW number incrementing in Lua is very old school: var = var + 1.
>
>
> Den fre 11 jan. 2019 13:57 skrev Axel Rauschmayer <raus...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org 
> <javascript:>>:
>
>>
>> I haven't looked at this in detail, but I would have 
>>> thought you could have extracted what you needed from 
>>> the `numbering` part of a Sec, which is just 
>>> a list of integers, e.g. 2, 4, 2. 
>>>
>>> If your top level header is parts, then the first 
>>> number is the part, the second the chapter, the 
>>> third the section.  Then it's just a matter of 
>>> converting the part to a roman numeral when the 
>>> other numbers are absent, and otherwise ignoring 
>>> the part and concatenating the other numbers 
>>> with '.' between... 
>>>
>>
>> The problem is that part numbers don’t affect chapter numbers:
>>
>>    - I. Part 1
>>       - Chapter 1
>>       - Chapter 2
>>    - II. Part 2
>>       - Chapter 3
>>       - Chapter 4
>>    
>> The first part of my filter numbers Headers properly (to be used with 
>> HTML and parts):
>>
>>    - Visit Headers via a filter.
>>    - Per Header:
>>       - Update a counter (with one integer per content entity): 
>>       depending on the level of the Header, while correctly handling part numbers.
>>       - Prefix the Header’s content with the properly formatted counter.
>>    
>> Given that I already track Headers and their numbers:
>>
>>    - I just additionally keep a mapping from chapter IDs to a list of 
>>    the chapter’s Headers.
>>    - For the chapter TOC, I transform this list to nested bullet lists, 
>>    in a second pass.
>>    
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "pandoc-discuss" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to pandoc-discus...-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org <javascript:>.
>> To post to this group, send email to pandoc-...-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org 
>> <javascript:>.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/pandoc-discuss/6e119a06-0158-452e-84e3-b248a4efd4a6%40googlegroups.com 
>> <https://groups.google.com/d/msgid/pandoc-discuss/6e119a06-0158-452e-84e3-b248a4efd4a6%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>

-- 
You received this message because you are subscribed to the Google Groups "pandoc-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To post to this group, send email to pandoc-discuss-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/05cb8702-be42-4970-9a99-084e920b632b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

[-- Attachment #1.2: Type: text/html, Size: 5869 bytes --]

  parent reply	other threads:[~2019-02-07  1:40 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-01-07  4:10 Axel Rauschmayer
     [not found] ` <1bb6e5f4-04ce-4209-8223-f928f2943998-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
2019-01-07  4:11   ` Axel Rauschmayer
2019-01-09 14:29   ` Christophe Demko
     [not found]     ` <6fe9c4df-2625-4508-8608-da8499e81599-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
2019-01-09 14:58       ` Gareth Stockwell
2019-01-09 16:46   ` John MacFarlane
     [not found]     ` <m2va2xvkwl.fsf-pgq/RBwaQ+zq8tPRBa0AtqxOck334EZe@public.gmane.org>
2019-01-10 19:50       ` Axel Rauschmayer
     [not found]         ` <4f0905e3-c55d-4d97-958c-8478ada10bcf-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
2019-01-10 23:09           ` John MacFarlane
     [not found]             ` <yh480ka7k8155j.fsf-pgq/RBwaQ+zq8tPRBa0AtqxOck334EZe@public.gmane.org>
2019-01-10 23:58               ` Axel Rauschmayer
     [not found]                 ` <e9ec0801-2490-4119-88cd-74adbcd9afe6-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
2019-01-11  5:14                   ` John MacFarlane
     [not found]                     ` <m2o98nvkqc.fsf-pgq/RBwaQ+zq8tPRBa0AtqxOck334EZe@public.gmane.org>
2019-01-11 12:56                       ` Axel Rauschmayer
     [not found]                         ` <6e119a06-0158-452e-84e3-b248a4efd4a6-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
2019-01-11 17:21                           ` BPJ
     [not found]                             ` <CADAJKhDkztkE+k35A4r4XuZJFoy9ivEm3=48YHkbdfNJbMYhrA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2019-02-07  1:40                               ` Cormac Relf [this message]
2019-01-11 19:22                           ` John MacFarlane

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

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

  git send-email \
    --in-reply-to=05cb8702-be42-4970-9a99-084e920b632b@googlegroups.com \
    --to=web-v7sng7lnsvbsqp/k+iv0sw@public.gmane.org \
    --cc=pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.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.
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 NNTP newsgroup(s).