Moodle Plugins directory: Table of Contents Generator | Moodle.org
Table of Contents Generator
Table of Contents (TOC) Filter
2017 version
The Table of Contents filter scans pages for heading tags (like h1, h2, etc) and automatically generates a nested list of these tags as a table of contents. Each entry in the table is made into an html link to the actual heading.
The plugin has both global and local settings.
Global Settings
- Headings: you can nominate which headings tags you want the filter to look for (default: h1,h2,h3,h4)
- Search in divs: you can choose whether or not to look for headings tags located inside divs (default: yes)
- Backlink: you can choose whether or not to include a backlink at the end of the heading that links back to the TOC.
- TOC Title: you can nominate the title used in the TOC (default: Table of Contents)
- TOC Title Heading Tag: you can choose which heading tag is used for the TOC's title (default: 1)
Local Settings
(The local settings allow you to override the global settings on a per page basis.)
- Headings: you can nominate which headings tags you want the filter to look for
- TOC Title: you can nominate the title used in the TOC
- TOC Title Heading Tag: you can choose which heading tag is used for the TOC's title
Hiding Individual Headings
You can also hide specific headings from the TOC by wrapping the heading in a div with class="non-toc". For example,
<div class="non-toc">
<h1>Lesson 1 — Greco-Roman Civilisation</h1>
</div>
Location
By default, the location of the TOC is placed at the beginning of the page. However, you can nominate a different position by putting the string
[contents]
where you want the TOC to appear.
CSS
CSS styling may be used to modify the appearance of the table. The entire table is contained within a div with the 'toc' class. The backlinks have the class 'toc_link' applied to them. For example,
/* Hide bullets in TOCs */
.toc ul {
list-style: none;
}
(Add to the custom CSS field of your moodle theme.)
I am happy to announce that Ben Chenoweth became a new maintainer of this plugin and hopefully will be able to release an update for more recent Moodle versions soon. Good luck Ben, and thanks for your offer to maintain this!
[contents]
where you want the TOC to appear on the page itself.
/* Hide bullets in TOCs */
.toc ul {
list-style: none;
}
There are no bugs that I am aware. My only guess is that all of the headings on your page are h4 headings. So when you remove h4 from the settings, there are no headings left to generate a TOC.
We have one suggestion for that plugin.
As far as we use a custom theme, we need to style the "a" tags that support the table of content, so that vertical alignment is correct.
It would be great to a a specific class on "a" tags added in filter.php line (lines 78 et 80).
Kisses
Zabelle
Sorry, but I am no longer able to support this plugin. I am not currently working at a place that uses Moodle, so I cannot do the required testing of any changes made to the code. The code itself is located at https://github.com/benchen71/moodle-filter_toc.
https://github.com/benchen71/moodle-filter_toc/issues/5
Thank you for the patch.
Installed and tested on Moodle 4.1.3+ (Build: 20230602)
It is working as expected. Will update here and on Github if I see any issues.