Skip to content

Exclude first title from table of contents #318

Closed

Description

@ePirat

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.

Activity

  1. d0ugal commented on Jan 6, 2015

    @d0ugal
    Contributor

    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.

  2. lovelydinosaur commented on Jan 6, 2015

    @lovelydinosaur
    Collaborator

    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.

  3. ePirat commented on Jan 6, 2015

    @ePirat
    Author

    Well, the main reason I decided to use mkdocs was because I do not have to bundle themes and clutter my repository with these.

  4. viktorasm commented on May 3, 2015

    @viktorasm

    I solved this by just hidding first TOC item:

    li.toctree-l3:first-child {
        display: none;
    }
    

    ..and making sure that each page includes h1 that repeats page title (which I needed, anyway). A bit of a workaround, but least intrusive.

  5. d0ugal commented on May 4, 2015

    @d0ugal
    Contributor

    @viktorasm That's a great way to do this. I might use that as an example in the docs, this is often requested.

  6. waylan commented on May 4, 2015

    @waylan
    Contributor

    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.

  7. ntessore commented on May 27, 2015

    @ntessore

    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.

  8. d0ugal commented on May 27, 2015

    @d0ugal
    Contributor

    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.

  9. ntessore commented on May 27, 2015

    @ntessore

    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.

  10. d0ugal commented on May 27, 2015

    @d0ugal
    Contributor

    Yup, that makes sense.

  11. sagikazarmark commented on Jun 12, 2015

    @sagikazarmark

    👍 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.

  12. sagikazarmark commented on Jun 12, 2015

    @sagikazarmark

    The CSS workaround works locally, but not when built with RTD. 😞

  13. d0ugal commented on Jun 12, 2015

    @d0ugal
    Contributor

    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.

  14. sagikazarmark commented on Jun 12, 2015

    @sagikazarmark

    Thanks

  15. ProfYaffle commented on Jun 12, 2015

    @ProfYaffle
    Contributor

    As @d0ugal says, specify it in extra_css in mkdocs.yml, e.g.:

    extra_css: 
        - custom.css
    

    ... and then it'll work everywhere.

  16. sagikazarmark commented on Jun 12, 2015

    @sagikazarmark

    Yeah, it works.

  17. added a commit that references this issue on Jan 7, 2020
  18. koppor commented on Jan 7, 2020

    @koppor

    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:

    li.toctree-l2:first-child {
        display: none;
    }
  19. wodny commented on Mar 19, 2020

    @wodny
    Contributor

    @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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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