Download
We're evolving to serve you better! This current forum has transitioned to read-only mode. For new discussions, support, and engagement, we've moved to GitHub Discussions.

Variable depth in table of content generator

  • #5047
    Avatar photo[anonymous]

    It would be useful to be able to specify the depth (h2,h3) of headings that are included in a generated table of contents. Currently it appears to generate as much depth as you have in your content. This is not always the desired outcome.

    The TOC also appears broken in a couple of ways:

    • It generates numbered links. If your H2/H3 text already includes a number, then it appears twice.
    • It does not handle a missing level very elegantly, in my case it included extra, blank entries in the TOC due to a missing level (My text was going straight from H2 to H4 in some cases by design)

    Example of this is at:

    https://www.fullonecommerce.com/ecommerce-platform-shortlist.html

    #5048
    Avatar photoBob
    [anonymous] wrote:

    It generates numbered links. If your H2/H3 text already includes a number, then it appears twice.

    The table of contents generates links with text retrieved from the headings, so if the headings contain numbers, they will also appear in the TOC links – this is normal behavior.

    [anonymous] wrote:

    It does not handle a missing level very elegantly, in my case it included extra, blank entries in the TOC due to a missing level (My text was going straight from H2 to H4 in some cases by design)

    The outline level of the headings is incorrect, and the TOC based on that, displays empty items because it lacks the correct outline. Instead of using H4, use H3 heading with .h4 class:

    <h2>1. Dominant ecommerce platforms</h2>
    <h3 class="h4">Salesforce B2C Commerce</h3>
    #5049
    Avatar photo[anonymous]
    [anonymous] wrote:

    The table of contents generates links with text retrieved from the headings, so if the headings contain numbers, they will also appear in the TOC links – this is normal behavior.

    But then you get the numbers appearing twice, for example:

    1. “1. Topic One”

    which does not seem right. I guess this is down to the use of li::marker in the CSS which includes a font-variant-numeric

    marker {
        font-variant-numeric: tabular-nums;
    }

    I will have to adjust the CSS I guess.

    #5050
    Avatar photoBob

    The default style of the TOC list comes with the numeric list-style-type, so this is why you see the numbers twice.

    You can change it via CSS; the list of all CSS classes generated by TOC can be found here: https://getpublii.com/dev/default-publii-classes-for-using-with-css/#table-of-contents-toc

    #5063
    Avatar photo[anonymous]

    Thanks for the responses, as always very helpful and I have implemented the change to using h3 class=”h4″. Unfortunately I can’t seem to get rid of the empty link (called 5.3) in the TOC structure on my page. Can you please have a quick look to see if I have missed something? Thanks in advance.

    https://www.fullonecommerce.com/ecommerce-platform-shortlist.html