DiscoTOC - automatic table of contents

If you check, I’ll think you’ll find it’s already been done. :slightly_smiling_face::+1:

But for anyone else wanting the swish new functionality, you can update the theme component from its customise page:

2 Likes

Hmmm, just thought of a scenario where a user doesn’t want to have a TOC in their topic, is there a way to revert that? :thinking:

1 Like

I like the tag element of it, so you could have a specific tag for TOC, and then remove it again if one is not desired?

2 Likes

I love the idea of automation, almost everytime and everywhere.

I haven’t updated DiscoTOC yet, but if it can take away option to insert TOC from toolbar when TOC comes from category it would be really nice touch. Like cherry top of the cake :wink:

Or, do opposite thing what @albert_vu asked — there would be an option insert something like !toc if you understand what I’m meaning.

For ordinary users it could be confusing, though.

I can live with that but TOC is quite unneeded when there is somethng like only one or two headers. Because when there is a TOC a long post must be scrolled to bottom to find out… what is it in discourse-lingo… well, possibility to scroll dates. But that is quite rare edge case I reckon.

4 Likes

What is the purpose of the anchor icon setting?
I could not find it anywhere. Was it removed in REFACTOR: General component overhaul (#19) · discourse/DiscoTOC@20366c6 · GitHub ?

1 Like

Awesome component! However I’ve found a bug in how it parses and renders TOC’s which contain escaped and certain characters.

For example it doesn’t render these headers correctly

### <a name="profilename">**[\<Profile Name\>]**</a>
### [\<Profile Name\>]
### \<encoder\>-general=\<general parameters\>

does it support generating the toc across the whole topic (not limited to the 1st post), like if I have a in-progress article that keeps updating with in one topic(by replying),will it work?

2 Likes

No, it only supports headings from the first post of a topic. (Additionally, as soon as another post is in view, the TOC disappears.)

3 Likes

Does the table of contents not work when headers are inside a div? I am trying to make a table of contents with the headers centered but it seems impossible to do.

1 Like

I think this was mentioned previously, if I understand it right:

4 Likes

So as far as I can tell basically there is no solution.

3 Likes

6 posts were split to a new topic: DiscoTOC option missing from gear icon menu

Is there a way to make the TOC ignore a header?

1 Like

If you don’t care about the semantic, you could create a data-h2 attribute or something like this on a span that mimics/extends the h2 style.

2 Likes

You can try my fix XD

As a non-latin language speaker, this theme component was not working well on my forum until I made some changes in javascripts/discourse/initializers/disco-toc-main.js

 headings.forEach((h, index) => {
              // suffix uses index for non-Latin languages
 ---             const suffix = slugify(h.textContent) || index;
 +++             const suffix = /*slugify(h.textContent) ||*/ index + "-salt-" + Math.round(Math.random() * 1145141919);
              const id =
                h.getAttribute("id") || slugify(`toc-${h.nodeName}-${suffix}`);

I used a huge random number instead of a title slug to make the link; it works fine in non-latin texts.

As you can see, it’s harder to get two titles confused than to win the lottery XD.

1 Like

For anyone who wants to apply DiscoTOC in their replies, I did this part of the work in my own fork!
Now it can apply TOC to any post and it works fine, just like it does on the OP.
It seems that the official team doesn’t think it’s necessary to apply DiscoTOC in the replies, so I won’t open a pull request. But you can use my modified version!

https://github.com/Lhcfl/DiscoTOC-edited

1 Like

It also happens to me that the TOC doesn’t work if the number of headings is less than three.

And I’d really appreciate it if the option “expand all” would be developed soon.