Skip to content

Fix inconsistent sidebar nesting #519

Description

@jhildenbiddle

The sidebar nesting logic is inconsistent which can create challenges for plugin and theme authors looking to target specific navigation levels.

Here is the docsify HTML output from a three-level sidebar navigation:

<divclass="sidebar-nav"><ul><liclass="active"><ahref="#/page">Page</a><ulclass="app-sub-sidebar"><li><aclass="section-link" href="#/page?id=section">Section</a></li><li><ulclass="children"><li><aclass="section-link" href="#/page?id=link">Link</a></li></ul></li></ul></li></ul></div>

Take notice of how the top-level item and its children are rendered:

<liclass="active"><ahref="#/page">Page</a><ulclass="app-sub-sidebar">
...
</ul></li>

The child items are rendered as a ul element which is a sibling of the a element. This makes it easy to target the ul element via CSS (a + ul) or JavaScript (aNode.nextSibling).

Now take notice of how the second level links are rendered:

<li><aclass="section-link" href="#/page?id=section">Section</a></li><li><ulclass="children">
...
</ul></li>

Here the a and ul elements are contained in separate li items. This makes it impossible to target the ul from the a element via CSS, and more expensive via JavaScript (aNode.parentNode.nextSibling.querySelector('ul.children')). This also breaks the default list styling, as the sibling li elements render as follows:

• Page
• Section
• • Child
• Child

What I would hope to see is the same nesting logic applied to all levels of the sidebar navigation: links that have children are rendered as an a tag immediately followed by a ul tag containing the children:

<li><aclass="section-link" href="#/page?id=section">Section</a><ulclass="children">
...
</ul></li>

Using this nesting logic would make targeting via CSS and JS much easier, and allow the default list styling to work for an infinite number of levels:

• Level 1
• Level 2
• Level 3
• Level 4
...

Thanks!

Activity

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