Skip to content

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

Description

@rougier

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinggood first issueGood for newcomers

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions