Raise an error when a document contains multiple top level titles
See original GitHub issueDescribe the bug
The rendered toc breaks when a document has multiple top level headers
To Reproduce
To reproduce create a book with a document which has two top level headers:
jupyter-book create test_book && cd test_book
echo "[{file: intro}, {part: part, chapters: [{file: content, title: title}]}]" > _toc.yml
printf "# title1\n\n# title2" > content.md
jupyter-book build .
Observe that the resulting toc looks like this:
So there are two toc entries, each referring to a different section within the source file. The title
key from the toc is completely ignored.
This contradicts to the docs:
Chapters are the top-most book structure. The top level of your
_toc.yml
contains a list of chapters. The title of each file will be the chapter’s title.
Expected behavior
I’d expect one of the following to happen
- An error is raised due to a document containing multiple top level headers and only a single
title
toc key. - A single chapter with a title “title” is created, and “title1” and “title2” are section titles within that document.
Environment
- Python Version: 3.8.3
- Package versions or output of
jupyter-book --version
:
Jupyter Book: 0.7.5
MyST-NB: 0.10.0
Sphinx Book Theme: 0.0.36
MyST-Parser: 0.12.7
Jupyter-Cache: 0.4.1
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (5 by maintainers)
Top Results From Across the Web
Writing multiple values to json file throws "only one top level ...
The resulting file has to be valid json. As the error says, you must not have multiple elements on the top level of...
Read more >CSE341 Lecture Notes 10: Exceptions (in ML) - Washington
In the example above, Empty is a built-in exception constructor, and we simply allow the raised exception to propagate to top-level, where SML/NJ...
Read more >Built-in Exceptions — Python 3.11.1 documentation
When raising a new exception while another exception is already being handled, ... to create a subclass that inherits from multiple exception types....
Read more >Best Practices for exceptions - .NET - Microsoft Learn
NET exception types; End exception class names with the word Exception; Include three constructors in custom exception classes ...
Read more >Video: Input and error messages - Microsoft Support
On the Input Message tab, check the box next to Show input message when cell is selected. Type a Title if you want....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@choldgraf I think a warning here would be good. You have done a nice job in the current docs but some users won’t read through it
:-)
and might prevent bug reports.thanks for these test cases @akhmerov. I am currently doing some homework to understand how various
toc
structures are working (in addition to some common patterns I think users will try) in an effort to improve the relationship between_toc.yml
and some more complex book elements such asfrontmatter
etc. Playing with some upstream ideas for support of specialtoctree
elements insphinx
in this thread forappendix
andfrontmatter
to help control style inhtml
andlatex
based on more contextual info.That’s reasonable, I assumed that it’d be the case. Would be also good to mention it around https://jupyterbook.org/customize/toc.html#how-headers-and-sections-map-onto-to-book-structure as well. Nevertheless the breaking is subtle and not obvious at a glance. Therefore I suggest to raise an error.