gohugoio / hugo

The world’s fastest framework for building websites.
https://gohugo.io
Apache License 2.0
75.86k stars 7.54k forks source link

Empty list items in table of contents when heading structure skips a level #7128

Open exprez135 opened 4 years ago

exprez135 commented 4 years ago

What version of Hugo are you using (hugo version)?

v0.68.3 on macOS via HomeBrew

Does this issue reproduce with the latest release?

Yes.


Whenever I enable the Table Of Contents in a situation without any endLevel specified in the site configuration:

Extra-Curriculars

Heading Four Here without Heading Three Before It

Technology

Heading Four Here without Heading Three Before It

The Table of Contents comes out looking like this:

image

I believe the expected behaviour would be for no extra bullet point to appear (or to appear with the H4).

If I add an H3:

Extra-Curriculars

Testing

Heading Four Here

Technology

Heading Four Here without Heading Three Before It

then:

image

Work-Around

If I manually set an endLevel, the problem disappears. It is only when one is not set that the problems occur.

exprez135 commented 4 years ago

Related support thread I opened on the forum: https://discourse.gohugo.io/t/requesting-help/9132.

stale[bot] commented 4 years ago

This issue has been automatically marked as stale because it has not had recent activity. The resources of the Hugo team are limited, and so we are asking for your help. If this is a bug and you can still reproduce this error on the master branch, please reply with all of the information you have about it in order to keep the issue open. If this is a feature request, and you feel that it is still relevant and valuable, please tell us why. This issue will automatically be closed in the near future if no further activity occurs. Thank you for all your contributions.

jmooring commented 4 years ago

Please re-open.

To reproduce:

git clone --single-branch -b hugo-github-issue-7128 https://github.com/jmooring/hugo-testing hugo-github-issue-7128
cd hugo-github-issue-7128
hugo server

Contrary to the original report, the following does not resolve the problem:

[markup.tableOfContents]
endLevel = 3
ordered = false
startLevel = 2

Related: https://discourse.gohugo.io/t/24460

jmooring commented 4 years ago

Please re-open.

tejasjadhav commented 2 months ago

One possible workaround for this is using CSS

For me, this is how it looked like earlier image

I applied the following CSS rules

.table-of-contents ul {
  padding-inline-start: 0;
  list-style: none;
}

.table-of-contents ul:has(> li > a) {
  padding-inline-start: 40px;
  list-style: disc;
}

This resulted in the following output image

This retains the nesting, but at the same time, hides the bullets for empty lists

jerrychan7 commented 2 weeks ago

For anyone running into similar ToC issues, I wrote a template library that generates a ToC. https://github.com/jerrychan7/hugoPerfectToC This project can correctly generate the table of contents, but the disadvantage is that the performance is relatively poor. Since the project parses HTML, it can theoretically parse any extension correctly (#12605). Or work with the heading rendering hook.

Example configuration, and markdown file (click to expand) Assuming the extension is enabled: ```yaml markup: goldmark: extensions: strikethrough: false extras: subscript: enable: true ``` For the following markdown: ```md --- title: "Markdown Syntax Guide" date: 2024-10-01T23:17:15+08:00 draft: false --- #### not h1/h2 first ------------------------------ ## Headings ↓ The heading in the blockquote element. Hopefully it will be possible to jump by ID, the same behavior as other heading elements. > # H1 in blockquote > > ## H2 in blockquote ------------------------------ ## Table ##### non-incrementing heading ↑ Some non-incrementing headings. ------------------------------ # heading in ul/ol * ## h2 in top level * ### h3 in sub-level * #### h4 in top level ------------------------------ # H~2~O ```

Comparison between the directory generated by Hugo and the directory generated by my project:

PAGE.TableOfContents ToC generated by my project
        • not h1/h2 first
    • Headings
  • H1 in blockquote
    • H2 in blockquote
    • Table
          • non-incrementing heading
  • heading in ul/ol
    • h2 in top level
      • h3 in sub-level
        • h4 in top level
  • H2O
  • not h1/h2 first
  • Headings
    • H1 in blockquote
      • H2 in blockquote
  • Table
    • non-incrementing heading
  • heading in ul/ol
    • h2 in top level
      • h3 in sub-level
    • h4 in top level
  • H2O