8000 Appending a class to an H1-tag breaks the ToC-hack · Issue #2563 · squidfunk/mkdocs-material · GitHub
[go: up one dir, main page]

Skip to content

Appending a class to an H1-tag breaks the ToC-hack #2563

@martinbira

Description

@martinbira

I've found a bug and checked that ...

  • ... the problem doesn't occur with the default MkDocs template
  • ... the problem is not in any of my customizations (CSS, JS, template)
  • ... the documentation does not mention anything about my problem
  • ... there are no open or closed issues that are related to my problem

Description

When appeding a class to an H1 tag with attribute lists, the ToC-hack in the toc.html partial breaks and the first item in the ToC is the page title. The ToC-hack assumes that the first attribute in an H1 is id, but when adding a class to it, class is the first tag.

Expected behavior

When adding a class to an H1 using attribute lists the Page Title should not be in the ToC.

Actual behavior

When adding a class to an H1 using attribute lists the Page Title is the first ToC item.

Steps to reproduce the bug

  1. Ensure that the attr_list markdown extension is used.
  2. Add a class to the H1 in a .md file with at least one H2:
# This is my title { .myTitleClass }

Text

## This is my first ToC entry

Text
  1. Run mkdocs serve and view

Package versions

  • Python: 3.9.0
  • MkDocs: 1.1.2
  • Material: 7.1.1

Project configuration

markdown_extensions:
  - attr_list

System information

N/A

Temporary workaround

A temporary workaround is to add an additional if to the toc.html partial that checks for class:

  {% if toc | first is defined and "\x3ch1 class=" in page.content %}
    {% set toc = (toc | first).children %}
  {% endif %}

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugIssue reports a bugresolvedIssue is resolved, yet unreleased if open

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0