1212from pydantic import BaseModel , ConfigDict , Field
1313
1414
15+ class Code (BaseModel ):
16+ """A block of preformatted text, typically source code."""
17+
18+ model_config = ConfigDict (strict = True )
19+
20+ type : Literal ["Code" ] = "Code"
21+ id : str | None = Field (
22+ default = None , description = "A unique identifier for the node."
23+ )
24+ classes : list [str ] | None = Field (
25+ default = None , description = "A list of class names for styling or semantics."
26+ )
27+ data : dict [str , Any ] | None = Field (
28+ default = None , description = "Arbitrary key-value data attached to the node."
29+ )
30+ language : str | None = Field (
31+ default = None , description = "The programming language of the code content."
32+ )
33+ value : str = Field (description = "The code content." )
34+
35+
1536class Document (BaseModel ):
1637 """A document with metadata, title, and block content."""
1738
@@ -73,6 +94,27 @@ class Heading(BaseModel):
7394 children : list ["Inline" ] = Field (description = "The inline content of the heading." )
7495
7596
97+ class InlineCode (BaseModel ):
98+ """Short fragments of code appearing within prose."""
99+
100+ model_config = ConfigDict (strict = True )
101+
102+ type : Literal ["InlineCode" ] = "InlineCode"
103+ id : str | None = Field (
104+ default = None , description = "A unique identifier for the node."
105+ )
106+ classes : list [str ] | None = Field (
107+ default = None , description = "A list of class names for styling or semantics."
108+ )
109+ data : dict [str , Any ] | None = Field (
110+ default = None , description = "Arbitrary key-value data attached to the node."
111+ )
112+ language : str | None = Field (
113+ default = None , description = "The programming language of the code content."
114+ )
115+ value : str = Field (description = "The code content." )
116+
117+
76118class Paragraph (BaseModel ):
77119 """A paragraph of inline content."""
78120
@@ -109,6 +151,46 @@ class Strong(BaseModel):
109151 children : list ["Inline" ] = Field (description = "The inline content to emphasize." )
110152
111153
154+ class Subscript (BaseModel ):
155+ """Content rendered below the baseline (e.g. chemical formulae, variable indices)."""
156+
157+ model_config = ConfigDict (strict = True )
158+
159+ type : Literal ["Subscript" ] = "Subscript"
160+ id : str | None = Field (
161+ default = None , description = "A unique identifier for the node."
162+ )
163+ classes : list [str ] | None = Field (
164+ default = None , description = "A list of class names for styling or semantics."
165+ )
166+ data : dict [str , Any ] | None = Field (
167+ default = None , description = "Arbitrary key-value data attached to the node."
168+ )
169+ children : list ["Inline" ] = Field (
170+ description = "The inline content to render as subscript."
171+ )
172+
173+
174+ class Superscript (BaseModel ):
175+ """Content rendered above the baseline (e.g. exponents, ordinal suffixes)."""
176+
177+ model_config = ConfigDict (strict = True )
178+
179+ type : Literal ["Superscript" ] = "Superscript"
180+ id : str | None = Field (
181+ default = None , description = "A unique identifier for the node."
182+ )
183+ classes : list [str ] | None = Field (
184+ default = None , description = "A list of class names for styling or semantics."
185+ )
186+ data : dict [str , Any ] | None = Field (
187+ default = None , description = "Arbitrary key-value data attached to the node."
188+ )
189+ children : list ["Inline" ] = Field (
190+ description = "The inline content to render as superscript."
191+ )
192+
193+
112194class Text (BaseModel ):
113195 """A text node containing a string value."""
114196
@@ -127,30 +209,62 @@ class Text(BaseModel):
127209 value : str = Field (description = "The text content." )
128210
129211
212+ class ThematicBreak (BaseModel ):
213+ """A thematic or structural division between sections of content."""
214+
215+ model_config = ConfigDict (strict = True )
216+
217+ type : Literal ["ThematicBreak" ] = "ThematicBreak"
218+ id : str | None = Field (
219+ default = None , description = "A unique identifier for the node."
220+ )
221+ classes : list [str ] | None = Field (
222+ default = None , description = "A list of class names for styling or semantics."
223+ )
224+ data : dict [str , Any ] | None = Field (
225+ default = None , description = "Arbitrary key-value data attached to the node."
226+ )
227+
228+
130229# Union of all block content types.
131- Block = Annotated [Union [Heading , Paragraph ], Field (discriminator = "type" )]
230+ Block = Annotated [
231+ Union [Code , Heading , Paragraph , ThematicBreak ], Field (discriminator = "type" )
232+ ]
132233
133234
134235# Union of all inline content types.
135- Inline = Annotated [Union [Text , Emphasis , Strong ], Field (discriminator = "type" )]
236+ Inline = Annotated [
237+ Union [Text , Emphasis , InlineCode , Strong , Subscript , Superscript ],
238+ Field (discriminator = "type" ),
239+ ]
136240
137241
138242# Rebuild models to resolve forward references
243+ Code .model_rebuild ()
139244Document .model_rebuild ()
140245Emphasis .model_rebuild ()
141246Heading .model_rebuild ()
247+ InlineCode .model_rebuild ()
142248Paragraph .model_rebuild ()
143249Strong .model_rebuild ()
250+ Subscript .model_rebuild ()
251+ Superscript .model_rebuild ()
144252Text .model_rebuild ()
253+ ThematicBreak .model_rebuild ()
145254
146255
147256__all__ = [
148257 "Block" ,
258+ "Code" ,
149259 "Document" ,
150260 "Emphasis" ,
151261 "Heading" ,
152262 "Inline" ,
263+ "InlineCode" ,
153264 "Paragraph" ,
154265 "Strong" ,
266+ "Subscript" ,
267+ "Superscript" ,
155268 "Text" ,
269+ "ThematicBreak" ,
156270]
0 commit comments