Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/short-areas-spend.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"oxa-types": patch
---

Add initial node types using RFC0003 (Code, InlineCode, Subscript, Superscript, ThematicBreak).
2 changes: 1 addition & 1 deletion docs/schema/block.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
Union of all block content types.


Union of: @oxa:heading, @oxa:paragraph
Union of: @oxa:code, @oxa:heading, @oxa:paragraph, @oxa:thematicbreak
31 changes: 31 additions & 0 deletions docs/schema/code.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
(oxa:code)=

## Code


A block of preformatted text, typically source code.


__type__: _string_, ("Code")

: The type discriminator for Code nodes.

__id__: __string__

: A unique identifier for the node.

__classes__: __array__ ("string")

: A list of class names for styling or semantics.

__data__: __object__

: Arbitrary key-value data attached to the node.

__language__: __string__

: The programming language of the code content.

__value__: __string__

: The code content.
2 changes: 1 addition & 1 deletion docs/schema/inline.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
Union of all inline content types.


Union of: @oxa:text, @oxa:emphasis, @oxa:strong
Union of: @oxa:text, @oxa:emphasis, @oxa:inlinecode, @oxa:strong, @oxa:subscript, @oxa:superscript
31 changes: 31 additions & 0 deletions docs/schema/inlinecode.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
(oxa:inlinecode)=

## InlineCode


Short fragments of code appearing within prose.


__type__: _string_, ("InlineCode")

: The type discriminator for InlineCode nodes.

__id__: __string__

: A unique identifier for the node.

__classes__: __array__ ("string")

: A list of class names for styling or semantics.

__data__: __object__

: Arbitrary key-value data attached to the node.

__language__: __string__

: The programming language of the code content.

__value__: __string__

: The code content.
28 changes: 28 additions & 0 deletions docs/schema/subscript.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
(oxa:subscript)=

## Subscript


Content rendered below the baseline (e.g. chemical formulae, variable indices).


__type__: _string_, ("Subscript")

: The type discriminator for Subscript nodes.

__id__: __string__

: A unique identifier for the node.

__classes__: __array__ ("string")

: A list of class names for styling or semantics.

__data__: __object__

: Arbitrary key-value data attached to the node.

__children__: __array__ ("Inline")

: The inline content to render as subscript.
: See @oxa:inline
28 changes: 28 additions & 0 deletions docs/schema/superscript.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
(oxa:superscript)=

## Superscript


Content rendered above the baseline (e.g. exponents, ordinal suffixes).


__type__: _string_, ("Superscript")

: The type discriminator for Superscript nodes.

__id__: __string__

: A unique identifier for the node.

__classes__: __array__ ("string")

: A list of class names for styling or semantics.

__data__: __object__

: Arbitrary key-value data attached to the node.

__children__: __array__ ("Inline")

: The inline content to render as superscript.
: See @oxa:inline
23 changes: 23 additions & 0 deletions docs/schema/thematicbreak.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
(oxa:thematicbreak)=

## ThematicBreak


A thematic or structural division between sections of content.


__type__: _string_, ("ThematicBreak")

: The type discriminator for ThematicBreak nodes.

__id__: __string__

: A unique identifier for the node.

__classes__: __array__ ("string")

: A list of class names for styling or semantics.

__data__: __object__

: Arbitrary key-value data attached to the node.
118 changes: 116 additions & 2 deletions packages/oxa-types-py/src/oxa_types/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,27 @@
from pydantic import BaseModel, ConfigDict, Field


class Code(BaseModel):
"""A block of preformatted text, typically source code."""

model_config = ConfigDict(strict=True)

type: Literal["Code"] = "Code"
id: str | None = Field(
default=None, description="A unique identifier for the node."
)
classes: list[str] | None = Field(
default=None, description="A list of class names for styling or semantics."
)
data: dict[str, Any] | None = Field(
default=None, description="Arbitrary key-value data attached to the node."
)
language: str | None = Field(
default=None, description="The programming language of the code content."
)
value: str = Field(description="The code content.")


class Document(BaseModel):
"""A document with metadata, title, and block content."""

Expand Down Expand Up @@ -73,6 +94,27 @@ class Heading(BaseModel):
children: list["Inline"] = Field(description="The inline content of the heading.")


class InlineCode(BaseModel):
"""Short fragments of code appearing within prose."""

model_config = ConfigDict(strict=True)

type: Literal["InlineCode"] = "InlineCode"
id: str | None = Field(
default=None, description="A unique identifier for the node."
)
classes: list[str] | None = Field(
default=None, description="A list of class names for styling or semantics."
)
data: dict[str, Any] | None = Field(
default=None, description="Arbitrary key-value data attached to the node."
)
language: str | None = Field(
default=None, description="The programming language of the code content."
)
value: str = Field(description="The code content.")


class Paragraph(BaseModel):
"""A paragraph of inline content."""

Expand Down Expand Up @@ -109,6 +151,46 @@ class Strong(BaseModel):
children: list["Inline"] = Field(description="The inline content to emphasize.")


class Subscript(BaseModel):
"""Content rendered below the baseline (e.g. chemical formulae, variable indices)."""

model_config = ConfigDict(strict=True)

type: Literal["Subscript"] = "Subscript"
id: str | None = Field(
default=None, description="A unique identifier for the node."
)
classes: list[str] | None = Field(
default=None, description="A list of class names for styling or semantics."
)
data: dict[str, Any] | None = Field(
default=None, description="Arbitrary key-value data attached to the node."
)
children: list["Inline"] = Field(
description="The inline content to render as subscript."
)


class Superscript(BaseModel):
"""Content rendered above the baseline (e.g. exponents, ordinal suffixes)."""

model_config = ConfigDict(strict=True)

type: Literal["Superscript"] = "Superscript"
id: str | None = Field(
default=None, description="A unique identifier for the node."
)
classes: list[str] | None = Field(
default=None, description="A list of class names for styling or semantics."
)
data: dict[str, Any] | None = Field(
default=None, description="Arbitrary key-value data attached to the node."
)
children: list["Inline"] = Field(
description="The inline content to render as superscript."
)


class Text(BaseModel):
"""A text node containing a string value."""

Expand All @@ -127,30 +209,62 @@ class Text(BaseModel):
value: str = Field(description="The text content.")


class ThematicBreak(BaseModel):
"""A thematic or structural division between sections of content."""

model_config = ConfigDict(strict=True)

type: Literal["ThematicBreak"] = "ThematicBreak"
id: str | None = Field(
default=None, description="A unique identifier for the node."
)
classes: list[str] | None = Field(
default=None, description="A list of class names for styling or semantics."
)
data: dict[str, Any] | None = Field(
default=None, description="Arbitrary key-value data attached to the node."
)


# Union of all block content types.
Block = Annotated[Union[Heading, Paragraph], Field(discriminator="type")]
Block = Annotated[
Union[Code, Heading, Paragraph, ThematicBreak], Field(discriminator="type")
]


# Union of all inline content types.
Inline = Annotated[Union[Text, Emphasis, Strong], Field(discriminator="type")]
Inline = Annotated[
Union[Text, Emphasis, InlineCode, Strong, Subscript, Superscript],
Field(discriminator="type"),
]


# Rebuild models to resolve forward references
Code.model_rebuild()
Document.model_rebuild()
Emphasis.model_rebuild()
Heading.model_rebuild()
InlineCode.model_rebuild()
Paragraph.model_rebuild()
Strong.model_rebuild()
Subscript.model_rebuild()
Superscript.model_rebuild()
Text.model_rebuild()
ThematicBreak.model_rebuild()


__all__ = [
"Block",
"Code",
"Document",
"Emphasis",
"Heading",
"Inline",
"InlineCode",
"Paragraph",
"Strong",
"Subscript",
"Superscript",
"Text",
"ThematicBreak",
]
Loading
Loading