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.
Files changed (201) hide show
  1. notionary/__init__.py +49 -1
  2. notionary/blocks/client.py +37 -11
  3. notionary/blocks/enums.py +0 -6
  4. notionary/blocks/rich_text/markdown_rich_text_converter.py +49 -15
  5. notionary/blocks/rich_text/models.py +13 -4
  6. notionary/blocks/rich_text/name_id_resolver/data_source.py +9 -3
  7. notionary/blocks/rich_text/name_id_resolver/person.py +6 -2
  8. notionary/blocks/rich_text/rich_text_markdown_converter.py +10 -3
  9. notionary/blocks/schemas.py +33 -78
  10. notionary/comments/client.py +19 -6
  11. notionary/comments/factory.py +10 -3
  12. notionary/comments/schemas.py +10 -31
  13. notionary/comments/service.py +12 -4
  14. notionary/data_source/http/data_source_instance_client.py +59 -17
  15. notionary/data_source/properties/schemas.py +156 -115
  16. notionary/data_source/query/builder.py +67 -18
  17. notionary/data_source/query/resolver.py +16 -5
  18. notionary/data_source/query/schema.py +24 -6
  19. notionary/data_source/query/validator.py +18 -6
  20. notionary/data_source/schema/registry.py +31 -12
  21. notionary/data_source/schema/service.py +66 -20
  22. notionary/data_source/schemas.py +2 -2
  23. notionary/data_source/service.py +103 -43
  24. notionary/database/client.py +27 -9
  25. notionary/database/database_metadata_update_client.py +12 -4
  26. notionary/database/schemas.py +2 -2
  27. notionary/database/service.py +14 -9
  28. notionary/exceptions/__init__.py +20 -4
  29. notionary/exceptions/api.py +2 -2
  30. notionary/exceptions/base.py +1 -1
  31. notionary/exceptions/block_parsing.py +9 -5
  32. notionary/exceptions/data_source/builder.py +13 -7
  33. notionary/exceptions/data_source/properties.py +6 -4
  34. notionary/exceptions/file_upload.py +76 -0
  35. notionary/exceptions/properties.py +7 -5
  36. notionary/exceptions/search.py +10 -6
  37. notionary/file_upload/__init__.py +4 -0
  38. notionary/file_upload/client.py +128 -210
  39. notionary/file_upload/config/__init__.py +17 -0
  40. notionary/file_upload/config/config.py +39 -0
  41. notionary/file_upload/config/constants.py +16 -0
  42. notionary/file_upload/file/reader.py +28 -0
  43. notionary/file_upload/query/__init__.py +7 -0
  44. notionary/file_upload/query/builder.py +58 -0
  45. notionary/file_upload/query/models.py +37 -0
  46. notionary/file_upload/schemas.py +80 -0
  47. notionary/file_upload/service.py +182 -291
  48. notionary/file_upload/validation/factory.py +66 -0
  49. notionary/file_upload/validation/impl/file_name_length.py +25 -0
  50. notionary/file_upload/validation/models.py +134 -0
  51. notionary/file_upload/validation/port.py +7 -0
  52. notionary/file_upload/validation/service.py +17 -0
  53. notionary/file_upload/validation/validators/__init__.py +11 -0
  54. notionary/file_upload/validation/validators/file_exists.py +15 -0
  55. notionary/file_upload/validation/validators/file_extension.py +131 -0
  56. notionary/file_upload/validation/validators/file_name_length.py +21 -0
  57. notionary/file_upload/validation/validators/upload_limit.py +31 -0
  58. notionary/http/client.py +33 -30
  59. notionary/page/content/__init__.py +9 -0
  60. notionary/page/content/factory.py +21 -7
  61. notionary/page/content/markdown/builder.py +85 -23
  62. notionary/page/content/markdown/nodes/audio.py +8 -4
  63. notionary/page/content/markdown/nodes/base.py +3 -3
  64. notionary/page/content/markdown/nodes/bookmark.py +5 -3
  65. notionary/page/content/markdown/nodes/breadcrumb.py +2 -2
  66. notionary/page/content/markdown/nodes/bulleted_list.py +5 -3
  67. notionary/page/content/markdown/nodes/callout.py +2 -2
  68. notionary/page/content/markdown/nodes/code.py +5 -3
  69. notionary/page/content/markdown/nodes/columns.py +3 -3
  70. notionary/page/content/markdown/nodes/container.py +9 -5
  71. notionary/page/content/markdown/nodes/divider.py +2 -2
  72. notionary/page/content/markdown/nodes/embed.py +8 -4
  73. notionary/page/content/markdown/nodes/equation.py +4 -2
  74. notionary/page/content/markdown/nodes/file.py +8 -4
  75. notionary/page/content/markdown/nodes/heading.py +2 -2
  76. notionary/page/content/markdown/nodes/image.py +8 -4
  77. notionary/page/content/markdown/nodes/mixins/caption.py +5 -3
  78. notionary/page/content/markdown/nodes/numbered_list.py +5 -3
  79. notionary/page/content/markdown/nodes/paragraph.py +4 -2
  80. notionary/page/content/markdown/nodes/pdf.py +8 -4
  81. notionary/page/content/markdown/nodes/quote.py +2 -2
  82. notionary/page/content/markdown/nodes/space.py +2 -2
  83. notionary/page/content/markdown/nodes/table.py +8 -5
  84. notionary/page/content/markdown/nodes/table_of_contents.py +2 -2
  85. notionary/page/content/markdown/nodes/todo.py +15 -7
  86. notionary/page/content/markdown/nodes/toggle.py +2 -2
  87. notionary/page/content/markdown/nodes/video.py +8 -4
  88. notionary/page/content/markdown/structured_output/__init__.py +73 -0
  89. notionary/page/content/markdown/structured_output/models.py +391 -0
  90. notionary/page/content/markdown/structured_output/service.py +211 -0
  91. notionary/page/content/parser/context.py +1 -1
  92. notionary/page/content/parser/factory.py +26 -8
  93. notionary/page/content/parser/parsers/audio.py +12 -32
  94. notionary/page/content/parser/parsers/base.py +2 -2
  95. notionary/page/content/parser/parsers/bookmark.py +2 -2
  96. notionary/page/content/parser/parsers/breadcrumb.py +2 -2
  97. notionary/page/content/parser/parsers/bulleted_list.py +19 -6
  98. notionary/page/content/parser/parsers/callout.py +15 -5
  99. notionary/page/content/parser/parsers/caption.py +9 -3
  100. notionary/page/content/parser/parsers/code.py +21 -7
  101. notionary/page/content/parser/parsers/column.py +8 -4
  102. notionary/page/content/parser/parsers/column_list.py +19 -7
  103. notionary/page/content/parser/parsers/divider.py +2 -2
  104. notionary/page/content/parser/parsers/embed.py +2 -4
  105. notionary/page/content/parser/parsers/equation.py +8 -4
  106. notionary/page/content/parser/parsers/file.py +12 -34
  107. notionary/page/content/parser/parsers/file_like_block.py +109 -0
  108. notionary/page/content/parser/parsers/heading.py +31 -10
  109. notionary/page/content/parser/parsers/image.py +12 -34
  110. notionary/page/content/parser/parsers/numbered_list.py +18 -6
  111. notionary/page/content/parser/parsers/paragraph.py +3 -1
  112. notionary/page/content/parser/parsers/pdf.py +12 -34
  113. notionary/page/content/parser/parsers/quote.py +28 -9
  114. notionary/page/content/parser/parsers/space.py +2 -2
  115. notionary/page/content/parser/parsers/table.py +31 -10
  116. notionary/page/content/parser/parsers/table_of_contents.py +7 -3
  117. notionary/page/content/parser/parsers/todo.py +15 -5
  118. notionary/page/content/parser/parsers/toggle.py +15 -5
  119. notionary/page/content/parser/parsers/video.py +12 -34
  120. notionary/page/content/parser/post_processing/handlers/rich_text_length.py +8 -2
  121. notionary/page/content/parser/post_processing/handlers/rich_text_length_truncation.py +8 -2
  122. notionary/page/content/parser/post_processing/service.py +3 -1
  123. notionary/page/content/parser/pre_processsing/handlers/column_syntax.py +21 -7
  124. notionary/page/content/parser/pre_processsing/handlers/indentation.py +11 -4
  125. notionary/page/content/parser/pre_processsing/handlers/video_syntax.py +13 -6
  126. notionary/page/content/parser/service.py +4 -1
  127. notionary/page/content/renderer/context.py +15 -5
  128. notionary/page/content/renderer/factory.py +12 -6
  129. notionary/page/content/renderer/post_processing/handlers/numbered_list.py +19 -9
  130. notionary/page/content/renderer/renderers/audio.py +20 -23
  131. notionary/page/content/renderer/renderers/base.py +3 -3
  132. notionary/page/content/renderer/renderers/bookmark.py +3 -1
  133. notionary/page/content/renderer/renderers/bulleted_list.py +11 -5
  134. notionary/page/content/renderer/renderers/callout.py +19 -7
  135. notionary/page/content/renderer/renderers/captioned_block.py +11 -5
  136. notionary/page/content/renderer/renderers/code.py +6 -2
  137. notionary/page/content/renderer/renderers/column.py +3 -1
  138. notionary/page/content/renderer/renderers/column_list.py +3 -1
  139. notionary/page/content/renderer/renderers/embed.py +3 -1
  140. notionary/page/content/renderer/renderers/equation.py +3 -1
  141. notionary/page/content/renderer/renderers/file.py +20 -23
  142. notionary/page/content/renderer/renderers/file_like_block.py +47 -0
  143. notionary/page/content/renderer/renderers/heading.py +22 -8
  144. notionary/page/content/renderer/renderers/image.py +20 -23
  145. notionary/page/content/renderer/renderers/numbered_list.py +8 -3
  146. notionary/page/content/renderer/renderers/paragraph.py +12 -4
  147. notionary/page/content/renderer/renderers/pdf.py +20 -23
  148. notionary/page/content/renderer/renderers/quote.py +14 -6
  149. notionary/page/content/renderer/renderers/table.py +15 -5
  150. notionary/page/content/renderer/renderers/todo.py +16 -6
  151. notionary/page/content/renderer/renderers/toggle.py +8 -4
  152. notionary/page/content/renderer/renderers/video.py +20 -23
  153. notionary/page/content/renderer/service.py +9 -3
  154. notionary/page/content/service.py +21 -7
  155. notionary/page/content/syntax/definition/__init__.py +11 -0
  156. notionary/page/content/syntax/definition/models.py +57 -0
  157. notionary/page/content/syntax/definition/registry.py +371 -0
  158. notionary/page/content/syntax/prompts/__init__.py +4 -0
  159. notionary/page/content/syntax/prompts/models.py +11 -0
  160. notionary/page/content/syntax/prompts/registry.py +703 -0
  161. notionary/page/page_metadata_update_client.py +12 -4
  162. notionary/page/properties/client.py +46 -16
  163. notionary/page/properties/factory.py +6 -2
  164. notionary/page/properties/{models.py → schemas.py} +93 -107
  165. notionary/page/properties/service.py +111 -37
  166. notionary/page/schemas.py +3 -3
  167. notionary/page/service.py +21 -7
  168. notionary/shared/entity/client.py +6 -2
  169. notionary/shared/entity/dto_parsers.py +4 -37
  170. notionary/shared/entity/entity_metadata_update_client.py +25 -5
  171. notionary/shared/entity/schemas.py +6 -6
  172. notionary/shared/entity/service.py +89 -35
  173. notionary/shared/models/file.py +36 -6
  174. notionary/shared/models/icon.py +5 -12
  175. notionary/user/base.py +6 -2
  176. notionary/user/bot.py +22 -14
  177. notionary/user/client.py +3 -1
  178. notionary/user/person.py +3 -1
  179. notionary/user/schemas.py +3 -1
  180. notionary/user/service.py +6 -2
  181. notionary/utils/decorators.py +13 -9
  182. notionary/utils/fuzzy.py +6 -2
  183. notionary/utils/mixins/logging.py +3 -1
  184. notionary/utils/pagination.py +14 -4
  185. notionary/workspace/__init__.py +6 -2
  186. notionary/workspace/query/__init__.py +2 -1
  187. notionary/workspace/query/service.py +42 -13
  188. notionary/workspace/service.py +74 -46
  189. {notionary-0.3.1.dist-info → notionary-0.4.1.dist-info}/METADATA +1 -1
  190. notionary-0.4.1.dist-info/RECORD +236 -0
  191. notionary/file_upload/models.py +0 -69
  192. notionary/page/blocks/client.py +0 -1
  193. notionary/page/content/syntax/__init__.py +0 -4
  194. notionary/page/content/syntax/models.py +0 -66
  195. notionary/page/content/syntax/registry.py +0 -393
  196. notionary/page/page_context.py +0 -50
  197. notionary/shared/models/cover.py +0 -20
  198. notionary-0.3.1.dist-info/RECORD +0 -211
  199. /notionary/page/content/syntax/{grammar.py → definition/grammar.py} +0 -0
  200. {notionary-0.3.1.dist-info → notionary-0.4.1.dist-info}/WHEEL +0 -0
  201. {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(self, text: str, builder_func: Callable[[MarkdownBuilder], MarkdownBuilder] | None = None) -> Self:
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(self, text: str, builder_func: Callable[[MarkdownBuilder], MarkdownBuilder] | None = None) -> Self:
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(self, text: str, builder_func: Callable[[MarkdownBuilder], MarkdownBuilder] | None = None) -> Self:
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(self, text: str, builder_func: Callable[[MarkdownBuilder], MarkdownBuilder] | None = None) -> Self:
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, text: str, builder_func: Callable[[MarkdownBuilder], MarkdownBuilder] | None = None
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(NumberedListMarkdownNode(texts=[text], children=child_nodes))
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, text: str, builder_func: Callable[[MarkdownBuilder], MarkdownBuilder] | None = None
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(BulletedListMarkdownNode(texts=[text], children=child_nodes))
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(TodoMarkdownNode(text=text, checked=checked, children=children))
124
+ self.children.append(
125
+ TodoMarkdownNode(text=text, checked=checked, children=children)
126
+ )
101
127
  return self
102
128
 
103
- def checked_todo(self, text: str, builder_func: Callable[[MarkdownBuilder], MarkdownBuilder] | None = None) -> Self:
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, text: str, builder_func: Callable[[MarkdownBuilder], MarkdownBuilder] | None = None
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(CalloutMarkdownNode(text=text, emoji=emoji, children=children))
161
+ self.children.append(
162
+ CalloutMarkdownNode(text=text, emoji=emoji, children=children)
163
+ )
130
164
  return self
131
165
 
132
- def toggle(self, title: str, builder_func: Callable[[MarkdownBuilder], MarkdownBuilder]) -> Self:
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(self, url: str, title: str | None = None, caption: str | None = None) -> Self:
158
- self.children.append(BookmarkMarkdownNode(url=url, title=title, caption=caption))
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(self, code: str, language: CodingLanguage | None = None, caption: str | None = None) -> Self:
166
- self.children.append(CodeMarkdownNode(code=code, language=language, caption=caption))
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(CodeMarkdownNode(code=diagram, language=CodingLanguage.MERMAID.value, caption=caption))
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(child.to_markdown() for child in self.children if child is not None)
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, text: str, level: int, builder_func: Callable[[MarkdownBuilder], MarkdownBuilder] | None
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(HeadingMarkdownNode(text=text, level=level, children=children))
261
+ self.children.append(
262
+ HeadingMarkdownNode(text=text, level=level, children=children)
263
+ )
206
264
  return self
207
265
 
208
- def _build_children(self, builder_func: Callable[[MarkdownBuilder], MarkdownBuilder] | None) -> list[MarkdownNode]:
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(ColumnMarkdownNode(children=children, width_ratio=width_ratio))
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 CaptionMarkdownNodeMixin
5
- from notionary.page.content.syntax import SyntaxRegistry
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: SyntaxRegistry | None = None,
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 = f"{audio_syntax.start_delimiter}{self.url}{audio_syntax.end_delimiter}"
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 SyntaxRegistry
3
+ from notionary.page.content.syntax.definition import SyntaxDefinitionRegistry
4
4
 
5
5
 
6
6
  class MarkdownNode(ABC):
7
- def __init__(self, syntax_registry: SyntaxRegistry | None = None) -> None:
8
- self._syntax_registry = syntax_registry or SyntaxRegistry()
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 CaptionMarkdownNodeMixin
5
- from notionary.page.content.syntax import SyntaxRegistry
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: SyntaxRegistry | None = None,
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 SyntaxRegistry
4
+ from notionary.page.content.syntax.definition import SyntaxDefinitionRegistry
5
5
 
6
6
 
7
7
  class BreadcrumbMarkdownNode(MarkdownNode):
8
- def __init__(self, syntax_registry: SyntaxRegistry | None = None) -> None:
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 SyntaxRegistry
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: SyntaxRegistry | None = None,
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 = [self._render_list_item(index, text) for index, text in enumerate(self.texts)]
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 SyntaxRegistry
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: SyntaxRegistry | None = None,
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 CaptionMarkdownNodeMixin
6
- from notionary.page.content.syntax import SyntaxRegistry
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: SyntaxRegistry | None = None,
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 SyntaxRegistry
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: SyntaxRegistry | None = None,
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: SyntaxRegistry | None = None,
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 SyntaxRegistry
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: SyntaxRegistry | None = None) -> None:
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(syntax_registry: SyntaxRegistry | None) -> MarkdownGrammar:
64
- return syntax_registry._markdown_grammar if syntax_registry else MarkdownGrammar()
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 SyntaxRegistry
4
+ from notionary.page.content.syntax.definition import SyntaxDefinitionRegistry
5
5
 
6
6
 
7
7
  class DividerMarkdownNode(MarkdownNode):
8
- def __init__(self, syntax_registry: SyntaxRegistry | None = None) -> None:
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 CaptionMarkdownNodeMixin
5
- from notionary.page.content.syntax import SyntaxRegistry
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: SyntaxRegistry | None = None,
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 = f"{embed_syntax.start_delimiter}{self.url}{embed_syntax.end_delimiter}"
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 SyntaxRegistry
4
+ from notionary.page.content.syntax.definition import SyntaxDefinitionRegistry
5
5
 
6
6
 
7
7
  class EquationMarkdownNode(MarkdownNode):
8
- def __init__(self, expression: str, syntax_registry: SyntaxRegistry | None = None) -> None:
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 CaptionMarkdownNodeMixin
5
- from notionary.page.content.syntax import SyntaxRegistry
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: SyntaxRegistry | None = None,
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 = f"{file_syntax.start_delimiter}{self.url}{file_syntax.end_delimiter}"
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 SyntaxRegistry
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: SyntaxRegistry | None = None,
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 CaptionMarkdownNodeMixin
5
- from notionary.page.content.syntax import SyntaxRegistry
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: SyntaxRegistry | None = None,
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 = f"{image_syntax.start_delimiter}{self.url}{image_syntax.end_delimiter}"
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 SyntaxRegistry
1
+ from notionary.page.content.syntax.definition import SyntaxDefinitionRegistry
2
2
 
3
3
 
4
4
  class CaptionMarkdownNodeMixin:
5
- _syntax_registry: SyntaxRegistry
5
+ _syntax_registry: SyntaxDefinitionRegistry
6
6
 
7
- def _append_caption_to_markdown(self, base_markdown: str, caption: str | None) -> str:
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 SyntaxRegistry
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: SyntaxRegistry | None = None,
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 = [self._render_list_item(index, text) for index, text in enumerate(self.texts)]
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 SyntaxRegistry
4
+ from notionary.page.content.syntax.definition import SyntaxDefinitionRegistry
5
5
 
6
6
 
7
7
  class ParagraphMarkdownNode(MarkdownNode):
8
- def __init__(self, text: str, syntax_registry: SyntaxRegistry | None = None):
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 CaptionMarkdownNodeMixin
5
- from notionary.page.content.syntax import SyntaxRegistry
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: SyntaxRegistry | None = None,
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 = f"{pdf_syntax.start_delimiter}{self.url}{pdf_syntax.end_delimiter}"
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)