From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.text.pandoc/24321 Path: news.gmane.io!.POSTED.ciao.gmane.io!not-for-mail From: BPJ Newsgroups: gmane.text.pandoc Subject: Re: Separate tables of contents for each section Date: Fri, 31 Jan 2020 21:31:15 +0100 Message-ID: References: <3d838861-862c-4b15-8d91-a9b37d671736@googlegroups.com> Reply-To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="0000000000003d6aae059d7575a9" Injection-Info: ciao.gmane.io; posting-host="ciao.gmane.io:159.69.161.202"; logging-data="77190"; mail-complaints-to="usenet@ciao.gmane.io" To: pandoc-discuss Original-X-From: pandoc-discuss+bncBCWMVYEK54FRBIE52LYQKGQEP7UH7AA-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Fri Jan 31 21:31:31 2020 Return-path: Envelope-to: gtp-pandoc-discuss@m.gmane-mx.org Original-Received: from mail-ot1-f56.google.com ([209.85.210.56]) by ciao.gmane.io with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1ixcwt-000K1k-2f for gtp-pandoc-discuss@m.gmane-mx.org; Fri, 31 Jan 2020 21:31:31 +0100 Original-Received: by mail-ot1-f56.google.com with SMTP id b21sf4154394otq.16 for ; Fri, 31 Jan 2020 12:31:31 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1580502690; cv=pass; d=google.com; s=arc-20160816; b=XsjOelJtjNYNH+6h+1mol1wwW/1RwlemR2z5ZopeePBn9KA7xQ7EPC2lhI9BITInWk 5Oes15MjYW2r4mXyyjqhZVR7AQ4jyTI3Q0kyq9gsyVx5WLlJVLJ69Fuam0odKc5j02d7 F9xXLVj2f1DhVbm9f78hVAC2zEuCVdopQaJtf5KAa7doCNOY1KzahYkbnRoxw3pShGy3 CdpRkJ/1Pcwq9jxcZOZ+n2x4asa0yBekFnOLiMazOtjmjE86K7IMyO3oMrr2QC6K8F1A Ohqhr9VrxSr3eJ8hFOC47kE2emQ/f11148rp7yPt0lYFpJXbSB+UC9exfhw1ElqZYlyU cI/g== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-unsubscribe:list-subscribe:list-archive:list-help:list-post :list-id:mailing-list:precedence:reply-to:to:subject:message-id:date :from:in-reply-to:references:mime-version:sender:dkim-signature :dkim-signature; bh=psa8EvTcTpQuqnSjKoFfZfFwOnRNpZmKqBUP/dbcW2g=; b=ZkMFa68DngAfZIBUoBCUzgIq64y4LLFnC6ujUiyx49RZkOT1wI1LUAKPQwP21WY7v4 9AtEvaEW0jnm5v2WFCv1xGpnc5uXq2i0lp4UWnF101YzYCLlroUugwqgKl8FPGe8bTL6 LDGlRshXdPXdpy3EXAeszGU3eSXAx31uh426gUW31ngFVt9v40LZtbwaFHHn/VNBJlsb 6VYRM+FlFly49t1rEYNTNhJNosRRYbZUV2SqB34HO2+TLj0REN537+InFEFI2ot0f1KK Gbwbzi+Twzkgol6CXhiW1/Mgigsuw4myrGYOpxQ3/5hvZPgaA0VfQZejzp9+BDsSTwzB boAQ== ARC-Authentication-Results: i=2; gmr-mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=GHuEBA2j; spf=pass (google.com: domain of melroch-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org designates 2607:f8b0:4864:20::231 as permitted sender) smtp.mailfrom=melroch-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=20161025; h=sender:mime-version:references:in-reply-to:from:date:message-id :subject:to:x-original-sender:x-original-authentication-results :reply-to:precedence:mailing-list:list-id:list-post:list-help :list-archive:list-subscribe:list-unsubscribe; bh=psa8EvTcTpQuqnSjKoFfZfFwOnRNpZmKqBUP/dbcW2g=; b=pShHTIsxWtes68Aql4CxQeQXZo5/qNGgphHL+VHviHBiKVJtClpHRzn20r9ugcKD6F qtQLsg7IUxoBZaZE/dkNCgoTyPetpXdyXjfRbQpZJtejXN1JgUmWUa7FN4spH2YlDzlX vrQwLScFkwWR2XceWoI/RYjSxv4nvOrTPZmNBrPEzNkP6s2lirDtu+em1CIfKSIET71I O9JnshfDuWZJfnmrOUx0ghA6rdJiGfl6p9M9Gq6ys29eg6mqROCKsmk1S9iB54mMlpwd nTsvDVomJY5fout5xXom7asRumoSHklQysTkBMTGoiYUexjrrXCHlEgpCYRU2PWYtR9k 7+yA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :x-original-sender:x-original-authentication-results:reply-to :precedence:mailing-list:list-id:list-post:list-help:list-archive :list-subscribe:list-unsubscribe; bh=psa8EvTcTpQuqnSjKoFfZfFwOnRNpZmKqBUP/dbcW2g=; b=gYIHYY/YzNOLSALeu0LKXzEnZfmMjjQu+BxzFGTiSC8UtzJiz2npr0K0OX9eQCR8v5 JhFUbQFWEyGvuRcq0Ybtc7C9RIDhF7nJ3IQwhPLpluUL+FGmkY/ZROIvemCrUyUWTy01 p8jmT5QbEXrgFZd0cZF0L5aLwzt0LUvpMzbYMk7aey8OC0VAX7f7bnnQ/HiFPfJMCKQW mVjlAUPdXsPVT67BE5BRhKQoClZVTIm7JP80iLyurHcJssKV3eZ/H6+UvX5Vf3iPOkrl b5qBCRk5z67Fd+zRyH2HVvEGPl54Tj7R2Mrs84maV6zmZleKvM9n1rG2VYME+E5BxjEw y6rw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=sender:x-gm-message-state:mime-version:references:in-reply-to:from :date:message-id:subject:to:x-original-sender :x-original-authentication-results:reply-to:precedence:mailing-list :list-id:x-spam-checked-in-group:list-post:list-help:list-archive :list-subscribe:list-unsubscribe; bh=psa8EvTcTpQuqnSjKoFfZfFwOnRNpZmKqBUP/dbcW2g=; b=L2HxXBc4YIiH5FU4vajptjhbL0ypQMOq97enrw66Pn6bDOs9l97XeXI4t0BQHjIPzp e6eiAkDTgyPZCBAuRmE148fNrik+eldFHDHvP/H1fePzgt15m1kJ+gqEHuPNFCMlZeei oALCMyW5P6Dps1rxAGosjMyAiqBBXOdF9yXiaOv1h7PZyZ8JpACI1Np0irQOUGCCPj7e wdbkwmscfCRu24SQUUAU5c0vhI1jpWyVucnQUErHxTJkMyL2l6faF+MvAbhOcRbaTD78 i/mrogIRt6cZnHo8+K11Xk11obIF7rRV4B/Yd7W+BepLsWEOs0o7JJbo8dwtixJ4miEy +t5w== Original-Sender: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org X-Gm-Message-State: APjAAAV5o6eEHQVJDkpIwd9lehovcz5/PXB+jJC9TXIkcKRnWAbd6XA5 fgT8COwxykFNIR28+B0jmFk= X-Google-Smtp-Source: APXvYqwtsnHQwfC2mQysPuWfSoO/k8KfKUZ5Cgh3aEm2KIPbjmXlz8FqID9nt65Y9x2aiBbE20gzrQ== X-Received: by 2002:aca:f1c2:: with SMTP id p185mr7644171oih.87.1580502690022; Fri, 31 Jan 2020 12:31:30 -0800 (PST) X-BeenThere: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Original-Received: by 2002:a05:6808:910:: with SMTP id w16ls711029oih.2.gmail; Fri, 31 Jan 2020 12:31:27 -0800 (PST) X-Received: by 2002:aca:36c1:: with SMTP id d184mr7484779oia.70.1580502687716; Fri, 31 Jan 2020 12:31:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1580502687; cv=none; d=google.com; s=arc-20160816; b=uBJ6nIwoo1QUK0yhOAFpjjuWcDIC5v0KUhCR7TYnufDip2dJ66gqaUdGIwpi6pCAXf lRVZRlvJpZOGfpCn3BehyWk8G9VctFu7wqZq/F4ZvqNIGuFfCZE9iR689HrWOkUcsoxm xBzl/ponLPSOh2ZIoCGX6xhEQEIY/SRoeoMfLaCAwpGKLdus6VuFQY28mycGTgsY7KOi uQKs8Dooyqd189pdq/aIUcTgqOoG8PQoop8Go4A37dlj+i/C2uoJWu6epeNwdBusFlcI nB0uqn7H5avc4uMLsGXC70aL69/34z6JfKPHoUN1ck2d10BeAdvje1XYLnS4r9HhbJC6 xiDA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=to:subject:message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=E+LQrZK/NfJn02TC/7X8gX0pjRgFQqDY1gG1BNVO3S8=; b=Kwu7+lcBYOFhgfJOLXnORnEUbCoFPKTy5/v3XDl5RXYuZF754d0H41OOIYnq1hovYV zxmyA+xRbsPbRwHKz4o5QNkXZWiB/4S714y0NbNb9uEWjX/jShMvI+VNeat/HdTHyQSw txMyqOZne1otIeYynbzaseH4t2T+FXPnDNbyYobB35KT8yayxXccCNtpi6g+IpkfucIk 5VOfDh+mgtDnzr/Y0SIKvPIeEXEg3D9GwcC+/uHOyN08LMq4I5mPbWoTPlsfn9TNx5H2 ifFc6x/MeNVPnRpbVS3ODgEj42YMFp7kUzajqdlhgN032QwxUzdIneXeNTZzzzE42dgg Yqpg== ARC-Authentication-Results: i=1; gmr-mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=GHuEBA2j; spf=pass (google.com: domain of melroch-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org designates 2607:f8b0:4864:20::231 as permitted sender) smtp.mailfrom=melroch-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Original-Received: from mail-oi1-x231.google.com (mail-oi1-x231.google.com. [2607:f8b0:4864:20::231]) by gmr-mx.google.com with ESMTPS id s10si344034oth.2.2020.01.31.12.31.27 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 31 Jan 2020 12:31:27 -0800 (PST) Received-SPF: pass (google.com: domain of melroch-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org designates 2607:f8b0:4864:20::231 as permitted sender) client-ip=2607:f8b0:4864:20::231; Original-Received: by mail-oi1-x231.google.com with SMTP id l9so4726791oii.5 for ; Fri, 31 Jan 2020 12:31:27 -0800 (PST) X-Received: by 2002:aca:a816:: with SMTP id r22mr7695886oie.1.1580502687245; Fri, 31 Jan 2020 12:31:27 -0800 (PST) In-Reply-To: <3d838861-862c-4b15-8d91-a9b37d671736-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> X-Original-Sender: melroch-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org X-Original-Authentication-Results: gmr-mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=GHuEBA2j; spf=pass (google.com: domain of melroch-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org designates 2607:f8b0:4864:20::231 as permitted sender) smtp.mailfrom=melroch-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com 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.io gmane.text.pandoc:24321 Archived-At: --0000000000003d6aae059d7575a9 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable I believe a change has been made so that Lua filters now traverse the document in linear order. If this is the case in the latest version of Pandoc it should be doable with a two-pass filter: first a pass which collects the headings and then a pass which inserts the TsoC. If you want hierarchical section numbering you probably also need to do a first pandoc run which inserts the numbering and then a second pandoc run with the filter to insert the TsoC. Something like this: (Warning 1: Untested code! Warning 2: Make sure not to overwrite any existing file! Warning 3: Assumes that all chapters are heading level 2 =E2=80=94 change= the chapter_level and toc_level variables to match! Warning 4: Assumes that each section/chapter has a unique identifier! ) local chapter_level =3D 2 local toc_level =3D 3 local headings =3D {} local current_chapter =3D nil local function collect_headings (head) if head.level =3D=3D chapter_level then local id =3D head.identifier current_chapter =3D { chapter =3D id toc =3D {} } headings[id] =3D current_chapter elseif head.level =3D toc_level then if current_chapter then local toc =3D current_chapter.toc toc[#toc+1] =3D head end end return nil end local function build_toc (heads) local toc =3D {} for _,head in ipairs(heads) do local entry =3D { pandoc.Plain{ pandoc.Link( head.content:clone(), -- text head.identifier, -- target "", -- empty title pandoc.Attr( "", -- empty identifier {'local-toc-link'} -- class ) ) } } toc[#toc+1] =3D entry end return pandoc.Div( { pandoc.BulletList(toc) }, pandoc.Attr( "", {'local-toc'} ) ) end local function insert_toc (head) if head.level =3D chapter_level then local id =3D head.identifier if headings[id] then local toc =3D build_toc( headings[id].toc ) return {head,toc} end end return nil end return { { Header =3D collect_headings }, { Header =3D insert_toc }, } Den fre 31 jan. 2020 19:27Szabolcs Horv=C3=A1t skrev: > Hello everyone, > > I am converting a Markdown file to HTML. > > I can insert a table of contents at the beginning using the --toc option. > > Is it possible to insert additional tables of contents under each > level-two or level-three heading? > > I am looking to create something similar to the organization of this page= : > https://igraph.org/c/doc/igraph-Visitors.html#idm209455316208 > > Szabolcs > > -- > 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 view this discussion on the web visit > https://groups.google.com/d/msgid/pandoc-discuss/3d838861-862c-4b15-8d91-= a9b37d671736%40googlegroups.com > > . > --=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 view this discussion on the web visit https://groups.google.com/d/msgid/= pandoc-discuss/CADAJKhBgy0rDop2EXuK_JP6YN6kTtwQ5UpU3HRwonZJh_Wapig%40mail.g= mail.com. --0000000000003d6aae059d7575a9 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
I believe a change has been made so that Lua filters now = traverse the document in linear order. If this is the case in the latest ve= rsion of Pandoc it should be doable with a two-pass filter: first a pass wh= ich collects the headings and then a pass which inserts the TsoC. If you wa= nt hierarchical section numbering you probably also need to do a first pand= oc run which inserts the numbering and then a second pandoc run with the fi= lter to insert the TsoC.=C2=A0 Something like this:

(Warning 1: Untested code!
=C2= =A0 Warning 2: Make sure not to overwrite any existing file!
=C2=A0 Warning 3: Assumes that all chapters are heading level 2 = =E2=80=94 change the chapter_level and toc_level variables to match!
<= div dir=3D"auto">=C2=A0 =C2=A0Warning 4: Assumes that each section/chapter = has a unique identifier!
)
local chapter_level =3D 2
=
local toc_level =3D 3
local headin= gs =3D {}
local current_chapter =3D nil

local function collect_headings (hea= d)
=C2=A0 if head.level =3D=3D chapter_level then
=C2=A0 =C2=A0 local id =3D head.identifier
=C2=A0 =C2=A0 current_chapter =3D {
=C2= =A0 =C2=A0 =C2=A0 chapter =3D id
=C2=A0 =C2=A0 =C2= =A0 toc =3D {}
=C2=A0 =C2=A0 }
=C2=A0 =C2=A0 headings[id] =3D current_chapter
=C2= =A0 elseif head.level =3D toc_level then
=C2=A0 =C2= =A0 if current_chapter then
=C2=A0 =C2=A0 =C2=A0 loc= al toc =3D current_chapter.toc
=C2=A0 =C2=A0 =C2=A0 = toc[#toc+1] =3D head
=C2=A0 =C2=A0 end
=C2=A0 end
=C2=A0 return nil
end

local func= tion build_toc (heads)
=C2=A0 local toc =3D {}
=
=C2=A0 for _,head in ipairs(heads) do
=C2=A0 =C2=A0 local entry =3D {
=C2=A0 =C2=A0 = =C2=A0 pandoc.Plain{
=C2=A0 =C2=A0 =C2=A0 =C2=A0 pan= doc.Link(
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 head.co= ntent:clone(), -- text
=C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 head.identifier, -- target
=C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 "", -- empty title
=C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 pandoc.Attr(
=C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 "", -- empty identifier
<= div dir=3D"auto">=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 {'local-toc-= link'} -- class
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 )
=C2=A0 =C2=A0 =C2=A0 =C2=A0 )
=C2=A0 =C2=A0 =C2=A0 }
=C2=A0 =C2=A0 }
<= div dir=3D"auto">=C2=A0 =C2=A0 toc[#toc+1] =3D entry
=C2=A0 end
=C2=A0 return pandoc.Div(
=C2=A0 =C2=A0 { pandoc.BulletList(toc) },
= =C2=A0 =C2=A0 pandoc.Attr( "", {'local-toc'} )
=C2=A0 )
end

local function insert_= toc (head)
=C2=A0 if head.level =3D chapter_level th= en
=C2=A0 =C2=A0 local id =3D head.identifier
<= div dir=3D"auto">=C2=A0 =C2=A0 if headings[id] then
= =C2=A0 =C2=A0 =C2=A0 local toc =3D build_toc(
=C2=A0= =C2=A0 =C2=A0 =C2=A0 headings[id].toc
=C2=A0 =C2=A0= =C2=A0 )
=C2=A0 =C2=A0 =C2=A0 return {head,toc}
=C2=A0 =C2=A0 end
=C2=A0 end
=C2=A0 return nil
end

return {
= =C2=A0 { Header =3D collect_headings },
=C2=A0 { Hea= der =3D insert_toc },
}

<= /div>

Den fre 31 jan. 2020 19:27Szabolcs Horv=C3=A1t <szhorvat-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> skrev:
Hello everyone,

I am converting a Markdown file to HTML.

I can in= sert a table of contents at the beginning using the --toc option.

Is it possible to insert additional tables of contents unde= r each level-two or level-three heading?

I am look= ing to create something similar to the organization of this page:=C2=A0https://igraph.org/c/doc/igraph-Visitors.ht= ml#idm209455316208

Szabolcs

--
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 pandoc-discuss+unsubscribe-/JYPxA39Uh4Ykp1iOSErHA@public.gmane.org= m.
To view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/3d838861-862c= -4b15-8d91-a9b37d671736%40googlegroups.com.

--
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 view this discussion on the web visit https://groups.= google.com/d/msgid/pandoc-discuss/CADAJKhBgy0rDop2EXuK_JP6YN6kTtwQ5UpU3HRwo= nZJh_Wapig%40mail.gmail.com.
--0000000000003d6aae059d7575a9--