From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.text.pandoc/22041 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: Cormac Relf Newsgroups: gmane.text.pandoc Subject: Re: Chapter TOC via filter? Date: Wed, 6 Feb 2019 17:40:54 -0800 (PST) Message-ID: <05cb8702-be42-4970-9a99-084e920b632b@googlegroups.com> References: <1bb6e5f4-04ce-4209-8223-f928f2943998@googlegroups.com> <4f0905e3-c55d-4d97-958c-8478ada10bcf@googlegroups.com> <6e119a06-0158-452e-84e3-b248a4efd4a6@googlegroups.com> Reply-To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="----=_Part_188_819391241.1549503654598" Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="248809"; mail-complaints-to="usenet@blaine.gmane.org" To: pandoc-discuss Original-X-From: pandoc-discuss+bncBDK6LDPPQ4GRBJ4Z53RAKGQEHTRWOVY-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Thu Feb 07 02:40:58 2019 Return-path: Envelope-to: gtp-pandoc-discuss@m.gmane.org Original-Received: from mail-ot1-f59.google.com ([209.85.210.59]) by blaine.gmane.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.89) (envelope-from ) id 1grYgU-0012YH-0f for gtp-pandoc-discuss@m.gmane.org; Thu, 07 Feb 2019 02:40:58 +0100 Original-Received: by mail-ot1-f59.google.com with SMTP id o8sf7940676otp.16 for ; Wed, 06 Feb 2019 17:40:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=20161025; h=sender:date:from:to:message-id:in-reply-to:references:subject :mime-version:x-original-sender:reply-to:precedence:mailing-list :list-id:list-post:list-help:list-archive:list-subscribe :list-unsubscribe; bh=kRTzLXmeMFDkfAs7lKbyZxtNZTEQ26iXCa2HrOZuqoE=; b=IZFt1G2MMhfZKZzzHhGOGMKlvkEe1KttstBOy0ppq3omvTOjpKtCALn8jSQpwqdEkf z6Ig07xl7/H9SDbjCk+SuVzWIeVvojNhAnBglQpCiUt3zU1TI+6J51fAVpbMB5PnEEYg 9io9ISNWtrnEtfIKbvwWKIG9UGMM6ugiGEHAYN8FMTOf5AAGUehbP/D7Ni4eJ0fSklRA Tgp73oiVXktsNp1a1D2CyX2Ck2QMG+X+2EcmtlNq+ANVn725gIXed3hdUoqk3pB1xpll bLnZ3SNdbuEuFgBUny1RXr2jJpDtoOX9l7WEyIOudpWmyE4NmfVAYIeXfafca1JMgl07 pdmA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=sender:x-gm-message-state:date:from:to:message-id:in-reply-to :references:subject:mime-version:x-original-sender:reply-to :precedence:mailing-list:list-id:x-spam-checked-in-group:list-post :list-help:list-archive:list-subscribe:list-unsubscribe; bh=kRTzLXmeMFDkfAs7lKbyZxtNZTEQ26iXCa2HrOZuqoE=; b=SvAeMdTk1JrPB9ifhSZctw6u2RN98sKvkH0FfjZBfPvEn32wgC/mFQmV5XcJiUabO9 FjVCHBv6SiKA2dOV0x5nt9a3b0okbyqJF3lCBvmGZ/JwO+0iT6KoOTzeeaxzFDE8PTlF vwDb40aJgdv3N3OIUPMT1B8HvqBIiwB7wypWRuDrSS1PHdWouqmXRYjgRbWDB6b+A3rP F5Th9C/vgIVnc4hq/qq1TlEqQh367CJe/b5fctzook6jarDFDgsH45o0TCPEYskoW313 w2ILA+vI6D2d/qP05odBuzsu0GKHnLVuaICcOEL+P3BNrj8SLTxncXE+sHZWyAZaeP+3 k9Xw== Original-Sender: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org X-Gm-Message-State: AHQUAuYLThyilW+IMVMIJXQ4++oKbvS3WSRQ6p6S/r7ozu0Q+pJvSWf2 uGHj75Jgkk7qKX0QzCjo7rw= X-Google-Smtp-Source: AHgI3IbnIFdCjLGsyCIlzgdSqIS7Yey85/om7q3n3e5I6LhHr5kRpT5jbqtiFVZH1yroggxezGEoTQ== X-Received: by 2002:a05:6830:104c:: with SMTP id b12mr169421otp.7.1549503656337; Wed, 06 Feb 2019 17:40:56 -0800 (PST) X-BeenThere: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Original-Received: by 2002:a54:4605:: with SMTP id p5ls342742oip.0.gmail; Wed, 06 Feb 2019 17:40:55 -0800 (PST) X-Received: by 2002:aca:df55:: with SMTP id w82mr476oig.6.1549503655318; Wed, 06 Feb 2019 17:40:55 -0800 (PST) In-Reply-To: X-Original-Sender: web-v7Sng7lNsVbsQp/K+IV0sw@public.gmane.org Precedence: list Mailing-list: list pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org; contact pandoc-discuss+owners-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org List-ID: X-Google-Group-Id: 1007024079513 List-Post: , List-Help: , List-Archive: , List-Unsubscribe: , Xref: news.gmane.org gmane.text.pandoc:22041 Archived-At: ------=_Part_188_819391241.1549503654598 Content-Type: multipart/alternative; boundary="----=_Part_189_1345089638.1549503654599" ------=_Part_189_1345089638.1549503654599 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable I have written something very similar that may be helpful. It wasn't for a= =20 ToC, but it does the visit-and-update-header-contents thing, and you could= =20 easily build a ToC as you go and insert it in a second pass. https://github.com/cormacrelf/dotfiles/blob/master/pandoc/filters/aglc-head= ers.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= =20 > holding a number to which you add 1 each time you encounter a new chapter= =20 > and then replace the "local" number at the chapter level with the value o= f=20 > this variable for each heading. > > BTW number incrementing in Lua is very old school: var =3D var + 1. > > > Den fre 11 jan. 2019 13:57 skrev Axel Rauschmayer >: > >> >> I haven't looked at this in detail, but I would have=20 >>> thought you could have extracted what you needed from=20 >>> the `numbering` part of a Sec, which is just=20 >>> a list of integers, e.g. 2, 4, 2.=20 >>> >>> If your top level header is parts, then the first=20 >>> number is the part, the second the chapter, the=20 >>> third the section. Then it's just a matter of=20 >>> converting the part to a roman numeral when the=20 >>> other numbers are absent, and otherwise ignoring=20 >>> the part and concatenating the other numbers=20 >>> with '.' between...=20 >>> >> >> The problem is that part numbers don=E2=80=99t affect chapter numbers: >> >> - I. Part 1 >> - Chapter 1 >> - Chapter 2 >> - II. Part 2 >> - Chapter 3 >> - Chapter 4 >> =20 >> The first part of my filter numbers Headers properly (to be used with=20 >> HTML and parts): >> >> - Visit Headers via a filter. >> - Per Header: >> - Update a counter (with one integer per content entity):=20 >> depending on the level of the Header, while correctly handling par= t numbers. >> - Prefix the Header=E2=80=99s content with the properly formatted = counter. >> =20 >> Given that I already track Headers and their numbers: >> >> - I just additionally keep a mapping from chapter IDs to a list of=20 >> the chapter=E2=80=99s Headers. >> - For the chapter TOC, I transform this list to nested bullet lists,= =20 >> in a second pass. >> =20 >> --=20 >> You received this message because you are subscribed to the Google Group= s=20 >> "pandoc-discuss" group. >> To unsubscribe from this group and stop receiving emails from it, send a= n=20 >> email to pandoc-discus...-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org . >> To post to this group, send email to pandoc-...-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org=20 >> . >> To view this discussion on the web visit=20 >> https://groups.google.com/d/msgid/pandoc-discuss/6e119a06-0158-452e-84e3= -b248a4efd4a6%40googlegroups.com=20 >> >> . >> For more options, visit https://groups.google.com/d/optout. >> > --=20 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 e= mail 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. ------=_Part_189_1345089638.1549503654599 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
I have written something very similar that may be hel= pful. It wasn't for a ToC, but it does the visit-and-update-header-cont= ents thing, and you could easily build a ToC as you go and insert it in a s= econd pass.

https://github.com/cormacrelf/dotf= iles/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 chap= ter numbers, basically a variable holding a number to which you add 1 each = time you encounter a new chapter and then replace the "local" num= ber at the chapter level with the value of this variable for each heading.<= div dir=3D"auto">
BTW number incrementing in Lua= is very old school: var =3D var + 1.


Den fre 11 jan. 2019 13:5= 7 skrev Axel Rauschmayer <raus...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>:

pandoc-discus...@googlegroups.com.
To post to this group, send email to pandoc-...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/pan= doc-discuss/6e119a06-0158-452e-84e3-b248a4efd4a6%40googlegroups.c= om.
For more options, visit https://groups.google.com= /d/optout.

--
You received this message because you are subscribed to the Google Groups &= quot;pandoc-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an e= mail to pand= oc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org.
To post to this group, send email to pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@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.co= m.
For more options, visit http= s://groups.google.com/d/optout.
------=_Part_189_1345089638.1549503654599-- ------=_Part_188_819391241.1549503654598--