question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Raise an error when a document contains multiple top level titles

See original GitHub issue

Describe 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:

  1. jupyter-book create test_book && cd test_book
  2. echo "[{file: intro}, {part: part, chapters: [{file: content, title: title}]}]" > _toc.yml
  3. printf "# title1\n\n# title2" > content.md
  4. jupyter-book build .

Observe that the resulting toc looks like this:

image

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:open
  • Created 3 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
mmckycommented, Sep 1, 2020

@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 as frontmatter etc. Playing with some upstream ideas for support of special toctree elements in sphinx in this thread for appendix and frontmatter to help control style in html and latex based on more contextual info.

1reaction
akhmerovcommented, Aug 31, 2020

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found