notionary 0.2.21__py3-none-any.whl → 0.2.22__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 (96) hide show
  1. notionary/blocks/_bootstrap.py +9 -1
  2. notionary/blocks/audio/audio_element.py +53 -28
  3. notionary/blocks/audio/audio_markdown_node.py +10 -4
  4. notionary/blocks/base_block_element.py +15 -3
  5. notionary/blocks/bookmark/bookmark_element.py +39 -36
  6. notionary/blocks/bookmark/bookmark_markdown_node.py +16 -17
  7. notionary/blocks/breadcrumbs/breadcrumb_element.py +2 -2
  8. notionary/blocks/bulleted_list/bulleted_list_element.py +21 -4
  9. notionary/blocks/callout/callout_element.py +20 -4
  10. notionary/blocks/child_database/__init__.py +11 -4
  11. notionary/blocks/child_database/child_database_element.py +61 -0
  12. notionary/blocks/child_database/child_database_models.py +7 -14
  13. notionary/blocks/child_page/child_page_element.py +94 -0
  14. notionary/blocks/client.py +0 -1
  15. notionary/blocks/code/code_element.py +51 -2
  16. notionary/blocks/code/code_markdown_node.py +52 -1
  17. notionary/blocks/column/column_element.py +9 -3
  18. notionary/blocks/column/column_list_element.py +18 -3
  19. notionary/blocks/divider/divider_element.py +3 -11
  20. notionary/blocks/embed/embed_element.py +27 -6
  21. notionary/blocks/equation/equation_element.py +94 -41
  22. notionary/blocks/equation/equation_element_markdown_node.py +8 -9
  23. notionary/blocks/file/file_element.py +56 -37
  24. notionary/blocks/file/file_element_markdown_node.py +9 -7
  25. notionary/blocks/guards.py +22 -0
  26. notionary/blocks/heading/heading_element.py +23 -4
  27. notionary/blocks/image_block/image_element.py +43 -38
  28. notionary/blocks/image_block/image_markdown_node.py +10 -5
  29. notionary/blocks/mixins/captions/__init__.py +4 -0
  30. notionary/blocks/mixins/captions/caption_markdown_node_mixin.py +31 -0
  31. notionary/blocks/mixins/captions/caption_mixin.py +92 -0
  32. notionary/blocks/models.py +3 -1
  33. notionary/blocks/numbered_list/numbered_list_element.py +21 -4
  34. notionary/blocks/paragraph/paragraph_element.py +21 -5
  35. notionary/blocks/pdf/pdf_element.py +47 -41
  36. notionary/blocks/pdf/pdf_markdown_node.py +9 -7
  37. notionary/blocks/quote/quote_element.py +26 -9
  38. notionary/blocks/quote/quote_markdown_node.py +2 -2
  39. notionary/blocks/registry/block_registry.py +1 -46
  40. notionary/blocks/registry/block_registry_builder.py +8 -0
  41. notionary/blocks/rich_text/name_to_id_resolver.py +205 -0
  42. notionary/blocks/rich_text/rich_text_models.py +62 -29
  43. notionary/blocks/rich_text/text_inline_formatter.py +432 -101
  44. notionary/blocks/syntax_prompt_builder.py +137 -0
  45. notionary/blocks/table/table_element.py +110 -9
  46. notionary/blocks/table_of_contents/table_of_contents_element.py +19 -2
  47. notionary/blocks/todo/todo_element.py +21 -4
  48. notionary/blocks/toggle/toggle_element.py +19 -3
  49. notionary/blocks/toggle/toggle_markdown_node.py +1 -1
  50. notionary/blocks/toggleable_heading/toggleable_heading_element.py +19 -4
  51. notionary/blocks/types.py +69 -0
  52. notionary/blocks/video/video_element.py +44 -39
  53. notionary/blocks/video/video_markdown_node.py +10 -5
  54. notionary/database/client.py +23 -0
  55. notionary/file_upload/models.py +2 -2
  56. notionary/markdown/markdown_builder.py +34 -27
  57. notionary/page/client.py +26 -6
  58. notionary/page/notion_page.py +37 -6
  59. notionary/page/page_content_deleting_service.py +117 -0
  60. notionary/page/page_content_writer.py +89 -113
  61. notionary/page/page_context.py +65 -0
  62. notionary/page/reader/handler/__init__.py +2 -0
  63. notionary/page/reader/handler/base_block_renderer.py +4 -4
  64. notionary/page/reader/handler/block_rendering_context.py +5 -0
  65. notionary/page/reader/handler/line_renderer.py +16 -3
  66. notionary/page/reader/handler/numbered_list_renderer.py +85 -0
  67. notionary/page/reader/page_content_retriever.py +17 -5
  68. notionary/page/writer/handler/__init__.py +2 -0
  69. notionary/page/writer/handler/code_handler.py +12 -40
  70. notionary/page/writer/handler/column_handler.py +12 -12
  71. notionary/page/writer/handler/column_list_handler.py +13 -13
  72. notionary/page/writer/handler/equation_handler.py +74 -0
  73. notionary/page/writer/handler/line_handler.py +4 -4
  74. notionary/page/writer/handler/regular_line_handler.py +31 -37
  75. notionary/page/writer/handler/table_handler.py +8 -72
  76. notionary/page/writer/handler/toggle_handler.py +14 -12
  77. notionary/page/writer/handler/toggleable_heading_handler.py +22 -16
  78. notionary/page/writer/markdown_to_notion_converter.py +28 -9
  79. notionary/page/writer/markdown_to_notion_converter_context.py +30 -0
  80. notionary/page/writer/markdown_to_notion_formatting_post_processor.py +73 -0
  81. notionary/page/writer/markdown_to_notion_post_processor.py +0 -0
  82. notionary/page/writer/markdown_to_notion_text_length_post_processor.py +0 -0
  83. notionary/page/writer/notion_text_length_processor.py +150 -0
  84. notionary/telemetry/service.py +0 -1
  85. notionary/user/notion_user_manager.py +22 -95
  86. notionary/util/concurrency_limiter.py +0 -0
  87. notionary/workspace.py +4 -4
  88. notionary-0.2.22.dist-info/METADATA +237 -0
  89. {notionary-0.2.21.dist-info → notionary-0.2.22.dist-info}/RECORD +92 -77
  90. notionary/page/markdown_whitespace_processor.py +0 -80
  91. notionary/page/notion_text_length_utils.py +0 -119
  92. notionary/user/notion_user_provider.py +0 -1
  93. notionary-0.2.21.dist-info/METADATA +0 -229
  94. /notionary/page/reader/handler/{context.py → equation_renderer.py} +0 -0
  95. {notionary-0.2.21.dist-info → notionary-0.2.22.dist-info}/LICENSE +0 -0
  96. {notionary-0.2.21.dist-info → notionary-0.2.22.dist-info}/WHEEL +0 -0
@@ -1,9 +1,35 @@
1
1
  from __future__ import annotations
2
2
 
3
+ from enum import Enum
3
4
  from typing import Optional
4
5
 
5
6
  from pydantic import BaseModel
6
- from typing_extensions import Literal
7
+
8
+
9
+ class RichTextType(str, Enum):
10
+ """Types of rich text objects."""
11
+
12
+ TEXT = "text"
13
+ MENTION = "mention"
14
+ EQUATION = "equation"
15
+
16
+
17
+ class MentionType(str, Enum):
18
+ """Types of mention objects."""
19
+
20
+ USER = "user"
21
+ PAGE = "page"
22
+ DATABASE = "database"
23
+ DATE = "date"
24
+ LINK_PREVIEW = "link_preview"
25
+ TEMPLATE_MENTION = "template_mention"
26
+
27
+
28
+ class TemplateMentionType(str, Enum):
29
+ """Types of template mentions."""
30
+
31
+ USER = "template_mention_user"
32
+ DATE = "template_mention_date"
7
33
 
8
34
 
9
35
  class TextAnnotations(BaseModel):
@@ -53,13 +79,11 @@ class MentionDate(BaseModel):
53
79
 
54
80
  class MentionTemplateMention(BaseModel):
55
81
  # Notion hat zwei Template-Mention-Typen
56
- type: Literal["template_mention_user", "template_mention_date"]
82
+ type: TemplateMentionType
57
83
 
58
84
 
59
85
  class MentionObject(BaseModel):
60
- type: Literal[
61
- "user", "page", "database", "date", "link_preview", "template_mention"
62
- ]
86
+ type: MentionType
63
87
  user: Optional[MentionUserRef] = None
64
88
  page: Optional[MentionPageRef] = None
65
89
  database: Optional[MentionDatabaseRef] = None
@@ -69,7 +93,7 @@ class MentionObject(BaseModel):
69
93
 
70
94
 
71
95
  class RichTextObject(BaseModel):
72
- type: Literal["text", "mention", "equation"] = "text"
96
+ type: RichTextType = RichTextType.TEXT
73
97
 
74
98
  text: Optional[TextContent] = None
75
99
  annotations: Optional[TextAnnotations] = None
@@ -83,26 +107,30 @@ class RichTextObject(BaseModel):
83
107
  @classmethod
84
108
  def from_plain_text(cls, content: str, **ann) -> RichTextObject:
85
109
  return cls(
86
- type="text",
110
+ type=RichTextType.TEXT,
87
111
  text=TextContent(content=content),
88
112
  annotations=TextAnnotations(**ann) if ann else TextAnnotations(),
89
113
  plain_text=content,
90
114
  )
91
115
 
92
116
  @classmethod
93
- def for_code_block(cls, content: str) -> RichTextObject:
94
- # keine annotations setzen → Notion Code-Highlight bleibt an
117
+ def for_caption(cls, content: str) -> RichTextObject:
95
118
  return cls(
96
- type="text",
119
+ type=RichTextType.TEXT,
97
120
  text=TextContent(content=content),
98
121
  annotations=None,
99
122
  plain_text=content,
100
123
  )
101
124
 
125
+ @classmethod
126
+ def for_code_block(cls, content: str) -> RichTextObject:
127
+ # keine annotations setzen → Notion Code-Highlight bleibt an
128
+ return cls.for_caption(content)
129
+
102
130
  @classmethod
103
131
  def for_link(cls, content: str, url: str, **ann) -> RichTextObject:
104
132
  return cls(
105
- type="text",
133
+ type=RichTextType.TEXT,
106
134
  text=TextContent(content=content, link=LinkObject(url=url)),
107
135
  annotations=TextAnnotations(**ann) if ann else TextAnnotations(),
108
136
  plain_text=content,
@@ -111,25 +139,29 @@ class RichTextObject(BaseModel):
111
139
  @classmethod
112
140
  def mention_user(cls, user_id: str) -> RichTextObject:
113
141
  return cls(
114
- type="mention",
115
- mention=MentionObject(type="user", user=MentionUserRef(id=user_id)),
142
+ type=RichTextType.MENTION,
143
+ mention=MentionObject(
144
+ type=MentionType.USER, user=MentionUserRef(id=user_id)
145
+ ),
116
146
  annotations=TextAnnotations(),
117
147
  )
118
148
 
119
149
  @classmethod
120
150
  def mention_page(cls, page_id: str) -> RichTextObject:
121
151
  return cls(
122
- type="mention",
123
- mention=MentionObject(type="page", page=MentionPageRef(id=page_id)),
152
+ type=RichTextType.MENTION,
153
+ mention=MentionObject(
154
+ type=MentionType.PAGE, page=MentionPageRef(id=page_id)
155
+ ),
124
156
  annotations=TextAnnotations(),
125
157
  )
126
158
 
127
159
  @classmethod
128
160
  def mention_database(cls, database_id: str) -> RichTextObject:
129
161
  return cls(
130
- type="mention",
162
+ type=RichTextType.MENTION,
131
163
  mention=MentionObject(
132
- type="database", database=MentionDatabaseRef(id=database_id)
164
+ type=MentionType.DATABASE, database=MentionDatabaseRef(id=database_id)
133
165
  ),
134
166
  annotations=TextAnnotations(),
135
167
  )
@@ -137,9 +169,9 @@ class RichTextObject(BaseModel):
137
169
  @classmethod
138
170
  def mention_link_preview(cls, url: str) -> RichTextObject:
139
171
  return cls(
140
- type="mention",
172
+ type=RichTextType.MENTION,
141
173
  mention=MentionObject(
142
- type="link_preview", link_preview=MentionLinkPreview(url=url)
174
+ type=MentionType.LINK_PREVIEW, link_preview=MentionLinkPreview(url=url)
143
175
  ),
144
176
  annotations=TextAnnotations(),
145
177
  )
@@ -149,9 +181,10 @@ class RichTextObject(BaseModel):
149
181
  cls, start: str, end: str | None = None, time_zone: str | None = None
150
182
  ) -> RichTextObject:
151
183
  return cls(
152
- type="mention",
184
+ type=RichTextType.MENTION,
153
185
  mention=MentionObject(
154
- type="date", date=MentionDate(start=start, end=end, time_zone=time_zone)
186
+ type=MentionType.DATE,
187
+ date=MentionDate(start=start, end=end, time_zone=time_zone),
155
188
  ),
156
189
  annotations=TextAnnotations(),
157
190
  )
@@ -159,10 +192,10 @@ class RichTextObject(BaseModel):
159
192
  @classmethod
160
193
  def mention_template_user(cls) -> RichTextObject:
161
194
  return cls(
162
- type="mention",
195
+ type=RichTextType.MENTION,
163
196
  mention=MentionObject(
164
- type="template_mention",
165
- template_mention=MentionTemplateMention(type="template_mention_user"),
197
+ type=MentionType.TEMPLATE_MENTION,
198
+ template_mention=MentionTemplateMention(type=TemplateMentionType.USER),
166
199
  ),
167
200
  annotations=TextAnnotations(),
168
201
  )
@@ -170,10 +203,10 @@ class RichTextObject(BaseModel):
170
203
  @classmethod
171
204
  def mention_template_date(cls) -> RichTextObject:
172
205
  return cls(
173
- type="mention",
206
+ type=RichTextType.MENTION,
174
207
  mention=MentionObject(
175
- type="template_mention",
176
- template_mention=MentionTemplateMention(type="template_mention_date"),
208
+ type=MentionType.TEMPLATE_MENTION,
209
+ template_mention=MentionTemplateMention(type=TemplateMentionType.DATE),
177
210
  ),
178
211
  annotations=TextAnnotations(),
179
212
  )
@@ -181,8 +214,8 @@ class RichTextObject(BaseModel):
181
214
  @classmethod
182
215
  def equation_inline(cls, expression: str) -> RichTextObject:
183
216
  return cls(
184
- type="equation",
217
+ type=RichTextType.EQUATION,
185
218
  equation=EquationObject(expression=expression),
186
219
  annotations=TextAnnotations(),
187
- plain_text=expression, # Notion liefert plain_text serverseitig; für Roundtrip hilfreich
220
+ plain_text=expression,
188
221
  )