commonmark icon indicating copy to clipboard operation
commonmark copied to clipboard

[TableOfContents] Add a label option

Open DanielEScherzer opened this issue 8 months ago • 5 comments

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>.

DanielEScherzer avatar Apr 30 '25 04:04 DanielEScherzer

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

DanielEScherzer avatar Apr 30 '25 04:04 DanielEScherzer

…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

froschdesign avatar May 05 '25 12:05 froschdesign

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]

colinodell avatar May 05 '25 12:05 colinodell

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>

DanielEScherzer avatar May 05 '25 18:05 DanielEScherzer

@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

DanielEScherzer avatar Jul 08 '25 18:07 DanielEScherzer