Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2020-11-28 11:10:45

gaekwad
Server grease monkey
From: People's Republic of Cornwall
Registered: 2005-11-19
Posts: 4,137
GitHub

How do you handle article table of contents?

Let’s say I have a single, long-form article with headings & subheadings in the body, with a placeholder for the table of contents (indents for clarity):

Lorem ipsum dolor sit amet, consectetur adipiscing elit.
(ToC here)
h2. Section 1
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
  h3. Subsection 1.1
  Lorem ipsum dolor sit amet, consectetur adipiscing elit.
h2. Section 2
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
  h3. Subsection 2.1
  Lorem ipsum dolor sit amet, consectetur adipiscing elit.
    h4. Subsection 2.1.1
    Lorem ipsum dolor sit amet, consectetur adipiscing elit.
h2. Section 3
Lorem ipsum dolor sit amet, consectetur adipiscing elit.

How would you go about building the ToC in a sustainable way (read: minimal work after the first publication) without doing it by hand? Is there a way to build one automatically with some tag voodoo? I can build one easily enough with a shell script but that’s a bit involved when you have text in a browser window.

I ask because I’ve been working on a client job that uses Google Docs extensively, and the ToC generator is really quite clever and saved a lot of work.

Please excuse any unintended entitlement, and also if I’ve missed a thread somewhere.

Offline

#2 2020-11-28 17:37:05

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 9,011
Website GitHub Mastodon Twitter

Re: How do you handle article table of contents?

There used to be a plugin for this many years ago. I remember that it was producing a list of anchored links based on the <h#> tags in the document.


Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.

Offline

#3 2020-11-28 17:44:58

gaekwad
Server grease monkey
From: People's Republic of Cornwall
Registered: 2005-11-19
Posts: 4,137
GitHub

Re: How do you handle article table of contents?

Thanks, Yiannis. I do have a veeeery vague memory of soo_toc but I haven’t tried it yet.

Offline

#4 2020-11-28 18:36:19

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 9,011
Website GitHub Mastodon Twitter

Re: How do you handle article table of contents?

gaekwad wrote #327140:

Thanks, Yiannis. I do have a veeeery vague memory of soo_toc but I haven’t tried it yet.

That was it! I found this which might be of help.


Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.

Offline

#5 2020-11-28 21:08:42

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 4,595
Website

Re: How do you handle article table of contents?

You could also do it with javascript, e.g. towboat, paged.js or using Chris Ferdinandi’s example (js is inline in the source) from his Vanilla JS Academy.


TXP Builders – finely-crafted code, design and txp

Offline

#6 2020-11-29 15:19:09

Destry
Member
From: Haut-Rhin
Registered: 2004-08-04
Posts: 4,909
Website

Re: How do you handle article table of contents?

I’ve explored contents lists a bit.

I can vouch soo_toc works good and automates list generation pretty well. I even turned it into a shortcode so I could set the heading level preference in a short tag on an article by article basis.

I can also vouch, per the link Colak gave, that etc_query can be used to create contents lists, but it’s easier for single level lists. However, this is a good way to go if you’re using a pageless section to store articles in and then collating those articles into a single larger document, which is really cool for big doc development. soo_toc won’t work in that case.

Finally, you can get custom numbered lists like that using CSS. My policies page is doing it, you can look at the styles there for an idea on the counting needed and whatnot. There’s also a thread around somewhere I started on that. Mind that list is done manually (if I recall) because it doesn’t change, but I would like to establish it as dynamic, and especially in context of pageless sections as mentioned, which would be useful in the future, so do share if you figure it out. ;)

Last edited by Destry (2020-11-29 15:27:19)

Offline

#7 2020-11-29 17:12:43

gaekwad
Server grease monkey
From: People's Republic of Cornwall
Registered: 2005-11-19
Posts: 4,137
GitHub

Re: How do you handle article table of contents?

Thanks, Julian and thanks, Destry – much appreciation for your input.

Offline

Board footer

Powered by FluxBB