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

Cannot create a file with a single header at level 2 (without having a level 1) #69

Open
rougier opened this issue Jan 31, 2022 · 1 comment
Labels
bug Something isn't working good first issue Good for newcomers

Comments

@rougier
Copy link

rougier commented Jan 31, 2022

Describe the bug
Cannot create a file with a single header at level 2 (without having a level 1)

To Reproduce

from mdutils.mdutils import MdUtils
mdFile = MdUtils(file_name='example.md',title='Markdown File Example')
mdFile.new_header(level=2, title='Atx Header 2')
mdFile.create_md_file()

Expected behavior
Markdown file with a level 2 header

Desktop (please complete the following information):

  • OS: macOS
  • Version: Python 3.8, mdutils installed throurgh pip

Additional context

Traceback:

Traceback (most recent call last):
  File "test-mdutils.py", line 4, in <module>
    mdFile.new_header(level=2, title='Atx Header 2')
  File "/opt/anaconda3/lib/python3.8/site-packages/mdutils/mdutils.py", line 113, in new_header
    self.__add_new_item_table_of_content(level, title)
  File "/opt/anaconda3/lib/python3.8/site-packages/mdutils/mdutils.py", line 130, in __add_new_item_table_of_content
    curr = curr[-1]
IndexError: list index out of range
@rougier rougier added the bug Something isn't working label Jan 31, 2022
@didix21 didix21 added the good first issue Good for newcomers label Feb 23, 2022
@GoodmanBen
Copy link

If you are okay with the header not being included in the table of contents, a work around to have the code run is to set add_table_of_contents="n", then the code should run without error (although possibly not with the fully desired behavior).

mdFile.new_header(level=2, title='Atx Header 2', add_table_of_contents="n")

rougier added a commit to rougier/numpy-100 that referenced this issue Oct 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

3 participants