Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement SyncedBlock #35

Merged
merged 6 commits into from
Jul 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ Here are some features we're planning to add in the future:
- Fix pagination bug that occurred with databases with more than 100 pages
- Make it easier to use multiple plugins for the same class by adding the "UseNextClass" exception
- Add the ability to include notion ids in export YAML files using the `id_property` commandline argument
- Add support for the SyncedBlock

### v0.4.1

Expand Down
9 changes: 7 additions & 2 deletions n2y/blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -468,8 +468,13 @@ class LinkPreviewBlock(WarningBlock):
pass


class SyncedBlock(WarningBlock):
pass
class SyncedBlock(Block):
def to_pandoc(self):
synced_block_shared = self.has_children
bimbashrestha marked this conversation as resolved.
Show resolved Hide resolved
if not synced_block_shared:
logger.warning('Skipping un-shared synced block (%s)', self.notion_url)
bimbashrestha marked this conversation as resolved.
Show resolved Hide resolved
return None
return self.children_to_pandoc()
bimbashrestha marked this conversation as resolved.
Show resolved Hide resolved


class LinkToPageBlock(WarningBlock):
Expand Down
2 changes: 1 addition & 1 deletion n2y/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def processed_date_to_plain_text(processed_date):
def pandoc_ast_to_markdown(pandoc_ast):
# This function tries to avoid calling the separate pandoc binary (which is
# slow) for basic cases with just spaces and strings
if pandoc_ast == []:
if pandoc_ast is None or pandoc_ast == []:
return ""
elif type(pandoc_ast) == list and all(type(n) in [Str, Space] for n in pandoc_ast):
# TODO: optimize performance for some other basic cases
Expand Down
29 changes: 29 additions & 0 deletions tests/test_blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -366,3 +366,32 @@ def test_callout():
'\n'
'Children\n'
)


def test_scyned_block_shared():
original_synced_block = mock_block(
"synced_block",
{"synced_from": None},
has_children=True)
reference_synced_block = mock_block(
"synced_block",
{"synced_from": {'type': 'block_id', 'block_id': 'some-block-id'}},
has_children=True)
children = [mock_paragraph_block([("synced", [])])]
original_pandoc_ast, original_markdown = process_parent_block(
original_synced_block, children)
reference_pandoc_ast, reference_markdown = process_parent_block(
reference_synced_block, children)
assert original_pandoc_ast == reference_pandoc_ast == [Para([Str("synced")])]
assert original_markdown == reference_markdown == "synced\n"


def test_scyned_block_unshared():
unshared_reference_synced_block = mock_block(
"synced_block",
{"synced_from": {'type': 'block_id', 'block_id': 'some-block-id'}},
has_children=False)
unshared_reference_pandoc_ast, unshared_reference_markdown = process_parent_block(
unshared_reference_synced_block, None)
assert unshared_reference_pandoc_ast is None
assert unshared_reference_markdown == ""
1 change: 1 addition & 0 deletions tests/test_end_to_end.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ def test_all_blocks_page_to_markdown(tmp_path):
assert "Callout block" in lines
assert "$e^{-i \\pi} = -1$" in lines
assert "``` javascript\nCode Block\n```" in document_as_markdown
assert lines.count("This is a synced block.") == 2
bimbashrestha marked this conversation as resolved.
Show resolved Hide resolved

# a bookmark with a caption and without
assert "<https://innolitics.com>" in lines
Expand Down