Skip to content

fix: allow creating headers at any level without requiring parent headers#118

Open
muhamedfazalps wants to merge 2 commits into
didix21:masterfrom
muhamedfazalps:fix/header-level-without-parent
Open

fix: allow creating headers at any level without requiring parent headers#118
muhamedfazalps wants to merge 2 commits into
didix21:masterfrom
muhamedfazalps:fix/header-level-without-parent

Conversation

@muhamedfazalps

Copy link
Copy Markdown

Fixes #69

MdUtils.new_header() raised IndexError: list index out of range when called with level >= 2 without first creating a level 1 header. This happened because __add_new_item_table_of_content tried to access _table_titles[-1] on an empty list when navigating to the parent level.

Fix: Before descending into the last child at each level, check if the current list is empty and create an intermediate container if needed. This allows headers to be created in any order, not just sequentially from level 1.

All 118 existing tests continue to pass.

…ders

When creating a header at level 2 or higher without first creating
a level 1 header, __add_new_item_table_of_content raised IndexError
because it tried to access _table_titles[-1] on an empty list.

Fix by creating intermediate level containers when they don't exist,
so the table of contents tree builds correctly regardless of the
order in which headers are added.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

1 participant