I created a bookmarklet to generate a foldable table of contents (ToC) like the one shown above.
I hope it helps avid community members who write long texts!
I sometimes write long topics/posts and needed a ToC for easier reading.
I found some existing work, such as DiscoTOC - automatic table of contents, but I needed a tool just for me, not needing to install something across the community.
After publishing a structured post, click the bookmarklet, and the ToC will be copied to your clipboard. Edit the post and paste the ToC at the top!
How to use
Save a page as a bookmark.
Edit the name, such as “ Copy forum ToC to clipboard.”
Edit the URL and paste the following code. Customize the code if needed – see two “Optional” items below.
I love how you framed the problem you’re solving with this tool, and how it is designed to meet the needs of important users on sites who themselves may not have permissions to change things on the site itself as things exist today.
Another problem with creating TOC for replies is that it’s not easy to define what would be the heading title for each reply. We could use information like the author and the date, but I’m not sure how it’s more useful than the existing scrolling progress bar.
Hi @RBoy, thank you for the feedback and the suggestion!
An editor plugin would be great, but it’d be a lot of effort to read the source code of discourse to understand the logic of handling emojis and defining the heading/anchor text and create a repository of the plugin.
A (seemingly) simple plugin like Spoiler Alert is a big repo and I don’t have a bandwidth to fully commit to the development. So, I hope Discourse can prioritize feature requests like Automatic Table of Contents generation and develop an native feature in the meantime
Below is the version with the bullet points. The spaces between <ul> and <ul> are rather too large, so I preferred the original unbulleted version.
Yes, that’s the differentiation. I created the bookmarklet because I’m not in a position to decide which “theme-component” to install to the forum I’m usually in, and only a few people write long texts that need a TOC.
Unfortunately that plug-in totally unusable when the heading more then a few words long as it make a complete mess of things. If the headers are one or two lines long (for example a FAQ page) then the Disco TOC plug-in makes a complete mess of the page which is why I had raised this request for an inline TOC (which this one provides) and is perfect for such pages
With the amount of genius/talent amongst the teams who build discourse it shouldn’t be that hard to include this amazing feature as an alternative to DiscoTOC to give it a much wider range of use.