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

Varying Title level leads to IndexError in __add_new_item_table_of_content #68

Closed
303sec opened this issue Nov 9, 2021 · 1 comment
Closed
Labels
bug Something isn't working

Comments

@303sec
Copy link

303sec commented Nov 9, 2021

There are various issues with using title levels in a non-standard order which seems to trigger an IndexError.

To Reproduce
Steps to reproduce the behavior:

from mdutils.mdutils import MdUtils
md.new_header(level=3, title=infile)
md = MdUtils(file_name='test.md',title='test')
md.new_header(level=3, title='Level 3 header')
python3.7 mdutilstest.py

Traceback (most recent call last):
  File "faraday_markdown_parser.py", line 19, in <module>
    md.new_header(level=3, title=host_title)
  File "/usr/local/lib/python3.7/dist-packages/mdutils/mdutils.py", line 113, in new_header
    self.__add_new_item_table_of_content(level, title)
  File "/usr/local/lib/python3.7/dist-packages/mdutils/mdutils.py", line 130, in __add_new_item_table_of_content
    curr = curr[-1]
IndexError: list index out of range

Expected behavior
It should be possible to have title levels in arbitrary order/

Desktop (please complete the following information):

  • OS: Ubuntu
  • Version 20.04 LTS
@303sec 303sec added the bug Something isn't working label Nov 9, 2021
@didix21
Copy link
Owner

didix21 commented Jan 2, 2022

Maybe you should add another example because you're using md instance before creating it. So your code will always crash 😅.

@didix21 didix21 closed this as completed Jan 2, 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
Projects
None yet
Development

No branches or pull requests

2 participants