Skip to content

[TOC] includes headings inside list items (e.g. - ### Case1) in the table of contents #432

@tsungjung411

Description

@tsungjung411

Is this a hackmd.io issue?

Read our Official tutorial

It's on https://hackmd.io/c/tutorials/

or Chinese version: https://hackmd.io/c/tutorials-tw/

What's the problem

Current behaviour

When using [TOC], headings written inside list items are also included in the table of contents.

Image

Reproducible content:

[TOC]

### Section
- ### Case1
- ### Case2
- ### Case3

Actual rendered TOC result:

- Section
- Case1
- Case2
- Case3

Provide steps to reproduce:

  1. Go to https://hackmd.io

  2. Create a new note

  3. Paste the content below:

    [TOC]
    
    ### Section
    - ### Case1
    - ### Case2
    - ### Case3
  4. Switch to preview / rendered view

  5. Observe that Case1, Case2, and Case3 are also included in TOC

Here is an example: https://hackmd.io/mhkr3m9WR4Kse_ePoV_c6w
(This never happened before.)

Expected behaviour

I would expect only the main section heading to appear in the table of contents:

- Section

Headings inside list items such as - ### Case1 should ideally not be included in TOC, or this behavior should be clearly documented if it is intended.

Environment

I use HackMD on:

Desktop

  • OS: Windows / Ubuntu 24.04 / Android 14
  • Browser: Chrome 147.0.7727.56 , FireFox 143.0(64 位元)

Mobile

  • Device: Xiaomi Pro 13
  • OS: Android 14
  • Browser: Chrome 146.0.7880.177

Additional context

This may be intended Markdown parsing behavior, but from a TOC usability perspective it is surprising and can pollute the generated table of contents.
If this is expected behavior, documentation clarification would be helpful.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions