notionary 0.1.13__py3-none-any.whl → 0.1.15__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- notionary/__init__.py +2 -2
- notionary/{converters/elements → elements}/audio_element.py +1 -1
- notionary/{converters/registry → elements}/block_element_registry.py +2 -5
- notionary/elements/block_element_registry_builder.py +383 -0
- notionary/{converters/elements → elements}/bookmark_element.py +1 -1
- notionary/{converters/elements → elements}/callout_element.py +2 -2
- notionary/{converters/elements → elements}/code_block_element.py +1 -1
- notionary/{converters/elements → elements}/column_element.py +1 -1
- notionary/{converters/elements → elements}/divider_element.py +1 -1
- notionary/{converters/elements → elements}/embed_element.py +1 -1
- notionary/{converters/elements → elements}/heading_element.py +2 -2
- notionary/{converters/elements → elements}/image_element.py +1 -1
- notionary/{converters/elements → elements}/list_element.py +2 -2
- notionary/elements/mention_element.py +227 -0
- notionary/{converters/elements → elements}/paragraph_element.py +2 -2
- notionary/{converters/elements → elements}/qoute_element.py +1 -1
- notionary/{converters/elements → elements}/table_element.py +2 -2
- notionary/{converters/elements → elements}/todo_lists.py +2 -2
- notionary/{converters/elements → elements}/toggle_element.py +1 -1
- notionary/{converters/elements → elements}/video_element.py +1 -1
- notionary/notion_client.py +55 -5
- notionary/page/content/page_content_manager.py +98 -26
- notionary/{converters → page}/markdown_to_notion_converter.py +2 -4
- notionary/page/notion_page.py +23 -5
- notionary/page/notion_page_factory.py +1 -15
- notionary/page/notion_to_markdown_converter.py +261 -0
- {notionary-0.1.13.dist-info → notionary-0.1.15.dist-info}/METADATA +1 -1
- notionary-0.1.15.dist-info/RECORD +56 -0
- notionary/converters/__init__.py +0 -50
- notionary/converters/notion_to_markdown_converter.py +0 -45
- notionary/converters/registry/block_element_registry_builder.py +0 -284
- notionary-0.1.13.dist-info/RECORD +0 -56
- /notionary/{converters/elements → elements}/notion_block_element.py +0 -0
- /notionary/{converters/elements → elements}/text_inline_formatter.py +0 -0
- {notionary-0.1.13.dist-info → notionary-0.1.15.dist-info}/WHEEL +0 -0
- {notionary-0.1.13.dist-info → notionary-0.1.15.dist-info}/licenses/LICENSE +0 -0
- {notionary-0.1.13.dist-info → notionary-0.1.15.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,261 @@
|
|
1
|
+
from typing import Dict, Any, List, Optional
|
2
|
+
|
3
|
+
from notionary.elements.block_element_registry import (
|
4
|
+
BlockElementRegistry,
|
5
|
+
)
|
6
|
+
from notionary.elements.block_element_registry_builder import (
|
7
|
+
BlockElementRegistryBuilder,
|
8
|
+
)
|
9
|
+
|
10
|
+
|
11
|
+
class NotionToMarkdownConverter:
|
12
|
+
"""Converts Notion blocks to Markdown text with support for nested structures."""
|
13
|
+
|
14
|
+
def __init__(self, block_registry: Optional[BlockElementRegistry] = None):
|
15
|
+
"""
|
16
|
+
Initialize the NotionToMarkdownConverter.
|
17
|
+
|
18
|
+
Args:
|
19
|
+
block_registry: Optional registry of Notion block elements
|
20
|
+
"""
|
21
|
+
self._block_registry = (
|
22
|
+
block_registry or BlockElementRegistryBuilder().create_standard_registry()
|
23
|
+
)
|
24
|
+
|
25
|
+
def convert(self, blocks: List[Dict[str, Any]]) -> str:
|
26
|
+
"""
|
27
|
+
Convert Notion blocks to Markdown text, handling nested structures.
|
28
|
+
|
29
|
+
Args:
|
30
|
+
blocks: List of Notion blocks
|
31
|
+
|
32
|
+
Returns:
|
33
|
+
Markdown text
|
34
|
+
"""
|
35
|
+
if not blocks:
|
36
|
+
return ""
|
37
|
+
|
38
|
+
markdown_parts = []
|
39
|
+
|
40
|
+
for block in blocks:
|
41
|
+
block_markdown = self._convert_single_block_with_children(block)
|
42
|
+
if block_markdown:
|
43
|
+
markdown_parts.append(block_markdown)
|
44
|
+
|
45
|
+
return "\n\n".join(filter(None, markdown_parts))
|
46
|
+
|
47
|
+
def _convert_single_block_with_children(self, block: Dict[str, Any]) -> str:
|
48
|
+
"""
|
49
|
+
Process a single block, including any children.
|
50
|
+
|
51
|
+
Args:
|
52
|
+
block: Notion block to process
|
53
|
+
|
54
|
+
Returns:
|
55
|
+
Markdown representation of the block and its children
|
56
|
+
"""
|
57
|
+
if not block:
|
58
|
+
return ""
|
59
|
+
|
60
|
+
block_markdown = self._block_registry.notion_to_markdown(block)
|
61
|
+
|
62
|
+
if not self._has_children(block):
|
63
|
+
return block_markdown
|
64
|
+
|
65
|
+
children_markdown = self.convert(block["children"])
|
66
|
+
if not children_markdown:
|
67
|
+
return block_markdown
|
68
|
+
|
69
|
+
block_type = block.get("type", "")
|
70
|
+
|
71
|
+
if block_type == "toggle":
|
72
|
+
return self._format_toggle_with_children(block_markdown, children_markdown)
|
73
|
+
|
74
|
+
if block_type in ["numbered_list_item", "bulleted_list_item"]:
|
75
|
+
return self._format_list_item_with_children(
|
76
|
+
block_markdown, children_markdown
|
77
|
+
)
|
78
|
+
|
79
|
+
if block_type in ["column_list", "column"]:
|
80
|
+
return children_markdown
|
81
|
+
|
82
|
+
return self._format_standard_block_with_children(
|
83
|
+
block_markdown, children_markdown
|
84
|
+
)
|
85
|
+
|
86
|
+
def _has_children(self, block: Dict[str, Any]) -> bool:
|
87
|
+
"""
|
88
|
+
Check if block has children that need processing.
|
89
|
+
|
90
|
+
Args:
|
91
|
+
block: Notion block to check
|
92
|
+
|
93
|
+
Returns:
|
94
|
+
True if block has children to process
|
95
|
+
"""
|
96
|
+
return block.get("has_children", False) and "children" in block
|
97
|
+
|
98
|
+
def _format_toggle_with_children(
|
99
|
+
self, toggle_markdown: str, children_markdown: str
|
100
|
+
) -> str:
|
101
|
+
"""
|
102
|
+
Format toggle block with its children content.
|
103
|
+
|
104
|
+
Args:
|
105
|
+
toggle_markdown: Markdown for the toggle itself
|
106
|
+
children_markdown: Markdown for toggle's children
|
107
|
+
|
108
|
+
Returns:
|
109
|
+
Formatted markdown with indented children
|
110
|
+
"""
|
111
|
+
indented_children = self._indent_text(children_markdown)
|
112
|
+
return f"{toggle_markdown}\n{indented_children}"
|
113
|
+
|
114
|
+
def _format_list_item_with_children(
|
115
|
+
self, item_markdown: str, children_markdown: str
|
116
|
+
) -> str:
|
117
|
+
"""
|
118
|
+
Format list item with its children content.
|
119
|
+
|
120
|
+
Args:
|
121
|
+
item_markdown: Markdown for the list item itself
|
122
|
+
children_markdown: Markdown for item's children
|
123
|
+
|
124
|
+
Returns:
|
125
|
+
Formatted markdown with indented children
|
126
|
+
"""
|
127
|
+
indented_children = self._indent_text(children_markdown)
|
128
|
+
return f"{item_markdown}\n{indented_children}"
|
129
|
+
|
130
|
+
def _format_standard_block_with_children(
|
131
|
+
self, block_markdown: str, children_markdown: str
|
132
|
+
) -> str:
|
133
|
+
"""
|
134
|
+
Format standard block with its children content.
|
135
|
+
|
136
|
+
Args:
|
137
|
+
block_markdown: Markdown for the block itself
|
138
|
+
children_markdown: Markdown for block's children
|
139
|
+
|
140
|
+
Returns:
|
141
|
+
Formatted markdown with children after block
|
142
|
+
"""
|
143
|
+
return f"{block_markdown}\n\n{children_markdown}"
|
144
|
+
|
145
|
+
def _indent_text(self, text: str, spaces: int = 4) -> str:
|
146
|
+
"""
|
147
|
+
Indent each line of text with specified number of spaces.
|
148
|
+
|
149
|
+
Args:
|
150
|
+
text: Text to indent
|
151
|
+
spaces: Number of spaces to use for indentation
|
152
|
+
|
153
|
+
Returns:
|
154
|
+
Indented text
|
155
|
+
"""
|
156
|
+
indent = " " * spaces
|
157
|
+
return "\n".join([f"{indent}{line}" for line in text.split("\n")])
|
158
|
+
|
159
|
+
def extract_toggle_content(self, blocks: List[Dict[str, Any]]) -> str:
|
160
|
+
"""
|
161
|
+
Extract only the content of toggles from blocks.
|
162
|
+
|
163
|
+
Args:
|
164
|
+
blocks: List of Notion blocks
|
165
|
+
|
166
|
+
Returns:
|
167
|
+
Markdown text with toggle contents
|
168
|
+
"""
|
169
|
+
if not blocks:
|
170
|
+
return ""
|
171
|
+
|
172
|
+
toggle_contents = []
|
173
|
+
|
174
|
+
for block in blocks:
|
175
|
+
self._extract_toggle_content_recursive(block, toggle_contents)
|
176
|
+
|
177
|
+
return "\n".join(toggle_contents)
|
178
|
+
|
179
|
+
def _extract_toggle_content_recursive(
|
180
|
+
self, block: Dict[str, Any], result: List[str]
|
181
|
+
) -> None:
|
182
|
+
"""
|
183
|
+
Recursively extract toggle content from a block and its children.
|
184
|
+
|
185
|
+
Args:
|
186
|
+
block: Block to process
|
187
|
+
result: List to collect toggle content
|
188
|
+
"""
|
189
|
+
if self._is_toggle_with_children(block):
|
190
|
+
self._add_toggle_header_to_result(block, result)
|
191
|
+
self._add_toggle_children_to_result(block, result)
|
192
|
+
|
193
|
+
if self._has_children(block):
|
194
|
+
for child in block["children"]:
|
195
|
+
self._extract_toggle_content_recursive(child, result)
|
196
|
+
|
197
|
+
def _is_toggle_with_children(self, block: Dict[str, Any]) -> bool:
|
198
|
+
"""
|
199
|
+
Check if block is a toggle with children.
|
200
|
+
|
201
|
+
Args:
|
202
|
+
block: Block to check
|
203
|
+
|
204
|
+
Returns:
|
205
|
+
True if block is a toggle with children
|
206
|
+
"""
|
207
|
+
return block.get("type") == "toggle" and "children" in block
|
208
|
+
|
209
|
+
def _add_toggle_header_to_result(
|
210
|
+
self, block: Dict[str, Any], result: List[str]
|
211
|
+
) -> None:
|
212
|
+
"""
|
213
|
+
Add toggle header text to result list.
|
214
|
+
|
215
|
+
Args:
|
216
|
+
block: Toggle block
|
217
|
+
result: List to add header to
|
218
|
+
"""
|
219
|
+
toggle_text = self._extract_text_from_rich_text(
|
220
|
+
block.get("toggle", {}).get("rich_text", [])
|
221
|
+
)
|
222
|
+
|
223
|
+
if toggle_text:
|
224
|
+
result.append(f"### {toggle_text}")
|
225
|
+
|
226
|
+
def _add_toggle_children_to_result(
|
227
|
+
self, block: Dict[str, Any], result: List[str]
|
228
|
+
) -> None:
|
229
|
+
"""
|
230
|
+
Add formatted toggle children to result list.
|
231
|
+
|
232
|
+
Args:
|
233
|
+
block: Toggle block with children
|
234
|
+
result: List to add children content to
|
235
|
+
"""
|
236
|
+
for child in block.get("children", []):
|
237
|
+
child_type = child.get("type")
|
238
|
+
if not (child_type and child_type in child):
|
239
|
+
continue
|
240
|
+
|
241
|
+
child_text = self._extract_text_from_rich_text(
|
242
|
+
child.get(child_type, {}).get("rich_text", [])
|
243
|
+
)
|
244
|
+
|
245
|
+
if child_text:
|
246
|
+
result.append(f"- {child_text}")
|
247
|
+
|
248
|
+
def _extract_text_from_rich_text(self, rich_text: List[Dict[str, Any]]) -> str:
|
249
|
+
"""
|
250
|
+
Extract plain text from Notion's rich text array.
|
251
|
+
|
252
|
+
Args:
|
253
|
+
rich_text: List of rich text objects
|
254
|
+
|
255
|
+
Returns:
|
256
|
+
Concatenated plain text
|
257
|
+
"""
|
258
|
+
if not rich_text:
|
259
|
+
return ""
|
260
|
+
|
261
|
+
return "".join([rt.get("plain_text", "") for rt in rich_text])
|
@@ -0,0 +1,56 @@
|
|
1
|
+
notionary/__init__.py,sha256=sVqdwzMQcc9jf6FKi1qflilsx8rnWzluVhWewVi5gyI,717
|
2
|
+
notionary/notion_client.py,sha256=NPPK7zId6EaC-hQeFJ7geaiROGtZfmc8cVP2nQez5DU,6040
|
3
|
+
notionary/database/database_discovery.py,sha256=qDGFhXG9s-_6CXdRg8tMiwX4dvX7jLjgAUFPSNlYtlI,4506
|
4
|
+
notionary/database/database_info_service.py,sha256=Ig6gx8jUSPYORJvfgEV5kV6t72pZQsWU8HPMqd43B-o,1336
|
5
|
+
notionary/database/notion_database.py,sha256=RY5MlXNE5DVNWLC_Derljsz87ZMHkE-05Vgm80kvLxg,7250
|
6
|
+
notionary/database/notion_database_factory.py,sha256=Af57yaUHidD8TKJ8uyXOc2nnqHm7on6VGFdDRjxiq9o,6692
|
7
|
+
notionary/database/models/page_result.py,sha256=Vmm5_oYpYAkIIJVoTd1ZZGloeC3cmFLMYP255mAmtaw,233
|
8
|
+
notionary/elements/audio_element.py,sha256=XLARz5zlPPW_Qof6uhcYXFmyYzyS1fLdxdfsvh6GMOs,5589
|
9
|
+
notionary/elements/block_element_registry.py,sha256=2mEbCEIPRY15qk6NYcq9vf7Bq_5vuu1xbiJatoLFf7w,8530
|
10
|
+
notionary/elements/block_element_registry_builder.py,sha256=xfZWJaamYCyw-aIU8TXTcAncVJaLpN7ioJRLYQxTbCo,11529
|
11
|
+
notionary/elements/bookmark_element.py,sha256=83ciz2THxjeq7ofn-Xz9sG1Ifzm_gkIDmOo0A-pNsSo,8577
|
12
|
+
notionary/elements/callout_element.py,sha256=K8yk7nE3WP8nskJKbMunkRDFlhSCXrONmYS6hELN6QE,5932
|
13
|
+
notionary/elements/code_block_element.py,sha256=wbW_PfH6QBUFVfeELESuLiI5-GmLm2YUFP4xwFHgNV4,5173
|
14
|
+
notionary/elements/column_element.py,sha256=F_hnaBtQbnfRiKRVfpo9X5aNiw75SxeHfWOiMyMPcBw,10706
|
15
|
+
notionary/elements/divider_element.py,sha256=RCN87xFizAjKd8c_beywNW5lfXFFtOZPT8tyXgAh2D0,2776
|
16
|
+
notionary/elements/embed_element.py,sha256=LZjbSfwq0v8NGzwfUXpnGwvJ34IjYDwZzqyxVd2Iqt8,4768
|
17
|
+
notionary/elements/heading_element.py,sha256=GsfEg5XtohmtO8PBP9giezIg6pRWQ_CdPXjh7jOiytw,2756
|
18
|
+
notionary/elements/image_element.py,sha256=663H_FzE_bsovps3uCV12trNTmMAWBu5Ko1tSBNu2V4,4845
|
19
|
+
notionary/elements/list_element.py,sha256=-f4mPRPesqFYYXfiiqGpnADeAY2ZAF1sTDtkLcejvLg,4846
|
20
|
+
notionary/elements/mention_element.py,sha256=N1AcE8daMs6sDJGidQ8vvtHj30Do3K7x-4lW2aAYthU,8274
|
21
|
+
notionary/elements/notion_block_element.py,sha256=lLRBDXhBeRaRzkbvdpYpr-U9nbkd62oVtqdSe-svT4c,1746
|
22
|
+
notionary/elements/paragraph_element.py,sha256=ULSPcwy_JbnKdQkMy-xMs_KtYI8k5uxh6b4EGMNldTk,2734
|
23
|
+
notionary/elements/qoute_element.py,sha256=3I2a7KboPF5QF6afu99HSIa62YUNfDJ6oaSDgyc9NjA,9041
|
24
|
+
notionary/elements/table_element.py,sha256=jCq1ZFNCdxYEI6ER21OZ64TYGjW162gH-A6DUbldxY4,11222
|
25
|
+
notionary/elements/text_inline_formatter.py,sha256=FE_Sq2cozpu5RVtMbnPq21gD06UjH3LMRYr3s16JKYo,10606
|
26
|
+
notionary/elements/todo_lists.py,sha256=PrLZdp1-q1gx7mBsL6NUQ5U18HxmkUw8yqVh9qJpArE,4233
|
27
|
+
notionary/elements/toggle_element.py,sha256=5cyWjkBgJcKdhhdrOn4bEM8Dpc5gXWhVbM4qZm9FNYM,7242
|
28
|
+
notionary/elements/video_element.py,sha256=uYCwFakna7pzpCDjjtxRhUkSkPfzJTttdKUKYSluqyw,6031
|
29
|
+
notionary/exceptions/database_exceptions.py,sha256=I-Tx6bYRLpi5pjGPtbT-Mqxvz3BFgYTiuZxknJeLxtI,2638
|
30
|
+
notionary/exceptions/page_creation_exception.py,sha256=4v7IuZD6GsQLrqhDLriGjuG3ML638gAO53zDCrLePuU,281
|
31
|
+
notionary/page/markdown_to_notion_converter.py,sha256=wTkH7o6367IWBtSqBrldpKx4rxHli176QfWtAenyysQ,15067
|
32
|
+
notionary/page/notion_page.py,sha256=KIjVeiMJGWWxR6ty1uuNvMoQf2IoRmSUxwMdDIyOu40,17635
|
33
|
+
notionary/page/notion_page_factory.py,sha256=UUEZ-cyEWL0OMVPrgjc4vJdcplEa1bO2yHCYooACYC8,8189
|
34
|
+
notionary/page/notion_to_markdown_converter.py,sha256=WHrESgMZPqnp3kufi0YB7Cyy8U1rwhJ0d4HHdBRfRdU,8053
|
35
|
+
notionary/page/content/notion_page_content_chunker.py,sha256=xRks74Dqec-De6-AVTxMPnXs-MSJBzSm1HfJfaHiKr8,3330
|
36
|
+
notionary/page/content/page_content_manager.py,sha256=jXWscZyiFNLGMiuJ8Da9P26q_9Hit9_G1j0rVDlOc5M,6224
|
37
|
+
notionary/page/metadata/metadata_editor.py,sha256=61uiw8oB25O8ePhytoJvZDetuof5sjPoM6aoHZGo4wc,4949
|
38
|
+
notionary/page/metadata/notion_icon_manager.py,sha256=ixZrWsHGVpmF05Ncy9LCt8vZlKAQHYFZW-2yI5JZZDI,1426
|
39
|
+
notionary/page/metadata/notion_page_cover_manager.py,sha256=qgQxQE-bx4oWjLFUQvpXD5GzO1Mx7w7htz1xC2BOqUg,1717
|
40
|
+
notionary/page/properites/database_property_service.py,sha256=AJuBGahbb53VQa6IGGHxBMoOgCy6vFZg08uR_eDjNUs,11570
|
41
|
+
notionary/page/properites/page_property_manager.py,sha256=Xl8Cwn8WVszqpFXT_NvASkmP5igpCTEgRVhG_F45424,6914
|
42
|
+
notionary/page/properites/property_formatter.py,sha256=d_Nr5XQxgjB6VIS0u3ey14MOUKY416o_BvdXjbkUNAQ,3667
|
43
|
+
notionary/page/properites/property_operation_result.py,sha256=PhxHJJxxG2BdDl7aswhWnMSmf9RQtoinKkRHDoqxwCs,3913
|
44
|
+
notionary/page/properites/property_value_extractor.py,sha256=1BfyCYrFzfIUmNTozavrLTjG--6P6Dy2tkewf6rHHwQ,2353
|
45
|
+
notionary/page/relations/notion_page_relation_manager.py,sha256=D7JZJLXjX2Jn3CIseJxoMK9qL9gp88t4NmL9Ihu06eg,12682
|
46
|
+
notionary/page/relations/notion_page_title_resolver.py,sha256=jUYsEkfyDgdh77oh2awYEB5g1vQqLBq6xYSXL-4uPH8,1722
|
47
|
+
notionary/page/relations/page_database_relation.py,sha256=F9aGXFjjL8ZLNbfTGeGm_QAyXhz2AEOw7GgDLdprEcE,2313
|
48
|
+
notionary/page/relations/relation_operation_result.py,sha256=NDxBzGntOxc_89ti-HG8xDSqfY6PwyGHKHrrKbCzNjM,5010
|
49
|
+
notionary/util/logging_mixin.py,sha256=fKsx9t90bwvL74ZX3dU-sXdC4TZCQyO6qU9I8txkw_U,1369
|
50
|
+
notionary/util/page_id_utils.py,sha256=EYNMxgf-7ghzL5K8lKZBZfW7g5CsdY0Xuj4IYmU8RPk,1381
|
51
|
+
notionary/util/singleton_decorator.py,sha256=GTNMfIlVNRUVMw_c88xqd12-DcqZJjmyidN54yqiNVw,472
|
52
|
+
notionary-0.1.15.dist-info/licenses/LICENSE,sha256=zOm3cRT1qD49eg7vgw95MI79rpUAZa1kRBFwL2FkAr8,1120
|
53
|
+
notionary-0.1.15.dist-info/METADATA,sha256=uXefq6BdsjQnMAf34az8oWfMb2_6L068evq_G8UGWlE,6154
|
54
|
+
notionary-0.1.15.dist-info/WHEEL,sha256=CmyFI0kx5cdEMTLiONQRbGQwjIoR1aIYB7eCAQ4KPJ0,91
|
55
|
+
notionary-0.1.15.dist-info/top_level.txt,sha256=fhONa6BMHQXqthx5PanWGbPL0b8rdFqhrJKVLf_adSs,10
|
56
|
+
notionary-0.1.15.dist-info/RECORD,,
|
notionary/converters/__init__.py
DELETED
@@ -1,50 +0,0 @@
|
|
1
|
-
# Import converters
|
2
|
-
from .markdown_to_notion_converter import MarkdownToNotionConverter
|
3
|
-
from .notion_to_markdown_converter import NotionToMarkdownConverter
|
4
|
-
|
5
|
-
# Import registry classes
|
6
|
-
from .registry.block_element_registry import BlockElementRegistry
|
7
|
-
from .registry.block_element_registry_builder import BlockElementRegistryBuilder
|
8
|
-
|
9
|
-
# Import elements for type hints and direct use
|
10
|
-
from .elements.paragraph_element import ParagraphElement
|
11
|
-
from .elements.heading_element import HeadingElement
|
12
|
-
from .elements.callout_element import CalloutElement
|
13
|
-
from .elements.code_block_element import CodeBlockElement
|
14
|
-
from .elements.divider_element import DividerElement
|
15
|
-
from .elements.table_element import TableElement
|
16
|
-
from .elements.todo_lists import TodoElement
|
17
|
-
from .elements.list_element import BulletedListElement, NumberedListElement
|
18
|
-
from .elements.qoute_element import QuoteElement
|
19
|
-
from .elements.image_element import ImageElement
|
20
|
-
from .elements.video_element import VideoElement
|
21
|
-
from .elements.toggle_element import ToggleElement
|
22
|
-
from .elements.bookmark_element import BookmarkElement
|
23
|
-
from .elements.column_element import ColumnElement
|
24
|
-
|
25
|
-
default_registry = BlockElementRegistryBuilder.create_standard_registry()
|
26
|
-
|
27
|
-
# Define what to export
|
28
|
-
__all__ = [
|
29
|
-
"BlockElementRegistry",
|
30
|
-
"BlockElementRegistryBuilder",
|
31
|
-
"MarkdownToNotionConverter",
|
32
|
-
"NotionToMarkdownConverter",
|
33
|
-
"default_registry",
|
34
|
-
# Element classes
|
35
|
-
"ParagraphElement",
|
36
|
-
"HeadingElement",
|
37
|
-
"CalloutElement",
|
38
|
-
"CodeBlockElement",
|
39
|
-
"DividerElement",
|
40
|
-
"TableElement",
|
41
|
-
"TodoElement",
|
42
|
-
"QuoteElement",
|
43
|
-
"BulletedListElement",
|
44
|
-
"NumberedListElement",
|
45
|
-
"ImageElement",
|
46
|
-
"VideoElement",
|
47
|
-
"ToggleElement",
|
48
|
-
"BookmarkElement",
|
49
|
-
"ColumnElement",
|
50
|
-
]
|
@@ -1,45 +0,0 @@
|
|
1
|
-
from typing import Dict, Any, List, Optional
|
2
|
-
|
3
|
-
from notionary.converters.registry.block_element_registry import (
|
4
|
-
BlockElementRegistry,
|
5
|
-
)
|
6
|
-
from notionary.converters.registry.block_element_registry_builder import (
|
7
|
-
BlockElementRegistryBuilder,
|
8
|
-
)
|
9
|
-
|
10
|
-
|
11
|
-
class NotionToMarkdownConverter:
|
12
|
-
"""Converts Notion blocks to Markdown text."""
|
13
|
-
|
14
|
-
def __init__(self, block_registry: Optional[BlockElementRegistry] = None):
|
15
|
-
"""
|
16
|
-
Initialize the MarkdownToNotionConverter.
|
17
|
-
|
18
|
-
Args:
|
19
|
-
block_registry: Optional registry of Notion block elements
|
20
|
-
"""
|
21
|
-
self._block_registry = (
|
22
|
-
block_registry or BlockElementRegistryBuilder().create_standard_registry()
|
23
|
-
)
|
24
|
-
|
25
|
-
def convert(self, blocks: List[Dict[str, Any]]) -> str:
|
26
|
-
"""
|
27
|
-
Convert Notion blocks to Markdown text.
|
28
|
-
|
29
|
-
Args:
|
30
|
-
blocks: List of Notion blocks
|
31
|
-
|
32
|
-
Returns:
|
33
|
-
Markdown text
|
34
|
-
"""
|
35
|
-
if not blocks:
|
36
|
-
return ""
|
37
|
-
|
38
|
-
markdown_parts = []
|
39
|
-
|
40
|
-
for block in blocks:
|
41
|
-
markdown = self._block_registry.notion_to_markdown(block)
|
42
|
-
if markdown:
|
43
|
-
markdown_parts.append(markdown)
|
44
|
-
|
45
|
-
return "\n\n".join(markdown_parts)
|