executablebooks / sphinx-book-theme

A clean book theme for scientific explanations and documentation with Sphinx
https://sphinx-book-theme.readthedocs.io
BSD 3-Clause "New" or "Revised" License
439 stars 201 forks source link

Custom titles in left nav don't work as expected if a page has more than one <h1> element #628

Closed lwasser closed 1 year ago

lwasser commented 2 years ago

Describe the bug

context Please see this discussion for reference. I was trying to create custom left side bar title. Sphinx theme defaults to the first H1 tag on the page for the left side bar title.

My toctree directive element looked like this where some of the labels rendered in the left nav and others didnt. :


```{toctree}
:hidden:
:caption: Documentation
I dont work <documentation/index.md>
I dont work <documentation/create-readme-files.md>
I work here <documentation/package-documentation-tutorials.md>
:hidden:
:caption: Package structure
I don't work <package-structure-code/index.md>
I work <package-structure-code/code-structure-style.md>

**expectation**
I expected all of the labels to render in the left nav for all pages. 

**bug**
But instead it happened seemingly randomly. by mistake as i was cleaning up my pages, i realized that i leave myself TODO's in h1 tags given they appear in vscode outline mode nicely.  it's mostly a reminder to myself and i go back and remove them as i complete tasks. All of a sudden the title of a page was fixed in the left nav.

this is when i realized that the multiple h1 tags on the page were causing sphinx to ignore my custom title. 

```console
$ jupyter-book build mybook
ERROR ...

problem

This is just unexpected behavior. i wouldn't expect extra h1 tags to interfere wtih how sphinx reads custom titles for the left nav.

PS. i'm also happy to update documentation with how to create a nice toc with hidden toctree elements and custom labels as i had to dig to figure this out!

thanks for all of the work that you do here on these awesome themes and myST syntax!

Reproduce the bug

please see the discussion that i mentioned above but i otherwise. just make an md page with multiple h1 tags throughout the page. and i think you'll see the behavior.

List your environment

Jupyter Book : 0.13.1 External ToC : 0.2.4 MyST-Parser : 0.15.2 MyST-NB : 0.13.2 Sphinx Book Theme : 0.3.3 Jupyter-Cache : 0.4.3 NbClient : 0.5.13

Tracked in

choldgraf commented 1 year ago

Ah interesting, I think this one can be fixed upstream in the pydata-sphinx-theme because this is where we inherit the sidebar behavior from. I opened up an issue to track it there, please let me know if my description was off:

lwasser commented 1 year ago

👋 @choldgraf oh good i meant to update this because i actually have found the same behavior in other themes. i will also test in furo to see if i get the same behavior just in case it's even more upstream than pydata.

choldgraf commented 1 year ago

I'm closing this one as I think it's now tracked upstream in pydata, and there's nothing actionable in this repo. Let's figure out the right path forward (even if just documentation) there!