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
I am using the RTD theme, and the first heading (# foobar) on the page, is the same as the page title.
Due to the fact that it is in the table of contents on the menu, the page title item in the menu is followed by the toc item for the first heading, which is the same as the page title.
There should be a setting to exclude the first heading, or some logic to exclude it, if it is the same as the current page title.
Reacted by Ed Morley, Sergey M., rbq, Timothy Leffel, Edan Schwartz, Alex Vig, Oliver Kopp, Zhongyuan Zhou, Jonathan, Rick and 1 more
Another alternative would be to define the title elsewhere (in thepages config setting or, when #472 lands, in the page's meta-data). Then the title would never appear in the Markdown text and would never appear in the TOC. Of course, in that situation, the Template might need to have a separate tag which inserts the title separate from the main body of the document. I wonder if there would be a way to do that internally. Perhaps mkdocs should remember how it obtained the title for a page, and then in the template, if the title was not obtained from the document itself (from the first item in the TOC), then insert the title into the page right before the main content.
I could not find other discussion about this, but why not simply ignore the h1 level when generating the list of anchors in the readthedocs theme? It does not make sense, I think, that the h1 and h2 levels are mixed as they are now. Since the logical progression of the menu is category - page - section, and a h1 heading belongs to the page level, there is no reason to repeat it in the list of sections.
As a side note, this is of course also inconsistent with RTFD's own theme, and because mkdocs strives to be an alternative, equivalent generator, should not happen.
Reacted by Oliver Kopp, Girish Tampi and Martin Michlmayr
I could not find other discussion about this, but why not simply ignore the h1 level when generating the list of anchors in the readthedocs theme?
Because then everyone that want it to be there will come and tell us otherwise.
Since the logical progression of the menu is category - page - section, and a h1 heading belongs to the page level, there is no reason to repeat it in the list of sections.
That is one approach, other people only include H1's in the page.
As a side note, this is of course also inconsistent with RTFD's own theme, and because mkdocs strives to be an alternative, equivalent generator, should not happen.
I'm not sure I would agree to that as being the goal of MkDocs. An alternative? Sure. Similar? Sure. Equivalent? No chance.
Thanks for the response @d0ugal. I was not talking about the TOC structure in general, but what appears on ReadTheDocs. I see now that this is probably more an issue for them than mkdocs. When they write
You have two options for format for your documentation:
In reStructuredText
In Markdown
I took this to mean that both of these paths would result in the same documentation. Maybe they will want to equalise the results, or at least point out that there are differences in the results.
I also think that this should be solved on the theme level. How about changing the readthdocs theme specifically to skip the first title. That would be consistent with RTD and still doesn't affect mkdocs behavior.
When using readthedocs and the docs is in the docs/ directory, the css file has to be put there. In my case, I had to change the level of the CSS class:
@koppor However, note that since mkdocs v1.1 (2020-02-23) the extra CSS does more harm than good because the bug seems to be fixed (#1594). I was surprised after the upgrade from 1.0.4 when my first h2 TOC entries disappeared as well (apart from the usual h1 page title).
Activity
d0ugal commentedon Jan 6, 2015
We absolutely don't want a setting for this. The logic based approach might make sense, I'm not sure. In reality it is a minor issue.
For now you can manually add the H1 HTML to the markdown to hide it from the TOC.
lovelydinosaur commentedon Jan 6, 2015
If we do want to allow folks to make those sorts of changes we should do so at a theme level. Keep the config etc minimal.
ePirat commentedon Jan 6, 2015
Well, the main reason I decided to use mkdocs was because I do not have to bundle themes and clutter my repository with these.
viktorasm commentedon May 3, 2015
I solved this by just hidding first TOC item:
..and making sure that each page includes h1 that repeats page title (which I needed, anyway). A bit of a workaround, but least intrusive.
d0ugal commentedon May 4, 2015
@viktorasm That's a great way to do this. I might use that as an example in the docs, this is often requested.
waylan commentedon May 4, 2015
Another alternative would be to define the title elsewhere (in the
pagesconfig setting or, when #472 lands, in the page's meta-data). Then the title would never appear in the Markdown text and would never appear in the TOC. Of course, in that situation, the Template might need to have a separate tag which inserts the title separate from the main body of the document. I wonder if there would be a way to do that internally. Perhaps mkdocs should remember how it obtained the title for a page, and then in the template, if the title was not obtained from the document itself (from the first item in the TOC), then insert the title into the page right before the main content.ntessore commentedon May 27, 2015
I could not find other discussion about this, but why not simply ignore the h1 level when generating the list of anchors in the readthedocs theme? It does not make sense, I think, that the h1 and h2 levels are mixed as they are now. Since the logical progression of the menu is category - page - section, and a h1 heading belongs to the page level, there is no reason to repeat it in the list of sections.
As a side note, this is of course also inconsistent with RTFD's own theme, and because mkdocs strives to be an alternative, equivalent generator, should not happen.
d0ugal commentedon May 27, 2015
Because then everyone that want it to be there will come and tell us otherwise.
That is one approach, other people only include H1's in the page.
I'm not sure I would agree to that as being the goal of MkDocs. An alternative? Sure. Similar? Sure. Equivalent? No chance.
ntessore commentedon May 27, 2015
Thanks for the response @d0ugal. I was not talking about the TOC structure in general, but what appears on ReadTheDocs. I see now that this is probably more an issue for them than mkdocs. When they write
I took this to mean that both of these paths would result in the same documentation. Maybe they will want to equalise the results, or at least point out that there are differences in the results.
d0ugal commentedon May 27, 2015
Yup, that makes sense.
sagikazarmark commentedon Jun 12, 2015
👍 for the CSS solution.
I also think that this should be solved on the theme level. How about changing the readthdocs theme specifically to skip the first title. That would be consistent with RTD and still doesn't affect mkdocs behavior.
sagikazarmark commentedon Jun 12, 2015
The CSS workaround works locally, but not when built with RTD. 😞
d0ugal commentedon Jun 12, 2015
It will work with ReadTheDocs, you just need to manually specify the extra_css. See readthedocs/readthedocs.org#1313
If that isn't clear, I'll expand on it tomorrow. I'm on the move now.
sagikazarmark commentedon Jun 12, 2015
Thanks
ProfYaffle commentedon Jun 12, 2015
As @d0ugal says, specify it in extra_css in mkdocs.yml, e.g.:
... and then it'll work everywhere.
sagikazarmark commentedon Jun 12, 2015
Yeah, it works.
Fix display of duplicate heading
koppor commentedon Jan 7, 2020
When using readthedocs and the docs is in the
docs/directory, thecssfile has to be put there. In my case, I had to change the level of the CSS class:wodny commentedon Mar 19, 2020
@koppor However, note that since mkdocs v1.1 (2020-02-23) the extra CSS does more harm than good because the bug seems to be fixed (#1594). I was surprised after the upgrade from 1.0.4 when my first h2 TOC entries disappeared as well (apart from the usual h1 page title).