From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.text.pandoc/32181 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Thomas Hodgson Newsgroups: gmane.text.pandoc Subject: Re: Customising toc in HTML Date: Wed, 15 Feb 2023 02:23:54 -0800 (PST) Message-ID: <9538ff1d-de89-4f74-92f1-d59a9028664bn@googlegroups.com> References: <6035b070-9f83-41e3-b392-5f6970e36757n@googlegroups.com> Reply-To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="----=_Part_922_1464634109.1676456634523" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="10966"; mail-complaints-to="usenet@ciao.gmane.io" To: pandoc-discuss Original-X-From: pandoc-discuss+bncBCEYTH5K2IARBPHFWKPQMGQEWYXYWBA-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Wed Feb 15 11:23:59 2023 Return-path: Envelope-to: gtp-pandoc-discuss@m.gmane-mx.org Original-Received: from mail-qv1-f60.google.com ([209.85.219.60]) by ciao.gmane.io with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1pSExD-0002e0-Du for gtp-pandoc-discuss@m.gmane-mx.org; Wed, 15 Feb 2023 11:23:59 +0100 Original-Received: by mail-qv1-f60.google.com with SMTP id f6-20020a0cc306000000b0056e96f4fd64sf7814997qvi.15 for ; Wed, 15 Feb 2023 02:23:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=20210112; h=list-unsubscribe:list-subscribe:list-archive:list-help:list-post :list-id:mailing-list:precedence:reply-to:x-original-sender :mime-version:subject:references:in-reply-to:message-id:to:from:date :sender:from:to:cc:subject:date:message-id:reply-to; bh=NjiuQQJR9eOdMf2HXiSePIolHDvCoU6yd/nzjLsfgKo=; b=pAHtCYMKkpPLA419PLhdraykn0WaFim11vjY/xD3Dok+kkKvXqAriKzqZhEU2cqVJK 2mOdxkqJkaKxaRVztyMpoZTw2H+XdjrvX+pqQ2B7IxPPnlcOWXnWCFZRnKiqYPC8nf5I moYU8HWrWZccoB+vmXzvZS96UifK5yDlMRvZsVo5DZfI6e4Z99ARTNcipF1ym2wpt7I/ 22+bJEACIkzdkfzJvLH3BTQcpSn6HhgFhjZD4L42nZx62COX075AqdBMvAPdNL7CuIPM 6rJOZaybOmICxr79Z4qvvry5cwaw+MzFD/fYnDe48PJ7qfzAaAXyfXY0a7EzCZZjM6mu zYxQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=list-unsubscribe:list-subscribe:list-archive:list-help:list-post :list-id:mailing-list:precedence:reply-to:x-original-sender :mime-version:subject:references:in-reply-to:message-id:to:from:date :from:to:cc:subject:date:message-id:reply-to; bh=NjiuQQJR9eOdMf2HXiSePIolHDvCoU6yd/nzjLsfgKo=; b=gQlYOoYgxyROJJU/beuWOcwqvLInA1lTCVcKGAlZfWzFlNrUV8QMwsHoM+mPWiBJgb gxx0iiqTAGipcxw0+6aaPW/SJ3cyFYOGwM4BCaIU7YBV/LIBdkyEhQBTB48Kw6eWUOGy QoNDbeZ0vbvMIbNiSYrRoqWqzIHASh0M6Y6xc5sDPhQT6wCP2fotqaK/KCOa3WkvwBkV mjJHJrS/e41KYNgEIUmKW3KmzQO7XfTHMvnKYJqaQxAVn7ajND7dvwu2KRIYTNIXZXyZ VMECicjs/38te6V0qPYRM/TgcxExzkPM4nWsuCtUsj8kdI3aXYpita4Yo7DF9saaKfh4 wm1w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=list-unsubscribe:list-subscribe:list-archive:list-help:list-post :x-spam-checked-in-group:list-id:mailing-list:precedence:reply-to :x-original-sender:mime-version:subject:references:in-reply-to :message-id:to:from:date:x-gm-message-state:sender:from:to:cc :subject:date:message-id:reply-to; bh=NjiuQQJR9eOdMf2HXiSePIolHDvCoU6yd/nzjLsfgKo=; b=l7AkecPSV1+CCS3gFcfnTCqsojlU3dFZc9REhaqojb/f9dptZoWMwSB5XyUFCgfnYF tszw2cUZl29xtibWtvT6aHxgcXqfHvAcVvYvbEjWcY7GdxF0n0Hl6Ewkx95hrgjS3TAh J8M2BRyF+eMLEtYW/SbHtDjMiNhjRXuYnLdCe1nkwt6diq+bq5ufqqQo7gOJ7eh/AjJ6 GmSBfBkntW9lF8nIAqWoPHJl6eH4hI92RqtZXh7fvZTeFvzYuuWggtTNtw0f/nctxUu7 +aomb+tNt3vNaq+0Y4AnbHp5YKrZzrCZ9D9mQWHLbECRuhs3kQPNmVvUGNCwknuFCJmw OFYg== Original-Sender: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org X-Gm-Message-State: AO0yUKXP9L0vNk613dCpEz/jDlfRBHi7pu6iw2GQibVRYkUttpmO58RL Suq7d0ssvN7ABjZ7oCn5nfw= X-Google-Smtp-Source: AK7set/P8ThACgecGPjRcSTQ3Xp1CQeV/AsF2UwaFOKJb93AZplC+4JQsGmgeWXbo2a0pXqNK/y6ew== X-Received: by 2002:a05:620a:16b3:b0:71c:e2b9:63b9 with SMTP id s19-20020a05620a16b300b0071ce2b963b9mr75176qkj.397.1676456638213; Wed, 15 Feb 2023 02:23:58 -0800 (PST) X-BeenThere: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Original-Received: by 2002:ac8:7d07:0:b0:3bc:fa01:de91 with SMTP id g7-20020ac87d07000000b003bcfa01de91ls1534130qtb.9.-pod-prod-gmail; Wed, 15 Feb 2023 02:23:55 -0800 (PST) X-Received: by 2002:ac8:104:0:b0:3b8:4adb:c602 with SMTP id e4-20020ac80104000000b003b84adbc602mr165250qtg.411.1676456635229; Wed, 15 Feb 2023 02:23:55 -0800 (PST) In-Reply-To: X-Original-Sender: thomas.hodgson-Re5JQEeQqe8AvxtiuMwx3w@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.io gmane.text.pandoc:32181 Archived-At: ------=_Part_922_1464634109.1676456634523 Content-Type: multipart/alternative; boundary="----=_Part_923_1170889313.1676456634523" ------=_Part_923_1170889313.1676456634523 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Thank you! I added an `if header.level =3D=3D 2` conditional, and it does exactly what= I=20 want. On Tuesday, 14 February 2023 at 16:26:38 UTC+1 Bastien DUMONT wrote: > You can use a filter to generate programmatically the content of=20 > table-of-contents. Here is a proof of concept (to be improved if you want= =20 > e.g. to take account of the header levels): > > ``` > local toc_inlines =3D {} > > local function feed_toc_inlines(header) > table.insert(toc_inlines, > pandoc.Span(pandoc.Link(header.content, '#' .. header.identifier))) > table.insert(toc_inlines, pandoc.RawInline('html', '\n')) > end > > local function set_metadata(meta) > meta['table-of-contents'] =3D toc_inlines > return meta > end > > return { > { Header =3D feed_toc_inlines }, > { Meta =3D set_metadata } > } > ``` > > However, I don't use HTML generation a lot=E2=80=94there may be a better = way. > > > Le Tuesday 14 February 2023 =C3=A0 05:20:59AM, Thomas Hodgson a =C3=A9cri= t : > > The best solution I have found is to put this in my metadata: > >=20 > > ``` > > table-of-contents: [Section=20 > one](#section-one)[Section two] > > (#section-two) > > ``` > >=20 > > Which works, but has to be updated by hand. > >=20 > > On Sunday, 12 February 2023 at 15:16:48 UTC+1 Thomas Hodgson wrote: > >=20 > > Hi, > >=20 > > I'm wondering whether there's a way to change the HTML for a table of > > contents. In particular, I'm wondering whether I could have something= =20 > like > > this, instead of a unordered list: > >=20 > > ``` > > > > ``` > >=20 > >=20 > > (I'm thinking about using <[1]https://readable-css.freedomtowrite.org/>= ,=20 > so > > I want the TOC to fit what will work with that.) > >=20 > > Tom > >=20 > > -- > > You received this message because you are subscribed to the Google Grou= ps > > "pandoc-discuss" group. > > To unsubscribe from this group and stop receiving emails from it, send= =20 > an email > > to [2]pandoc-discus...-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > To view this discussion on the web visit [3] > https://groups.google.com/d/msgid/ > > pandoc-discuss/b1b171d9-87c7-4bac-8ab4-a0473c401519n%40googlegroups.com= . > >=20 > > References: > >=20 > > [1] https://readable-css.freedomtowrite.org/ > > [2] mailto:pandoc-discus...-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org > > [3]=20 > https://groups.google.com/d/msgid/pandoc-discuss/b1b171d9-87c7-4bac-8ab4-= a0473c401519n%40googlegroups.com?utm_medium=3Demail&utm_source=3Dfooter > > --=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/9538ff1d-de89-4f74-92f1-d59a9028664bn%40googlegroups.com. ------=_Part_923_1170889313.1676456634523 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Thank you!

I added an `if header.level =3D= =3D 2` conditional, and it does exactly what I want.

On Tuesday, 14= February 2023 at 16:26:38 UTC+1 Bastien DUMONT wrote:
You can use a filter to generate = programmatically the content of table-of-contents. Here is a proof of conce= pt (to be improved if you want e.g. to take account of the header levels):

```
local toc_inlines =3D {}

local function feed_toc_inlines(header)
table.insert(toc_inlines,
pandoc.Span(pandoc.Link(header.content, '#' .. h= eader.identifier)))
table.insert(toc_inlines, pandoc.RawInline('html', '\n= 9;))
end

local function set_metadata(meta)
meta['table-of-contents'] =3D toc_inlines
return meta
end

return {
{ Header =3D feed_toc_inlines },
{ Meta =3D set_metadata }
}
```

However, I don't use HTML generation a lot=E2=80=94there may be a b= etter way.


Le Tuesday 14 February 2023 =C3=A0 05:20:59AM, Thomas Hodgson a =C3=A9c= rit :
> The best solution I have found is to put this in my metadata:
>=20
> ```
> table-of-contents: <span>[Section one](#section-one)</spa= n><span>[Section two]
> (#section-two)</span>
> ```
>=20
> Which works, but has to be updated by hand.
>=20
> On Sunday, 12 February 2023 at 15:16:48 UTC+1 Thomas Hodgson wrote= :
>=20
> Hi,
>=20
> I'm wondering whether there's a way to change the HTML= for a table of
> contents. In particular, I'm wondering whether I could hav= e something like
> this, instead of a unordered list:
>=20
> ```
> <nav>
> <span><a href=3D"#section-one">Section o= ne</a></span>
> <span><a href=3D"#section-two">Section t= wo</a></span>
> </nav>
> ```
>=20
>=20
> (I'm thinking about using <[1]https://readable-css.freedomtowrite.org/= >, so
> I want the TOC to fit what will work with that.)
>=20
> Tom
>=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 email
> to [2]pandoc-discus...@= googlegroups.com.
> To view this discussion on the web visit [3]https://groups.google.com/d/msgid/
> pandoc-discuss/b1b171d9-87c7-4bac-8ab4-a0473c401519n%40googlegroups.com.
>=20
> References:
>=20
> [1] ht= tps://readable-css.freedomtowrite.org/
> [2] mailto:pandoc-discu= s...-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
> [3] https://gro= ups.google.com/d/msgid/pandoc-discuss/b1b171d9-87c7-4bac-8ab4-a0473c401519n= %40googlegroups.com?utm_medium=3Demail&utm_source=3Dfooter

--
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/9538ff1d-de89-4f74-92f1-d59a9028664bn%40googlegroups.= com.
------=_Part_923_1170889313.1676456634523-- ------=_Part_922_1464634109.1676456634523--