gohugoio / hugo

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

Counter-intuitive table of contents output #12917

Closed jerrychan7 closed 1 week ago

jerrychan7 commented 1 week ago

Poorly structured markdown can result in a counter-intuitive ToC output. It looks like the heading is not generated via the AST, but through some string processing. This seems to be an old issue (#1778).

With config:

markup:
  tableOfContents:
    startLevel: 1
    endLevel: 7
    ordered: false

And markdown for test:

---
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
>
> ## H2

## Table

##### heading

↑ Some non-incrementing headings.

ToC result:

image

Expected intuitive ToC output:

image

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

$ hugo version
hugo v0.134.3-5fb333b9f5ff4ec018f9d78910177d0bec1befb0+extended linux/amd64 BuildDate=2024-09-19T14:28:20Z VendorInfo=hugomods

Does this issue reproduce with the latest release?

yes

jmooring commented 1 week ago

Duplicate of https://github.com/gohugoio/hugo/issues/7128.

You might consider the "Method 3" approach described in this article, or tocbot.js.