Skip to content

Commit 24961db

Browse files
authored
🏷️ RFC0003 - Simple node types (#43)
1 parent 672311e commit 24961db

19 files changed

Lines changed: 836 additions & 6 deletions

File tree

.changeset/short-areas-spend.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"oxa-types": patch
3+
---
4+
5+
Add initial node types using RFC0003 (Code, InlineCode, Subscript, Superscript, ThematicBreak).

docs/schema/block.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@
66
Union of all block content types.
77

88

9-
Union of: @oxa:heading, @oxa:paragraph
9+
Union of: @oxa:code, @oxa:heading, @oxa:paragraph, @oxa:thematicbreak

docs/schema/code.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
(oxa:code)=
2+
3+
## Code
4+
5+
6+
A block of preformatted text, typically source code.
7+
8+
9+
__type__: _string_, ("Code")
10+
11+
: The type discriminator for Code nodes.
12+
13+
__id__: __string__
14+
15+
: A unique identifier for the node.
16+
17+
__classes__: __array__ ("string")
18+
19+
: A list of class names for styling or semantics.
20+
21+
__data__: __object__
22+
23+
: Arbitrary key-value data attached to the node.
24+
25+
__language__: __string__
26+
27+
: The programming language of the code content.
28+
29+
__value__: __string__
30+
31+
: The code content.

docs/schema/inline.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@
66
Union of all inline content types.
77

88

9-
Union of: @oxa:text, @oxa:emphasis, @oxa:strong
9+
Union of: @oxa:text, @oxa:emphasis, @oxa:inlinecode, @oxa:strong, @oxa:subscript, @oxa:superscript

docs/schema/inlinecode.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
(oxa:inlinecode)=
2+
3+
## InlineCode
4+
5+
6+
Short fragments of code appearing within prose.
7+
8+
9+
__type__: _string_, ("InlineCode")
10+
11+
: The type discriminator for InlineCode nodes.
12+
13+
__id__: __string__
14+
15+
: A unique identifier for the node.
16+
17+
__classes__: __array__ ("string")
18+
19+
: A list of class names for styling or semantics.
20+
21+
__data__: __object__
22+
23+
: Arbitrary key-value data attached to the node.
24+
25+
__language__: __string__
26+
27+
: The programming language of the code content.
28+
29+
__value__: __string__
30+
31+
: The code content.

docs/schema/subscript.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
(oxa:subscript)=
2+
3+
## Subscript
4+
5+
6+
Content rendered below the baseline (e.g. chemical formulae, variable indices).
7+
8+
9+
__type__: _string_, ("Subscript")
10+
11+
: The type discriminator for Subscript nodes.
12+
13+
__id__: __string__
14+
15+
: A unique identifier for the node.
16+
17+
__classes__: __array__ ("string")
18+
19+
: A list of class names for styling or semantics.
20+
21+
__data__: __object__
22+
23+
: Arbitrary key-value data attached to the node.
24+
25+
__children__: __array__ ("Inline")
26+
27+
: The inline content to render as subscript.
28+
: See @oxa:inline

docs/schema/superscript.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
(oxa:superscript)=
2+
3+
## Superscript
4+
5+
6+
Content rendered above the baseline (e.g. exponents, ordinal suffixes).
7+
8+
9+
__type__: _string_, ("Superscript")
10+
11+
: The type discriminator for Superscript nodes.
12+
13+
__id__: __string__
14+
15+
: A unique identifier for the node.
16+
17+
__classes__: __array__ ("string")
18+
19+
: A list of class names for styling or semantics.
20+
21+
__data__: __object__
22+
23+
: Arbitrary key-value data attached to the node.
24+
25+
__children__: __array__ ("Inline")
26+
27+
: The inline content to render as superscript.
28+
: See @oxa:inline

docs/schema/thematicbreak.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
(oxa:thematicbreak)=
2+
3+
## ThematicBreak
4+
5+
6+
A thematic or structural division between sections of content.
7+
8+
9+
__type__: _string_, ("ThematicBreak")
10+
11+
: The type discriminator for ThematicBreak nodes.
12+
13+
__id__: __string__
14+
15+
: A unique identifier for the node.
16+
17+
__classes__: __array__ ("string")
18+
19+
: A list of class names for styling or semantics.
20+
21+
__data__: __object__
22+
23+
: Arbitrary key-value data attached to the node.

packages/oxa-types-py/src/oxa_types/__init__.py

Lines changed: 116 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,27 @@
1212
from 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+
1536
class 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+
76118
class 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+
112194
class 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()
139244
Document.model_rebuild()
140245
Emphasis.model_rebuild()
141246
Heading.model_rebuild()
247+
InlineCode.model_rebuild()
142248
Paragraph.model_rebuild()
143249
Strong.model_rebuild()
250+
Subscript.model_rebuild()
251+
Superscript.model_rebuild()
144252
Text.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

Comments
 (0)