You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Extract first level heading as nav bar entry doesn't work if SPDX meta data as HTML comments is present #3908
To my research MkDocs itself (not a plugin or theme) is responsible to generate the entries in the navigation bar. It will use the first level heading from the md file if present.
In my case this does not work because there is a multiline HTML comment containing SPDX/REUSE meta data.
It could be worth it to also investigate how would using both HTML comments and the front-matter meta header, affect the render.
Given that REUSE and perhaps other tools expect .md files to use HTML comments as meta headers, then MkDocs should support all variants with both HTML comments above and below the front-matter meta header.
@kamilkrzyskow thanks, looks like the break was always at this indentation level, which might have been an oversight? I suppose it could be indented once more, to make sure we actually break at the first H1 tag, without expecting it to be the absolute first thing in the file. I'll try that locally and see if that breaks any test.
I understand this approach as a way to optimize the performance and prevent scanning the whole file.
I suppose it could be indented once more, to make sure we actually break at the first H1 tag
Some people only use H2 tags, as Material for MkDocs does a hack to add missing H1 based on page.tile.
So there has to be some constraint to prevent the script from scanning the whole file and not finding anything.
Either skip the comments and stick to checking the first tag being H1, or break on any H1-H6, but the latter also opens up a performance issue for docs without any headings 🤔
Still, like mentioned above, HTML comments need to be properly handled above and below the front matter meta header to support all cases.
Thanks @kamilkrzyskow, that makes sense if the intention was to stay as close as the previous behavior.
I don't think the perf hit is important here if we indent break. It wouldn't scan the whole file, just the top-level HTML elements, and only their tag name. It's pretty fast, even for huge documents.
Activity
kamilkrzyskow commentedon Jan 19, 2025
I'll copy the relevant part from the comment for a possible fix here
The Treeprocessor goes over the tags in the file but
breaks after the first tag is checked, I guess this is a good place to skip over comment tags:mkdocs/mkdocs/structure/pages.py
Lines 557 to 560 in 7e4892a
It could be worth it to also investigate how would using both HTML comments and the front-matter meta header, affect the render.
Given that REUSE and perhaps other tools expect
.mdfiles to use HTML comments as meta headers, then MkDocs should support all variants with both HTML comments above and below the front-matter meta header.buhtz commentedon Jan 19, 2025
I can confirm that the front matter heading thing does work with
mkdocsand alsoreuse lintis satisfied.pawamoy commentedon Jan 19, 2025
Maybe dumb question, but have you tried adding newlines?
The parser can be sensitive to that.
pawamoy commentedon Jan 19, 2025
@kamilkrzyskow thanks, looks like the
breakwas always at this indentation level, which might have been an oversight? I suppose it could be indented once more, to make sure we actually break at the first H1 tag, without expecting it to be the absolute first thing in the file. I'll try that locally and see if that breaks any test.pawamoy commentedon Jan 19, 2025
Tests pass with the suggested change.
kamilkrzyskow commentedon Jan 20, 2025
@pawamoy
This is not an oversight, but intentional given the previous code, where it read the first non-empty line and checked for
#mkdocs/mkdocs/utils/__init__.py
Lines 311 to 315 in 7e4892a
I understand this approach as a way to optimize the performance and prevent scanning the whole file.
Some people only use
H2tags, as Material for MkDocs does a hack to add missing H1 based onpage.tile.So there has to be some constraint to prevent the script from scanning the whole file and not finding anything.
Either skip the comments and stick to checking the first tag being H1, or break on any H1-H6, but the latter also opens up a performance issue for docs without any headings 🤔
Still, like mentioned above, HTML comments need to be properly handled above and below the front matter meta header to support all cases.
pawamoy commentedon Jan 20, 2025
Thanks @kamilkrzyskow, that makes sense if the intention was to stay as close as the previous behavior.
I don't think the perf hit is important here if we indent
break. It wouldn't scan the whole file, just the top-level HTML elements, and only their tag name. It's pretty fast, even for huge documents.chore: MkDocs compliant SPDX/REUSE meta data
chore: MkDocs compliant SPDX/REUSE meta data
chore: MkDocs compliant SPDX/REUSE meta data