Skip to content

Commit

Permalink
Add basic support for callout blocks
Browse files Browse the repository at this point in the history
Currently, it just prints the content of the block but ignores the emoji
and color.

Closes #26
  • Loading branch information
johndgiese committed May 10, 2022
1 parent 4ed0dea commit 9438df5
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ Classes that can be extended (case sensitive):
- Bookmark
- BulletedList
- BulletedListItem
- CalloutBlock
- ChildPageBlock
- CodeBlockFenced
- Divider
Expand Down Expand Up @@ -118,6 +119,7 @@ Here are some features we're planning to add in the future:

- Add support for exporting pages
- Add basic support for links
- Add support for callout blocks

### v0.2.3

Expand Down
22 changes: 20 additions & 2 deletions n2y/blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ def parse_block(client: Client, block, get_children=True):
return Toggle(client, block, get_children)
elif block['type'] == "equation":
return Equation(client, block, get_children)
elif block['type'] == "callout":
return CalloutBlock(client, block, get_children)
else:
# TODO: add remaining block types
raise NotImplementedError(f'Unknown block type: "{block["type"]}"')
Expand Down Expand Up @@ -167,9 +169,9 @@ def to_pandoc(self):
if children:
result = [Para(content)]
result.extend(children)
return result
else:
return Para(content)
result = Para(content)
return result


class BulletedListItem(Block):
Expand Down Expand Up @@ -361,6 +363,22 @@ def to_pandoc(self):
return output


class CalloutBlock(Block):
def __init__(self, client: Client, block, get_children=True):
super().__init__(client, block, get_children)
self.text = RichTextArray(self.text)

def to_pandoc(self):
content = self.text.to_pandoc()
children = super().to_pandoc()
if children:
result = [Para(content)]
result.extend(children)
else:
result = Para(content)
return result


class File:
"""
See https://developers.notion.com/reference/file-object
Expand Down
1 change: 1 addition & 0 deletions tests/test_end_to_end.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ def test_all_blocks_page_to_markdown(tmp_path):
assert "### Heading 3" in lines
assert "- List block" in lines
assert "1. Number list block" in lines
assert "Callout block" in lines
# TODO: add more blocks to the document, along with assertions

# "Unknown.jpeg" is a file block in the Notion page
Expand Down

0 comments on commit 9438df5

Please sign in to comment.