Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python preprocessor example is ignorant of part titles #2295

Open
GetPsyched opened this issue Jan 21, 2024 · 0 comments
Open

Python preprocessor example is ignorant of part titles #2295

GetPsyched opened this issue Jan 21, 2024 · 0 comments
Labels
C-enhancement Category: Enhancement or feature request

Comments

@GetPsyched
Copy link

Problem

I am using mdBook in my Python libary project. The docs have a nice snippet of code for making a preprocessor in Python (thanks for that btw). However, I kept getting a KeyError saying that Chapter is not a valid key in the section. I couldn't even debug this since printing the output of the json would just be eaten by mdBook.

That is until today; instead of running print(book) I ran logging.error(book) which thankfully showed the entire json structure.

The reason for the KeyError was because the first entry was a part title.

Here's a small snippet of the JSON:

{
  "sections": [
      {"PartTitle": "User Guide"},
      {
          "Chapter": {
              "name": "Introduction",
              "content": "stuff",
              "number": [1],
              "sub_items": [],
              "path": "readme.md",
              "source_path": "readme.md",
              "parent_names": [],
          }
      },
      # more entries
  ]
}

Proposed Solution

The JSON structure should be mentioned along with the preprocessor snippet.

And this code just doesn't work unless you change the index.

# and now, we can just modify the content of the first chapter
book['sections'][0]['Chapter']['content'] = '# Hello'

Notes

No response

@GetPsyched GetPsyched added the C-enhancement Category: Enhancement or feature request label Jan 21, 2024
@GetPsyched GetPsyched changed the title Pytthon preprocessor example is ignorant of part titles Python preprocessor example is ignorant of part titles Jan 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-enhancement Category: Enhancement or feature request
Projects
None yet
Development

No branches or pull requests

1 participant