Skip to content

when toc_level set to 4, it generate UnboundLocalError: cannot access local variable 'h3li' where it is not associated with a value #95

@allenyllee

Description

@allenyllee

mkdocs.yml

site_name: User Manual
nav:
  - Chapter 1  Introduction: 
      - Chapter_1.md

theme:
  name: material
plugins:
  - to-pdf:
      toc_level: 4

Chapter_1.md

# 1.1 Introduction

test123

### sub-section

test456

The full error messsage is:

INFO    -  Building documentation...
INFO    -  Cleaning site directory
INFO    -  (hook on inject_link: A.1 Overview)
INFO    -  (hook on inject_link: B.1 Overview)
INFO    -  (hook on inject_link: C.1 Overview)
INFO    -  (hook on inject_link: D.1 Overview)
INFO    -  (hook on inject_link: 1.1 Introduction to the BMC Platform)
INFO    -  (hook on inject_link: Chapter 2)
INFO    -  (hook on inject_link: Chapter 3  Frequently Asked Questions)
INFO    -  (hook on inject_link: 4.1 Introduction)
INFO    -  (hook on inject_link: Contacting Axiomtek)
INFO    -  (hook on inject_link: Conventions Used in the Manual)
INFO    -  (hook on inject_link: Disclaimer)
INFO    -  (hook on inject_link: Disclaimer Continued)
INFO    -  (hook on inject_link: Preface)
INFO    -  Number headings up to level 4.
INFO    -  Generate a table of contents up to heading level 4.
Traceback (most recent call last):
  File "/mnt/DATA/ax-docs/../venv/bin/mkdocs", line 8, in <module>
    sys.exit(cli())
             ^^^^^
  File "/mnt/DATA/venv/lib/python3.12/site-packages/click/core.py", line 1462, in __call__
    return self.main(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/mnt/DATA/venv/lib/python3.12/site-packages/click/core.py", line 1383, in main
    rv = self.invoke(ctx)
         ^^^^^^^^^^^^^^^^
  File "/mnt/DATA/venv/lib/python3.12/site-packages/click/core.py", line 1850, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/mnt/DATA/venv/lib/python3.12/site-packages/click/core.py", line 1246, in invoke
    return ctx.invoke(self.callback, **ctx.params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/mnt/DATA/venv/lib/python3.12/site-packages/click/core.py", line 814, in invoke
    return callback(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/mnt/DATA/venv/lib/python3.12/site-packages/mkdocs/__main__.py", line 272, in serve_command
    serve.serve(**kwargs)
  File "/mnt/DATA/venv/lib/python3.12/site-packages/mkdocs/commands/serve.py", line 85, in serve
    builder(config)
  File "/mnt/DATA/venv/lib/python3.12/site-packages/mkdocs/commands/serve.py", line 67, in builder
    build(config, serve_url=None if is_clean else serve_url, dirty=is_dirty)
  File "/mnt/DATA/venv/lib/python3.12/site-packages/mkdocs/commands/build.py", line 347, in build
    config.plugins.on_post_build(config=config)
  File "/mnt/DATA/venv/lib/python3.12/site-packages/mkdocs/plugins.py", line 602, in on_post_build
    return self.run_event('post_build', config=config)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/mnt/DATA/venv/lib/python3.12/site-packages/mkdocs/plugins.py", line 568, in run_event
    result = method(**kwargs)
             ^^^^^^^^^^^^^^^^
  File "/mnt/DATA/venv/lib/python3.12/site-packages/mkdocs_to_pdf/plugin.py", line 134, in on_post_build
    self.generator.on_post_build(config, self.config['output_path'])
  File "/mnt/DATA/venv/lib/python3.12/site-packages/mkdocs_to_pdf/generator.py", line 130, in on_post_build
    make_indexes(soup, self._options)
  File "/mnt/DATA/venv/lib/python3.12/site-packages/mkdocs_to_pdf/toc.py", line 90, in make_indexes
    if not h3li:
           ^^^^
UnboundLocalError: cannot access local variable 'h3li' where it is not associated with a value

If I change Chapter_1.md to

# 1.1 Introduction

test123

## section

### sub-section

test456

by adding second level heading, it will not prompt error.

But in my case, i need to skip second level heading to avoid auto numbering, so I don't want to add second level heading, I think this should be allowed.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions