[TableOfContents] Add a label option
By default no label is shown, but if one is set it is added as a <strong> before the table of contents, and the table of contents and label are wrapped together in a <div>.
The failing check continuous-integration/styleci/pr says
We were unable to access the repo or commit to analyze it.
So I don't think that is something that I can fix
…it is added as a
<strong>before the first item in the table of contents.
Which produces invalid HTML: https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/ul#technical_summary
Have you considered using the 'position' => 'placeholder' option instead? It allows much more flexibility, such as providing a heading (which could be made linkable thanks to the Heading Permalinks extension):
## Table of Contents
[TOC]
Have you considered using the
'position' => 'placeholder'option instead? It allows much more flexibility, such as providing a heading (which could be made linkable thanks to the Heading Permalinks extension):## Table of Contents [TOC]
I wanted the heading to be more clearly part of the TOC itself, so that is why I didn't have a placeholder. You can see how I'm using a label at https://scherzer.dev/Blog/20250429-attributes-on-constants in the sidebar
…it is added as a
\<strong\>before the first item in the table of contents.Which produces invalid HTML: https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/ul#technical_summary
Good point - what would you think of having a wrapping div when a label is requested?
<div class="table-of-contents-wrapper">
<strong>Table of Contents</strong>
<ul class="table-of-contents">
<li>...
</ul>
</div>
@colinodell I've fixed this so that the HTML is valid, but now this is a tiny BC break because of the new TableOfContentsWrapper class that I introduced. Is this BC break acceptable in a minor version? If not, I can turn TableOfContents into an interface so that there isn't a break