Skip to content

Commit

Permalink
fix: add todo parsing for paragraphs
Browse files Browse the repository at this point in the history
  • Loading branch information
vzhd1701 committed Dec 7, 2021
1 parent 8478fb0 commit f3e9871
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
10 changes: 9 additions & 1 deletion enex2notion/note_parser_e_div.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

from enex2notion.notion_blocks import NotionBookmarkBlock, NotionTextBlock
from enex2notion.notion_blocks_container import NotionCodeBlock
from enex2notion.notion_blocks_list import NotionTodoBlock
from enex2notion.string_extractor import extract_string

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -39,7 +40,14 @@ def parse_codeblock(element: Tag):


def parse_text(element: Tag):
return NotionTextBlock(text_prop=extract_string(element))
element_text = extract_string(element)

todo = element.find("en-todo")
if todo:
is_checked = todo.get("checked") == "true"
return NotionTodoBlock(text_prop=element_text, checked=is_checked)

return NotionTextBlock(text_prop=element_text)


def parse_richlink(element: Tag):
Expand Down
12 changes: 12 additions & 0 deletions tests/test_note_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,18 @@ def test_text_block():
assert parse_note_dom(test_note) == [NotionTextBlock(text_prop=TextProp("test1"))]


def test_text_block_todo():
test_note = parse_html(
'<div><en-todo checked="false" />test1</div>'
'<div><en-todo checked="true" />test2</div>'
)

assert parse_note_dom(test_note) == [
NotionTodoBlock(text_prop=TextProp("test1"), checked=False),
NotionTodoBlock(text_prop=TextProp("test2"), checked=True),
]


def test_skipped_blocks():
test_note = parse_html(
'<div style="--en-task-group:true;" <!--irrelevant_attrs--> >'
Expand Down

0 comments on commit f3e9871

Please sign in to comment.