notionary 0.3.1__py3-none-any.whl → 0.4.1__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 +49 -1
- notionary/blocks/client.py +37 -11
- notionary/blocks/enums.py +0 -6
- notionary/blocks/rich_text/markdown_rich_text_converter.py +49 -15
- notionary/blocks/rich_text/models.py +13 -4
- notionary/blocks/rich_text/name_id_resolver/data_source.py +9 -3
- notionary/blocks/rich_text/name_id_resolver/person.py +6 -2
- notionary/blocks/rich_text/rich_text_markdown_converter.py +10 -3
- notionary/blocks/schemas.py +33 -78
- notionary/comments/client.py +19 -6
- notionary/comments/factory.py +10 -3
- notionary/comments/schemas.py +10 -31
- notionary/comments/service.py +12 -4
- notionary/data_source/http/data_source_instance_client.py +59 -17
- notionary/data_source/properties/schemas.py +156 -115
- notionary/data_source/query/builder.py +67 -18
- notionary/data_source/query/resolver.py +16 -5
- notionary/data_source/query/schema.py +24 -6
- notionary/data_source/query/validator.py +18 -6
- notionary/data_source/schema/registry.py +31 -12
- notionary/data_source/schema/service.py +66 -20
- notionary/data_source/schemas.py +2 -2
- notionary/data_source/service.py +103 -43
- notionary/database/client.py +27 -9
- notionary/database/database_metadata_update_client.py +12 -4
- notionary/database/schemas.py +2 -2
- notionary/database/service.py +14 -9
- notionary/exceptions/__init__.py +20 -4
- notionary/exceptions/api.py +2 -2
- notionary/exceptions/base.py +1 -1
- notionary/exceptions/block_parsing.py +9 -5
- notionary/exceptions/data_source/builder.py +13 -7
- notionary/exceptions/data_source/properties.py +6 -4
- notionary/exceptions/file_upload.py +76 -0
- notionary/exceptions/properties.py +7 -5
- notionary/exceptions/search.py +10 -6
- notionary/file_upload/__init__.py +4 -0
- notionary/file_upload/client.py +128 -210
- notionary/file_upload/config/__init__.py +17 -0
- notionary/file_upload/config/config.py +39 -0
- notionary/file_upload/config/constants.py +16 -0
- notionary/file_upload/file/reader.py +28 -0
- notionary/file_upload/query/__init__.py +7 -0
- notionary/file_upload/query/builder.py +58 -0
- notionary/file_upload/query/models.py +37 -0
- notionary/file_upload/schemas.py +80 -0
- notionary/file_upload/service.py +182 -291
- notionary/file_upload/validation/factory.py +66 -0
- notionary/file_upload/validation/impl/file_name_length.py +25 -0
- notionary/file_upload/validation/models.py +134 -0
- notionary/file_upload/validation/port.py +7 -0
- notionary/file_upload/validation/service.py +17 -0
- notionary/file_upload/validation/validators/__init__.py +11 -0
- notionary/file_upload/validation/validators/file_exists.py +15 -0
- notionary/file_upload/validation/validators/file_extension.py +131 -0
- notionary/file_upload/validation/validators/file_name_length.py +21 -0
- notionary/file_upload/validation/validators/upload_limit.py +31 -0
- notionary/http/client.py +33 -30
- notionary/page/content/__init__.py +9 -0
- notionary/page/content/factory.py +21 -7
- notionary/page/content/markdown/builder.py +85 -23
- notionary/page/content/markdown/nodes/audio.py +8 -4
- notionary/page/content/markdown/nodes/base.py +3 -3
- notionary/page/content/markdown/nodes/bookmark.py +5 -3
- notionary/page/content/markdown/nodes/breadcrumb.py +2 -2
- notionary/page/content/markdown/nodes/bulleted_list.py +5 -3
- notionary/page/content/markdown/nodes/callout.py +2 -2
- notionary/page/content/markdown/nodes/code.py +5 -3
- notionary/page/content/markdown/nodes/columns.py +3 -3
- notionary/page/content/markdown/nodes/container.py +9 -5
- notionary/page/content/markdown/nodes/divider.py +2 -2
- notionary/page/content/markdown/nodes/embed.py +8 -4
- notionary/page/content/markdown/nodes/equation.py +4 -2
- notionary/page/content/markdown/nodes/file.py +8 -4
- notionary/page/content/markdown/nodes/heading.py +2 -2
- notionary/page/content/markdown/nodes/image.py +8 -4
- notionary/page/content/markdown/nodes/mixins/caption.py +5 -3
- notionary/page/content/markdown/nodes/numbered_list.py +5 -3
- notionary/page/content/markdown/nodes/paragraph.py +4 -2
- notionary/page/content/markdown/nodes/pdf.py +8 -4
- notionary/page/content/markdown/nodes/quote.py +2 -2
- notionary/page/content/markdown/nodes/space.py +2 -2
- notionary/page/content/markdown/nodes/table.py +8 -5
- notionary/page/content/markdown/nodes/table_of_contents.py +2 -2
- notionary/page/content/markdown/nodes/todo.py +15 -7
- notionary/page/content/markdown/nodes/toggle.py +2 -2
- notionary/page/content/markdown/nodes/video.py +8 -4
- notionary/page/content/markdown/structured_output/__init__.py +73 -0
- notionary/page/content/markdown/structured_output/models.py +391 -0
- notionary/page/content/markdown/structured_output/service.py +211 -0
- notionary/page/content/parser/context.py +1 -1
- notionary/page/content/parser/factory.py +26 -8
- notionary/page/content/parser/parsers/audio.py +12 -32
- notionary/page/content/parser/parsers/base.py +2 -2
- notionary/page/content/parser/parsers/bookmark.py +2 -2
- notionary/page/content/parser/parsers/breadcrumb.py +2 -2
- notionary/page/content/parser/parsers/bulleted_list.py +19 -6
- notionary/page/content/parser/parsers/callout.py +15 -5
- notionary/page/content/parser/parsers/caption.py +9 -3
- notionary/page/content/parser/parsers/code.py +21 -7
- notionary/page/content/parser/parsers/column.py +8 -4
- notionary/page/content/parser/parsers/column_list.py +19 -7
- notionary/page/content/parser/parsers/divider.py +2 -2
- notionary/page/content/parser/parsers/embed.py +2 -4
- notionary/page/content/parser/parsers/equation.py +8 -4
- notionary/page/content/parser/parsers/file.py +12 -34
- notionary/page/content/parser/parsers/file_like_block.py +109 -0
- notionary/page/content/parser/parsers/heading.py +31 -10
- notionary/page/content/parser/parsers/image.py +12 -34
- notionary/page/content/parser/parsers/numbered_list.py +18 -6
- notionary/page/content/parser/parsers/paragraph.py +3 -1
- notionary/page/content/parser/parsers/pdf.py +12 -34
- notionary/page/content/parser/parsers/quote.py +28 -9
- notionary/page/content/parser/parsers/space.py +2 -2
- notionary/page/content/parser/parsers/table.py +31 -10
- notionary/page/content/parser/parsers/table_of_contents.py +7 -3
- notionary/page/content/parser/parsers/todo.py +15 -5
- notionary/page/content/parser/parsers/toggle.py +15 -5
- notionary/page/content/parser/parsers/video.py +12 -34
- notionary/page/content/parser/post_processing/handlers/rich_text_length.py +8 -2
- notionary/page/content/parser/post_processing/handlers/rich_text_length_truncation.py +8 -2
- notionary/page/content/parser/post_processing/service.py +3 -1
- notionary/page/content/parser/pre_processsing/handlers/column_syntax.py +21 -7
- notionary/page/content/parser/pre_processsing/handlers/indentation.py +11 -4
- notionary/page/content/parser/pre_processsing/handlers/video_syntax.py +13 -6
- notionary/page/content/parser/service.py +4 -1
- notionary/page/content/renderer/context.py +15 -5
- notionary/page/content/renderer/factory.py +12 -6
- notionary/page/content/renderer/post_processing/handlers/numbered_list.py +19 -9
- notionary/page/content/renderer/renderers/audio.py +20 -23
- notionary/page/content/renderer/renderers/base.py +3 -3
- notionary/page/content/renderer/renderers/bookmark.py +3 -1
- notionary/page/content/renderer/renderers/bulleted_list.py +11 -5
- notionary/page/content/renderer/renderers/callout.py +19 -7
- notionary/page/content/renderer/renderers/captioned_block.py +11 -5
- notionary/page/content/renderer/renderers/code.py +6 -2
- notionary/page/content/renderer/renderers/column.py +3 -1
- notionary/page/content/renderer/renderers/column_list.py +3 -1
- notionary/page/content/renderer/renderers/embed.py +3 -1
- notionary/page/content/renderer/renderers/equation.py +3 -1
- notionary/page/content/renderer/renderers/file.py +20 -23
- notionary/page/content/renderer/renderers/file_like_block.py +47 -0
- notionary/page/content/renderer/renderers/heading.py +22 -8
- notionary/page/content/renderer/renderers/image.py +20 -23
- notionary/page/content/renderer/renderers/numbered_list.py +8 -3
- notionary/page/content/renderer/renderers/paragraph.py +12 -4
- notionary/page/content/renderer/renderers/pdf.py +20 -23
- notionary/page/content/renderer/renderers/quote.py +14 -6
- notionary/page/content/renderer/renderers/table.py +15 -5
- notionary/page/content/renderer/renderers/todo.py +16 -6
- notionary/page/content/renderer/renderers/toggle.py +8 -4
- notionary/page/content/renderer/renderers/video.py +20 -23
- notionary/page/content/renderer/service.py +9 -3
- notionary/page/content/service.py +21 -7
- notionary/page/content/syntax/definition/__init__.py +11 -0
- notionary/page/content/syntax/definition/models.py +57 -0
- notionary/page/content/syntax/definition/registry.py +371 -0
- notionary/page/content/syntax/prompts/__init__.py +4 -0
- notionary/page/content/syntax/prompts/models.py +11 -0
- notionary/page/content/syntax/prompts/registry.py +703 -0
- notionary/page/page_metadata_update_client.py +12 -4
- notionary/page/properties/client.py +46 -16
- notionary/page/properties/factory.py +6 -2
- notionary/page/properties/{models.py → schemas.py} +93 -107
- notionary/page/properties/service.py +111 -37
- notionary/page/schemas.py +3 -3
- notionary/page/service.py +21 -7
- notionary/shared/entity/client.py +6 -2
- notionary/shared/entity/dto_parsers.py +4 -37
- notionary/shared/entity/entity_metadata_update_client.py +25 -5
- notionary/shared/entity/schemas.py +6 -6
- notionary/shared/entity/service.py +89 -35
- notionary/shared/models/file.py +36 -6
- notionary/shared/models/icon.py +5 -12
- notionary/user/base.py +6 -2
- notionary/user/bot.py +22 -14
- notionary/user/client.py +3 -1
- notionary/user/person.py +3 -1
- notionary/user/schemas.py +3 -1
- notionary/user/service.py +6 -2
- notionary/utils/decorators.py +13 -9
- notionary/utils/fuzzy.py +6 -2
- notionary/utils/mixins/logging.py +3 -1
- notionary/utils/pagination.py +14 -4
- notionary/workspace/__init__.py +6 -2
- notionary/workspace/query/__init__.py +2 -1
- notionary/workspace/query/service.py +42 -13
- notionary/workspace/service.py +74 -46
- {notionary-0.3.1.dist-info → notionary-0.4.1.dist-info}/METADATA +1 -1
- notionary-0.4.1.dist-info/RECORD +236 -0
- notionary/file_upload/models.py +0 -69
- notionary/page/blocks/client.py +0 -1
- notionary/page/content/syntax/__init__.py +0 -4
- notionary/page/content/syntax/models.py +0 -66
- notionary/page/content/syntax/registry.py +0 -393
- notionary/page/page_context.py +0 -50
- notionary/shared/models/cover.py +0 -20
- notionary-0.3.1.dist-info/RECORD +0 -211
- /notionary/page/content/syntax/{grammar.py → definition/grammar.py} +0 -0
- {notionary-0.3.1.dist-info → notionary-0.4.1.dist-info}/WHEEL +0 -0
- {notionary-0.3.1.dist-info → notionary-0.4.1.dist-info}/licenses/LICENSE +0 -0
|
@@ -38,13 +38,25 @@ class MarkdownBuilder:
|
|
|
38
38
|
def __init__(self) -> None:
|
|
39
39
|
self.children: list[MarkdownNode] = []
|
|
40
40
|
|
|
41
|
-
def h1(
|
|
41
|
+
def h1(
|
|
42
|
+
self,
|
|
43
|
+
text: str,
|
|
44
|
+
builder_func: Callable[[MarkdownBuilder], MarkdownBuilder] | None = None,
|
|
45
|
+
) -> Self:
|
|
42
46
|
return self._add_heading(text, 1, builder_func)
|
|
43
47
|
|
|
44
|
-
def h2(
|
|
48
|
+
def h2(
|
|
49
|
+
self,
|
|
50
|
+
text: str,
|
|
51
|
+
builder_func: Callable[[MarkdownBuilder], MarkdownBuilder] | None = None,
|
|
52
|
+
) -> Self:
|
|
45
53
|
return self._add_heading(text, 2, builder_func)
|
|
46
54
|
|
|
47
|
-
def h3(
|
|
55
|
+
def h3(
|
|
56
|
+
self,
|
|
57
|
+
text: str,
|
|
58
|
+
builder_func: Callable[[MarkdownBuilder], MarkdownBuilder] | None = None,
|
|
59
|
+
) -> Self:
|
|
48
60
|
return self._add_heading(text, 3, builder_func)
|
|
49
61
|
|
|
50
62
|
def paragraph(self, text: str) -> Self:
|
|
@@ -55,7 +67,11 @@ class MarkdownBuilder:
|
|
|
55
67
|
self.children.append(SpaceMarkdownNode())
|
|
56
68
|
return self
|
|
57
69
|
|
|
58
|
-
def quote(
|
|
70
|
+
def quote(
|
|
71
|
+
self,
|
|
72
|
+
text: str,
|
|
73
|
+
builder_func: Callable[[MarkdownBuilder], MarkdownBuilder] | None = None,
|
|
74
|
+
) -> Self:
|
|
59
75
|
children = self._build_children(builder_func)
|
|
60
76
|
self.children.append(QuoteMarkdownNode(text=text, children=children))
|
|
61
77
|
return self
|
|
@@ -69,12 +85,16 @@ class MarkdownBuilder:
|
|
|
69
85
|
return self
|
|
70
86
|
|
|
71
87
|
def numbered_list_item(
|
|
72
|
-
self,
|
|
88
|
+
self,
|
|
89
|
+
text: str,
|
|
90
|
+
builder_func: Callable[[MarkdownBuilder], MarkdownBuilder] | None = None,
|
|
73
91
|
) -> Self:
|
|
74
92
|
children = self._build_children(builder_func)
|
|
75
93
|
wrapped = flatten_children(children)
|
|
76
94
|
child_nodes = [wrapped] if wrapped else None
|
|
77
|
-
self.children.append(
|
|
95
|
+
self.children.append(
|
|
96
|
+
NumberedListMarkdownNode(texts=[text], children=child_nodes)
|
|
97
|
+
)
|
|
78
98
|
return self
|
|
79
99
|
|
|
80
100
|
def bulleted_list(self, items: list[str]) -> Self:
|
|
@@ -82,12 +102,16 @@ class MarkdownBuilder:
|
|
|
82
102
|
return self
|
|
83
103
|
|
|
84
104
|
def bulleted_list_item(
|
|
85
|
-
self,
|
|
105
|
+
self,
|
|
106
|
+
text: str,
|
|
107
|
+
builder_func: Callable[[MarkdownBuilder], MarkdownBuilder] | None = None,
|
|
86
108
|
) -> Self:
|
|
87
109
|
children = self._build_children(builder_func)
|
|
88
110
|
wrapped = flatten_children(children)
|
|
89
111
|
child_nodes = [wrapped] if wrapped else None
|
|
90
|
-
self.children.append(
|
|
112
|
+
self.children.append(
|
|
113
|
+
BulletedListMarkdownNode(texts=[text], children=child_nodes)
|
|
114
|
+
)
|
|
91
115
|
return self
|
|
92
116
|
|
|
93
117
|
def todo(
|
|
@@ -97,14 +121,22 @@ class MarkdownBuilder:
|
|
|
97
121
|
builder_func: Callable[[MarkdownBuilder], MarkdownBuilder] | None = None,
|
|
98
122
|
) -> Self:
|
|
99
123
|
children = self._build_children(builder_func)
|
|
100
|
-
self.children.append(
|
|
124
|
+
self.children.append(
|
|
125
|
+
TodoMarkdownNode(text=text, checked=checked, children=children)
|
|
126
|
+
)
|
|
101
127
|
return self
|
|
102
128
|
|
|
103
|
-
def checked_todo(
|
|
129
|
+
def checked_todo(
|
|
130
|
+
self,
|
|
131
|
+
text: str,
|
|
132
|
+
builder_func: Callable[[MarkdownBuilder], MarkdownBuilder] | None = None,
|
|
133
|
+
) -> Self:
|
|
104
134
|
return self.todo(text, checked=True, builder_func=builder_func)
|
|
105
135
|
|
|
106
136
|
def unchecked_todo(
|
|
107
|
-
self,
|
|
137
|
+
self,
|
|
138
|
+
text: str,
|
|
139
|
+
builder_func: Callable[[MarkdownBuilder], MarkdownBuilder] | None = None,
|
|
108
140
|
) -> Self:
|
|
109
141
|
return self.todo(text, checked=False, builder_func=builder_func)
|
|
110
142
|
|
|
@@ -126,10 +158,14 @@ class MarkdownBuilder:
|
|
|
126
158
|
builder_func: Callable[[MarkdownBuilder], MarkdownBuilder] | None = None,
|
|
127
159
|
) -> Self:
|
|
128
160
|
children = self._build_children(builder_func)
|
|
129
|
-
self.children.append(
|
|
161
|
+
self.children.append(
|
|
162
|
+
CalloutMarkdownNode(text=text, emoji=emoji, children=children)
|
|
163
|
+
)
|
|
130
164
|
return self
|
|
131
165
|
|
|
132
|
-
def toggle(
|
|
166
|
+
def toggle(
|
|
167
|
+
self, title: str, builder_func: Callable[[MarkdownBuilder], MarkdownBuilder]
|
|
168
|
+
) -> Self:
|
|
133
169
|
children = self._build_children(builder_func)
|
|
134
170
|
self.children.append(ToggleMarkdownNode(title=title, children=children))
|
|
135
171
|
return self
|
|
@@ -154,20 +190,35 @@ class MarkdownBuilder:
|
|
|
154
190
|
self.children.append(PdfMarkdownNode(url=url, caption=caption))
|
|
155
191
|
return self
|
|
156
192
|
|
|
157
|
-
def bookmark(
|
|
158
|
-
self
|
|
193
|
+
def bookmark(
|
|
194
|
+
self, url: str, title: str | None = None, caption: str | None = None
|
|
195
|
+
) -> Self:
|
|
196
|
+
self.children.append(
|
|
197
|
+
BookmarkMarkdownNode(url=url, title=title, caption=caption)
|
|
198
|
+
)
|
|
159
199
|
return self
|
|
160
200
|
|
|
161
201
|
def embed(self, url: str, caption: str | None = None) -> Self:
|
|
162
202
|
self.children.append(EmbedMarkdownNode(url=url, caption=caption))
|
|
163
203
|
return self
|
|
164
204
|
|
|
165
|
-
def code(
|
|
166
|
-
self
|
|
205
|
+
def code(
|
|
206
|
+
self,
|
|
207
|
+
code: str,
|
|
208
|
+
language: CodingLanguage | None = None,
|
|
209
|
+
caption: str | None = None,
|
|
210
|
+
) -> Self:
|
|
211
|
+
self.children.append(
|
|
212
|
+
CodeMarkdownNode(code=code, language=language, caption=caption)
|
|
213
|
+
)
|
|
167
214
|
return self
|
|
168
215
|
|
|
169
216
|
def mermaid(self, diagram: str, caption: str | None = None) -> Self:
|
|
170
|
-
self.children.append(
|
|
217
|
+
self.children.append(
|
|
218
|
+
CodeMarkdownNode(
|
|
219
|
+
code=diagram, language=CodingLanguage.MERMAID.value, caption=caption
|
|
220
|
+
)
|
|
221
|
+
)
|
|
171
222
|
return self
|
|
172
223
|
|
|
173
224
|
def table(self, headers: list[str], rows: list[list[str]]) -> Self:
|
|
@@ -196,16 +247,25 @@ class MarkdownBuilder:
|
|
|
196
247
|
return self
|
|
197
248
|
|
|
198
249
|
def build(self) -> str:
|
|
199
|
-
return "\n\n".join(
|
|
250
|
+
return "\n\n".join(
|
|
251
|
+
child.to_markdown() for child in self.children if child is not None
|
|
252
|
+
)
|
|
200
253
|
|
|
201
254
|
def _add_heading(
|
|
202
|
-
self,
|
|
255
|
+
self,
|
|
256
|
+
text: str,
|
|
257
|
+
level: int,
|
|
258
|
+
builder_func: Callable[[MarkdownBuilder], MarkdownBuilder] | None,
|
|
203
259
|
) -> Self:
|
|
204
260
|
children = self._build_children(builder_func)
|
|
205
|
-
self.children.append(
|
|
261
|
+
self.children.append(
|
|
262
|
+
HeadingMarkdownNode(text=text, level=level, children=children)
|
|
263
|
+
)
|
|
206
264
|
return self
|
|
207
265
|
|
|
208
|
-
def _build_children(
|
|
266
|
+
def _build_children(
|
|
267
|
+
self, builder_func: Callable[[MarkdownBuilder], MarkdownBuilder] | None
|
|
268
|
+
) -> list[MarkdownNode]:
|
|
209
269
|
if builder_func is None:
|
|
210
270
|
return []
|
|
211
271
|
|
|
@@ -222,5 +282,7 @@ class MarkdownBuilder:
|
|
|
222
282
|
for i, builder_func in enumerate(builder_funcs):
|
|
223
283
|
width_ratio = width_ratios[i] if width_ratios else None
|
|
224
284
|
children = self._build_children(builder_func)
|
|
225
|
-
columns.append(
|
|
285
|
+
columns.append(
|
|
286
|
+
ColumnMarkdownNode(children=children, width_ratio=width_ratio)
|
|
287
|
+
)
|
|
226
288
|
return columns
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
from typing import override
|
|
2
2
|
|
|
3
3
|
from notionary.page.content.markdown.nodes.base import MarkdownNode
|
|
4
|
-
from notionary.page.content.markdown.nodes.mixins.caption import
|
|
5
|
-
|
|
4
|
+
from notionary.page.content.markdown.nodes.mixins.caption import (
|
|
5
|
+
CaptionMarkdownNodeMixin,
|
|
6
|
+
)
|
|
7
|
+
from notionary.page.content.syntax.definition import SyntaxDefinitionRegistry
|
|
6
8
|
|
|
7
9
|
|
|
8
10
|
class AudioMarkdownNode(MarkdownNode, CaptionMarkdownNodeMixin):
|
|
@@ -10,7 +12,7 @@ class AudioMarkdownNode(MarkdownNode, CaptionMarkdownNodeMixin):
|
|
|
10
12
|
self,
|
|
11
13
|
url: str,
|
|
12
14
|
caption: str | None = None,
|
|
13
|
-
syntax_registry:
|
|
15
|
+
syntax_registry: SyntaxDefinitionRegistry | None = None,
|
|
14
16
|
) -> None:
|
|
15
17
|
super().__init__(syntax_registry=syntax_registry)
|
|
16
18
|
self.url = url
|
|
@@ -19,5 +21,7 @@ class AudioMarkdownNode(MarkdownNode, CaptionMarkdownNodeMixin):
|
|
|
19
21
|
@override
|
|
20
22
|
def to_markdown(self) -> str:
|
|
21
23
|
audio_syntax = self._syntax_registry.get_audio_syntax()
|
|
22
|
-
base_markdown =
|
|
24
|
+
base_markdown = (
|
|
25
|
+
f"{audio_syntax.start_delimiter}{self.url}{audio_syntax.end_delimiter}"
|
|
26
|
+
)
|
|
23
27
|
return self._append_caption_to_markdown(base_markdown, self.caption)
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
from abc import ABC, abstractmethod
|
|
2
2
|
|
|
3
|
-
from notionary.page.content.syntax import
|
|
3
|
+
from notionary.page.content.syntax.definition import SyntaxDefinitionRegistry
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
class MarkdownNode(ABC):
|
|
7
|
-
def __init__(self, syntax_registry:
|
|
8
|
-
self._syntax_registry = syntax_registry or
|
|
7
|
+
def __init__(self, syntax_registry: SyntaxDefinitionRegistry | None = None) -> None:
|
|
8
|
+
self._syntax_registry = syntax_registry or SyntaxDefinitionRegistry()
|
|
9
9
|
|
|
10
10
|
@abstractmethod
|
|
11
11
|
def to_markdown(self) -> str:
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
from typing import override
|
|
2
2
|
|
|
3
3
|
from notionary.page.content.markdown.nodes.base import MarkdownNode
|
|
4
|
-
from notionary.page.content.markdown.nodes.mixins.caption import
|
|
5
|
-
|
|
4
|
+
from notionary.page.content.markdown.nodes.mixins.caption import (
|
|
5
|
+
CaptionMarkdownNodeMixin,
|
|
6
|
+
)
|
|
7
|
+
from notionary.page.content.syntax.definition import SyntaxDefinitionRegistry
|
|
6
8
|
|
|
7
9
|
|
|
8
10
|
class BookmarkMarkdownNode(MarkdownNode, CaptionMarkdownNodeMixin):
|
|
@@ -11,7 +13,7 @@ class BookmarkMarkdownNode(MarkdownNode, CaptionMarkdownNodeMixin):
|
|
|
11
13
|
url: str,
|
|
12
14
|
title: str | None = None,
|
|
13
15
|
caption: str | None = None,
|
|
14
|
-
syntax_registry:
|
|
16
|
+
syntax_registry: SyntaxDefinitionRegistry | None = None,
|
|
15
17
|
) -> None:
|
|
16
18
|
super().__init__(syntax_registry=syntax_registry)
|
|
17
19
|
self.url = url
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
from typing import override
|
|
2
2
|
|
|
3
3
|
from notionary.page.content.markdown.nodes.base import MarkdownNode
|
|
4
|
-
from notionary.page.content.syntax import
|
|
4
|
+
from notionary.page.content.syntax.definition import SyntaxDefinitionRegistry
|
|
5
5
|
|
|
6
6
|
|
|
7
7
|
class BreadcrumbMarkdownNode(MarkdownNode):
|
|
8
|
-
def __init__(self, syntax_registry:
|
|
8
|
+
def __init__(self, syntax_registry: SyntaxDefinitionRegistry | None = None) -> None:
|
|
9
9
|
super().__init__(syntax_registry=syntax_registry)
|
|
10
10
|
|
|
11
11
|
@override
|
|
@@ -2,7 +2,7 @@ from typing import override
|
|
|
2
2
|
|
|
3
3
|
from notionary.page.content.markdown.nodes.base import MarkdownNode
|
|
4
4
|
from notionary.page.content.markdown.nodes.container import ContainerNode
|
|
5
|
-
from notionary.page.content.syntax import
|
|
5
|
+
from notionary.page.content.syntax.definition import SyntaxDefinitionRegistry
|
|
6
6
|
|
|
7
7
|
|
|
8
8
|
class BulletedListMarkdownNode(ContainerNode):
|
|
@@ -10,7 +10,7 @@ class BulletedListMarkdownNode(ContainerNode):
|
|
|
10
10
|
self,
|
|
11
11
|
texts: list[str],
|
|
12
12
|
children: list[MarkdownNode | None] | None = None,
|
|
13
|
-
syntax_registry:
|
|
13
|
+
syntax_registry: SyntaxDefinitionRegistry | None = None,
|
|
14
14
|
) -> None:
|
|
15
15
|
super().__init__(syntax_registry=syntax_registry)
|
|
16
16
|
self.texts = texts
|
|
@@ -18,7 +18,9 @@ class BulletedListMarkdownNode(ContainerNode):
|
|
|
18
18
|
|
|
19
19
|
@override
|
|
20
20
|
def to_markdown(self) -> str:
|
|
21
|
-
list_items = [
|
|
21
|
+
list_items = [
|
|
22
|
+
self._render_list_item(index, text) for index, text in enumerate(self.texts)
|
|
23
|
+
]
|
|
22
24
|
return "\n".join(list_items)
|
|
23
25
|
|
|
24
26
|
def _render_list_item(self, index: int, text: str) -> str:
|
|
@@ -2,7 +2,7 @@ from typing import override
|
|
|
2
2
|
|
|
3
3
|
from notionary.page.content.markdown.nodes.base import MarkdownNode
|
|
4
4
|
from notionary.page.content.markdown.nodes.container import ContainerNode
|
|
5
|
-
from notionary.page.content.syntax import
|
|
5
|
+
from notionary.page.content.syntax.definition import SyntaxDefinitionRegistry
|
|
6
6
|
|
|
7
7
|
|
|
8
8
|
class CalloutMarkdownNode(ContainerNode):
|
|
@@ -11,7 +11,7 @@ class CalloutMarkdownNode(ContainerNode):
|
|
|
11
11
|
text: str,
|
|
12
12
|
emoji: str | None = None,
|
|
13
13
|
children: list[MarkdownNode] | None = None,
|
|
14
|
-
syntax_registry:
|
|
14
|
+
syntax_registry: SyntaxDefinitionRegistry | None = None,
|
|
15
15
|
):
|
|
16
16
|
super().__init__(syntax_registry=syntax_registry)
|
|
17
17
|
self.text = text
|
|
@@ -2,8 +2,10 @@ from typing import override
|
|
|
2
2
|
|
|
3
3
|
from notionary.blocks.enums import CodingLanguage
|
|
4
4
|
from notionary.page.content.markdown.nodes.base import MarkdownNode
|
|
5
|
-
from notionary.page.content.markdown.nodes.mixins.caption import
|
|
6
|
-
|
|
5
|
+
from notionary.page.content.markdown.nodes.mixins.caption import (
|
|
6
|
+
CaptionMarkdownNodeMixin,
|
|
7
|
+
)
|
|
8
|
+
from notionary.page.content.syntax.definition import SyntaxDefinitionRegistry
|
|
7
9
|
|
|
8
10
|
|
|
9
11
|
class CodeMarkdownNode(MarkdownNode, CaptionMarkdownNodeMixin):
|
|
@@ -12,7 +14,7 @@ class CodeMarkdownNode(MarkdownNode, CaptionMarkdownNodeMixin):
|
|
|
12
14
|
code: str,
|
|
13
15
|
language: CodingLanguage | None = None,
|
|
14
16
|
caption: str | None = None,
|
|
15
|
-
syntax_registry:
|
|
17
|
+
syntax_registry: SyntaxDefinitionRegistry | None = None,
|
|
16
18
|
) -> None:
|
|
17
19
|
super().__init__(syntax_registry=syntax_registry)
|
|
18
20
|
self.code = code
|
|
@@ -2,7 +2,7 @@ from typing import override
|
|
|
2
2
|
|
|
3
3
|
from notionary.page.content.markdown.nodes.base import MarkdownNode
|
|
4
4
|
from notionary.page.content.markdown.nodes.container import ContainerNode
|
|
5
|
-
from notionary.page.content.syntax import
|
|
5
|
+
from notionary.page.content.syntax.definition import SyntaxDefinitionRegistry
|
|
6
6
|
|
|
7
7
|
|
|
8
8
|
class ColumnMarkdownNode(ContainerNode):
|
|
@@ -10,7 +10,7 @@ class ColumnMarkdownNode(ContainerNode):
|
|
|
10
10
|
self,
|
|
11
11
|
children: list[MarkdownNode] | None = None,
|
|
12
12
|
width_ratio: float | None = None,
|
|
13
|
-
syntax_registry:
|
|
13
|
+
syntax_registry: SyntaxDefinitionRegistry | None = None,
|
|
14
14
|
):
|
|
15
15
|
super().__init__(syntax_registry=syntax_registry)
|
|
16
16
|
self.children = children or []
|
|
@@ -34,7 +34,7 @@ class ColumnListMarkdownNode(MarkdownNode):
|
|
|
34
34
|
def __init__(
|
|
35
35
|
self,
|
|
36
36
|
columns: list[ColumnMarkdownNode] | None = None,
|
|
37
|
-
syntax_registry:
|
|
37
|
+
syntax_registry: SyntaxDefinitionRegistry | None = None,
|
|
38
38
|
):
|
|
39
39
|
super().__init__(syntax_registry=syntax_registry)
|
|
40
40
|
self.columns = columns or []
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
from notionary.page.content.markdown.nodes.base import MarkdownNode
|
|
2
|
-
from notionary.page.content.syntax import
|
|
3
|
-
from notionary.page.content.syntax.grammar import MarkdownGrammar
|
|
2
|
+
from notionary.page.content.syntax.definition import SyntaxDefinitionRegistry
|
|
3
|
+
from notionary.page.content.syntax.definition.grammar import MarkdownGrammar
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
def flatten_children(children: list[MarkdownNode]) -> MarkdownNode | None:
|
|
@@ -24,7 +24,7 @@ class _MultiChildWrapper(MarkdownNode):
|
|
|
24
24
|
class ContainerNode(MarkdownNode):
|
|
25
25
|
children: list[MarkdownNode]
|
|
26
26
|
|
|
27
|
-
def __init__(self, syntax_registry:
|
|
27
|
+
def __init__(self, syntax_registry: SyntaxDefinitionRegistry | None = None) -> None:
|
|
28
28
|
super().__init__(syntax_registry=syntax_registry)
|
|
29
29
|
grammar = self._get_grammar(syntax_registry)
|
|
30
30
|
self._spaces_per_nesting_level = grammar.spaces_per_nesting_level
|
|
@@ -60,5 +60,9 @@ class ContainerNode(MarkdownNode):
|
|
|
60
60
|
return "\n".join(f"{indent}{line}" if line.strip() else line for line in lines)
|
|
61
61
|
|
|
62
62
|
@staticmethod
|
|
63
|
-
def _get_grammar(
|
|
64
|
-
|
|
63
|
+
def _get_grammar(
|
|
64
|
+
syntax_registry: SyntaxDefinitionRegistry | None,
|
|
65
|
+
) -> MarkdownGrammar:
|
|
66
|
+
return (
|
|
67
|
+
syntax_registry._markdown_grammar if syntax_registry else MarkdownGrammar()
|
|
68
|
+
)
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
from typing import override
|
|
2
2
|
|
|
3
3
|
from notionary.page.content.markdown.nodes.base import MarkdownNode
|
|
4
|
-
from notionary.page.content.syntax import
|
|
4
|
+
from notionary.page.content.syntax.definition import SyntaxDefinitionRegistry
|
|
5
5
|
|
|
6
6
|
|
|
7
7
|
class DividerMarkdownNode(MarkdownNode):
|
|
8
|
-
def __init__(self, syntax_registry:
|
|
8
|
+
def __init__(self, syntax_registry: SyntaxDefinitionRegistry | None = None) -> None:
|
|
9
9
|
super().__init__(syntax_registry=syntax_registry)
|
|
10
10
|
|
|
11
11
|
@override
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
from typing import override
|
|
2
2
|
|
|
3
3
|
from notionary.page.content.markdown.nodes.base import MarkdownNode
|
|
4
|
-
from notionary.page.content.markdown.nodes.mixins.caption import
|
|
5
|
-
|
|
4
|
+
from notionary.page.content.markdown.nodes.mixins.caption import (
|
|
5
|
+
CaptionMarkdownNodeMixin,
|
|
6
|
+
)
|
|
7
|
+
from notionary.page.content.syntax.definition import SyntaxDefinitionRegistry
|
|
6
8
|
|
|
7
9
|
|
|
8
10
|
class EmbedMarkdownNode(MarkdownNode, CaptionMarkdownNodeMixin):
|
|
@@ -10,7 +12,7 @@ class EmbedMarkdownNode(MarkdownNode, CaptionMarkdownNodeMixin):
|
|
|
10
12
|
self,
|
|
11
13
|
url: str,
|
|
12
14
|
caption: str | None = None,
|
|
13
|
-
syntax_registry:
|
|
15
|
+
syntax_registry: SyntaxDefinitionRegistry | None = None,
|
|
14
16
|
) -> None:
|
|
15
17
|
super().__init__(syntax_registry=syntax_registry)
|
|
16
18
|
self.url = url
|
|
@@ -19,5 +21,7 @@ class EmbedMarkdownNode(MarkdownNode, CaptionMarkdownNodeMixin):
|
|
|
19
21
|
@override
|
|
20
22
|
def to_markdown(self) -> str:
|
|
21
23
|
embed_syntax = self._syntax_registry.get_embed_syntax()
|
|
22
|
-
base_markdown =
|
|
24
|
+
base_markdown = (
|
|
25
|
+
f"{embed_syntax.start_delimiter}{self.url}{embed_syntax.end_delimiter}"
|
|
26
|
+
)
|
|
23
27
|
return self._append_caption_to_markdown(base_markdown, self.caption)
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
from typing import override
|
|
2
2
|
|
|
3
3
|
from notionary.page.content.markdown.nodes.base import MarkdownNode
|
|
4
|
-
from notionary.page.content.syntax import
|
|
4
|
+
from notionary.page.content.syntax.definition import SyntaxDefinitionRegistry
|
|
5
5
|
|
|
6
6
|
|
|
7
7
|
class EquationMarkdownNode(MarkdownNode):
|
|
8
|
-
def __init__(
|
|
8
|
+
def __init__(
|
|
9
|
+
self, expression: str, syntax_registry: SyntaxDefinitionRegistry | None = None
|
|
10
|
+
) -> None:
|
|
9
11
|
super().__init__(syntax_registry=syntax_registry)
|
|
10
12
|
self.expression = expression
|
|
11
13
|
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
from typing import override
|
|
2
2
|
|
|
3
3
|
from notionary.page.content.markdown.nodes.base import MarkdownNode
|
|
4
|
-
from notionary.page.content.markdown.nodes.mixins.caption import
|
|
5
|
-
|
|
4
|
+
from notionary.page.content.markdown.nodes.mixins.caption import (
|
|
5
|
+
CaptionMarkdownNodeMixin,
|
|
6
|
+
)
|
|
7
|
+
from notionary.page.content.syntax.definition import SyntaxDefinitionRegistry
|
|
6
8
|
|
|
7
9
|
|
|
8
10
|
class FileMarkdownNode(MarkdownNode, CaptionMarkdownNodeMixin):
|
|
@@ -10,7 +12,7 @@ class FileMarkdownNode(MarkdownNode, CaptionMarkdownNodeMixin):
|
|
|
10
12
|
self,
|
|
11
13
|
url: str,
|
|
12
14
|
caption: str | None = None,
|
|
13
|
-
syntax_registry:
|
|
15
|
+
syntax_registry: SyntaxDefinitionRegistry | None = None,
|
|
14
16
|
) -> None:
|
|
15
17
|
super().__init__(syntax_registry=syntax_registry)
|
|
16
18
|
self.url = url
|
|
@@ -19,5 +21,7 @@ class FileMarkdownNode(MarkdownNode, CaptionMarkdownNodeMixin):
|
|
|
19
21
|
@override
|
|
20
22
|
def to_markdown(self) -> str:
|
|
21
23
|
file_syntax = self._syntax_registry.get_file_syntax()
|
|
22
|
-
base_markdown =
|
|
24
|
+
base_markdown = (
|
|
25
|
+
f"{file_syntax.start_delimiter}{self.url}{file_syntax.end_delimiter}"
|
|
26
|
+
)
|
|
23
27
|
return self._append_caption_to_markdown(base_markdown, self.caption)
|
|
@@ -2,7 +2,7 @@ from typing import override
|
|
|
2
2
|
|
|
3
3
|
from notionary.page.content.markdown.nodes.base import MarkdownNode
|
|
4
4
|
from notionary.page.content.markdown.nodes.container import ContainerNode
|
|
5
|
-
from notionary.page.content.syntax import
|
|
5
|
+
from notionary.page.content.syntax.definition import SyntaxDefinitionRegistry
|
|
6
6
|
|
|
7
7
|
|
|
8
8
|
class HeadingMarkdownNode(ContainerNode):
|
|
@@ -14,7 +14,7 @@ class HeadingMarkdownNode(ContainerNode):
|
|
|
14
14
|
text: str,
|
|
15
15
|
level: int = 1,
|
|
16
16
|
children: list[MarkdownNode] | None = None,
|
|
17
|
-
syntax_registry:
|
|
17
|
+
syntax_registry: SyntaxDefinitionRegistry | None = None,
|
|
18
18
|
) -> None:
|
|
19
19
|
super().__init__(syntax_registry=syntax_registry)
|
|
20
20
|
self.text = text
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
from typing import override
|
|
2
2
|
|
|
3
3
|
from notionary.page.content.markdown.nodes.base import MarkdownNode
|
|
4
|
-
from notionary.page.content.markdown.nodes.mixins.caption import
|
|
5
|
-
|
|
4
|
+
from notionary.page.content.markdown.nodes.mixins.caption import (
|
|
5
|
+
CaptionMarkdownNodeMixin,
|
|
6
|
+
)
|
|
7
|
+
from notionary.page.content.syntax.definition import SyntaxDefinitionRegistry
|
|
6
8
|
|
|
7
9
|
|
|
8
10
|
class ImageMarkdownNode(MarkdownNode, CaptionMarkdownNodeMixin):
|
|
@@ -10,7 +12,7 @@ class ImageMarkdownNode(MarkdownNode, CaptionMarkdownNodeMixin):
|
|
|
10
12
|
self,
|
|
11
13
|
url: str,
|
|
12
14
|
caption: str | None = None,
|
|
13
|
-
syntax_registry:
|
|
15
|
+
syntax_registry: SyntaxDefinitionRegistry | None = None,
|
|
14
16
|
) -> None:
|
|
15
17
|
super().__init__(syntax_registry=syntax_registry)
|
|
16
18
|
self.url = url
|
|
@@ -19,5 +21,7 @@ class ImageMarkdownNode(MarkdownNode, CaptionMarkdownNodeMixin):
|
|
|
19
21
|
@override
|
|
20
22
|
def to_markdown(self) -> str:
|
|
21
23
|
image_syntax = self._syntax_registry.get_image_syntax()
|
|
22
|
-
base_markdown =
|
|
24
|
+
base_markdown = (
|
|
25
|
+
f"{image_syntax.start_delimiter}{self.url}{image_syntax.end_delimiter}"
|
|
26
|
+
)
|
|
23
27
|
return self._append_caption_to_markdown(base_markdown, self.caption)
|
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
from notionary.page.content.syntax import
|
|
1
|
+
from notionary.page.content.syntax.definition import SyntaxDefinitionRegistry
|
|
2
2
|
|
|
3
3
|
|
|
4
4
|
class CaptionMarkdownNodeMixin:
|
|
5
|
-
_syntax_registry:
|
|
5
|
+
_syntax_registry: SyntaxDefinitionRegistry
|
|
6
6
|
|
|
7
|
-
def _append_caption_to_markdown(
|
|
7
|
+
def _append_caption_to_markdown(
|
|
8
|
+
self, base_markdown: str, caption: str | None
|
|
9
|
+
) -> str:
|
|
8
10
|
if not caption:
|
|
9
11
|
return base_markdown
|
|
10
12
|
|
|
@@ -2,7 +2,7 @@ from typing import override
|
|
|
2
2
|
|
|
3
3
|
from notionary.page.content.markdown.nodes.base import MarkdownNode
|
|
4
4
|
from notionary.page.content.markdown.nodes.container import ContainerNode
|
|
5
|
-
from notionary.page.content.syntax import
|
|
5
|
+
from notionary.page.content.syntax.definition import SyntaxDefinitionRegistry
|
|
6
6
|
|
|
7
7
|
|
|
8
8
|
class NumberedListMarkdownNode(ContainerNode):
|
|
@@ -10,7 +10,7 @@ class NumberedListMarkdownNode(ContainerNode):
|
|
|
10
10
|
self,
|
|
11
11
|
texts: list[str],
|
|
12
12
|
children: list[MarkdownNode | None] | None = None,
|
|
13
|
-
syntax_registry:
|
|
13
|
+
syntax_registry: SyntaxDefinitionRegistry | None = None,
|
|
14
14
|
):
|
|
15
15
|
super().__init__(syntax_registry=syntax_registry)
|
|
16
16
|
self.texts = texts
|
|
@@ -18,7 +18,9 @@ class NumberedListMarkdownNode(ContainerNode):
|
|
|
18
18
|
|
|
19
19
|
@override
|
|
20
20
|
def to_markdown(self) -> str:
|
|
21
|
-
list_items = [
|
|
21
|
+
list_items = [
|
|
22
|
+
self._render_list_item(index, text) for index, text in enumerate(self.texts)
|
|
23
|
+
]
|
|
22
24
|
return "\n".join(list_items)
|
|
23
25
|
|
|
24
26
|
def _render_list_item(self, index: int, text: str) -> str:
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
from typing import override
|
|
2
2
|
|
|
3
3
|
from notionary.page.content.markdown.nodes.base import MarkdownNode
|
|
4
|
-
from notionary.page.content.syntax import
|
|
4
|
+
from notionary.page.content.syntax.definition import SyntaxDefinitionRegistry
|
|
5
5
|
|
|
6
6
|
|
|
7
7
|
class ParagraphMarkdownNode(MarkdownNode):
|
|
8
|
-
def __init__(
|
|
8
|
+
def __init__(
|
|
9
|
+
self, text: str, syntax_registry: SyntaxDefinitionRegistry | None = None
|
|
10
|
+
):
|
|
9
11
|
super().__init__(syntax_registry=syntax_registry)
|
|
10
12
|
self.text = text
|
|
11
13
|
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
from typing import override
|
|
2
2
|
|
|
3
3
|
from notionary.page.content.markdown.nodes.base import MarkdownNode
|
|
4
|
-
from notionary.page.content.markdown.nodes.mixins.caption import
|
|
5
|
-
|
|
4
|
+
from notionary.page.content.markdown.nodes.mixins.caption import (
|
|
5
|
+
CaptionMarkdownNodeMixin,
|
|
6
|
+
)
|
|
7
|
+
from notionary.page.content.syntax.definition import SyntaxDefinitionRegistry
|
|
6
8
|
|
|
7
9
|
|
|
8
10
|
class PdfMarkdownNode(MarkdownNode, CaptionMarkdownNodeMixin):
|
|
@@ -10,7 +12,7 @@ class PdfMarkdownNode(MarkdownNode, CaptionMarkdownNodeMixin):
|
|
|
10
12
|
self,
|
|
11
13
|
url: str,
|
|
12
14
|
caption: str | None = None,
|
|
13
|
-
syntax_registry:
|
|
15
|
+
syntax_registry: SyntaxDefinitionRegistry | None = None,
|
|
14
16
|
) -> None:
|
|
15
17
|
super().__init__(syntax_registry=syntax_registry)
|
|
16
18
|
self.url = url
|
|
@@ -19,5 +21,7 @@ class PdfMarkdownNode(MarkdownNode, CaptionMarkdownNodeMixin):
|
|
|
19
21
|
@override
|
|
20
22
|
def to_markdown(self) -> str:
|
|
21
23
|
pdf_syntax = self._syntax_registry.get_pdf_syntax()
|
|
22
|
-
base_markdown =
|
|
24
|
+
base_markdown = (
|
|
25
|
+
f"{pdf_syntax.start_delimiter}{self.url}{pdf_syntax.end_delimiter}"
|
|
26
|
+
)
|
|
23
27
|
return self._append_caption_to_markdown(base_markdown, self.caption)
|