Skip to content

Commit

Permalink
fix: handle embedded lists at the start of other lists
Browse files Browse the repository at this point in the history
  • Loading branch information
vzhd1701 committed Dec 14, 2021
1 parent 66ceb28 commit f3b83ac
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
10 changes: 10 additions & 0 deletions enex2notion/note_parser_elements.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ def parse_list(element: Tag):
nodes.append(li_item)

elif subelement.name in {"ul", "ol"}:
if not nodes:
nodes.append(_make_blank_node(is_ul))

nodes[-1].children.extend(parse_list(subelement))

else:
Expand All @@ -46,6 +49,13 @@ def parse_list(element: Tag):
return nodes


def _make_blank_node(is_ul):
if is_ul:
return NotionBulletedListBlock(text_prop=TextProp(text=""))

return NotionNumberedListBlock(text_prop=TextProp(text=""))


def _parse_odd_item(element: Tag):
if isinstance(element, NavigableString):
if not element.text.strip():
Expand Down
28 changes: 28 additions & 0 deletions tests/test_note_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,34 @@ def test_list_ul():
]


def test_list_ul_ul():
test_note = parse_html(
"<ul><ul><li><div>test_sub</div></li></ul><li><div>test</div></li></ul>"
)

expected = [
NotionBulletedListBlock(text_prop=TextProp(text="")),
NotionBulletedListBlock(text_prop=TextProp("test")),
]
expected[0].children = [NotionBulletedListBlock(text_prop=TextProp("test_sub"))]

assert parse_note_dom(test_note) == expected


def test_list_ol_ol():
test_note = parse_html(
"<ol><ol><li><div>test_sub</div></li></ol><li><div>test</div></li></ol>"
)

expected = [
NotionNumberedListBlock(text_prop=TextProp(text="")),
NotionNumberedListBlock(text_prop=TextProp("test")),
]
expected[0].children = [NotionNumberedListBlock(text_prop=TextProp("test_sub"))]

assert parse_note_dom(test_note) == expected


def test_list_ul_todo():
test_note = parse_html(
(
Expand Down

0 comments on commit f3b83ac

Please sign in to comment.