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/fair-snails-occur.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"oxa-types": minor
---

Add Emphasis node type
28 changes: 28 additions & 0 deletions docs/schema/emphasis.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
(oxa:emphasis)=

## Emphasis


Emphasized content (typically italicized).


__type__: _string_, ("Emphasis")

: The type discriminator for Emphasis 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 emphasize.
: See @oxa:inline
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:strong
Union of: @oxa:text, @oxa:emphasis, @oxa:strong
22 changes: 21 additions & 1 deletion packages/oxa-types-py/src/oxa_types/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,24 @@ class Document(BaseModel):
children: list["Block"] = Field(description="The block content of the document.")


class Emphasis(BaseModel):
"""Emphasized content (typically italicized)."""

model_config = ConfigDict(strict=True)

type: Literal["Emphasis"] = "Emphasis"
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 emphasize.")


class Heading(BaseModel):
"""A heading with a level and inline content."""

Expand Down Expand Up @@ -114,11 +132,12 @@ class Text(BaseModel):


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


# Rebuild models to resolve forward references
Document.model_rebuild()
Emphasis.model_rebuild()
Heading.model_rebuild()
Paragraph.model_rebuild()
Strong.model_rebuild()
Expand All @@ -128,6 +147,7 @@ class Text(BaseModel):
__all__ = [
"Block",
"Document",
"Emphasis",
"Heading",
"Inline",
"Paragraph",
Expand Down
19 changes: 19 additions & 0 deletions packages/oxa-types-rs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,24 @@ pub struct Document {
pub children: Vec<Block>,
}

/// Emphasized content (typically italicized).
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct Emphasis {
/// The type discriminator for Emphasis nodes.
pub r#type: MustBe!("Emphasis"),
/// A unique identifier for the node.
#[serde(skip_serializing_if = "Option::is_none")]
pub id: Option<String>,
/// A list of class names for styling or semantics.
#[serde(skip_serializing_if = "Option::is_none")]
pub classes: Option<Vec<String>>,
/// Arbitrary key-value data attached to the node.
#[serde(skip_serializing_if = "Option::is_none")]
pub data: Option<serde_json::Value>,
/// The inline content to emphasize.
pub children: Vec<Inline>,
}

/// A heading with a level and inline content.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct Heading {
Expand Down Expand Up @@ -120,5 +138,6 @@ pub enum Block {
#[serde(untagged)]
pub enum Inline {
Text(Text),
Emphasis(Emphasis),
Strong(Strong),
}
28 changes: 27 additions & 1 deletion packages/oxa-types-ts/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,32 @@ export interface Document {
children: Block[];
}

/**
* Emphasized content (typically italicized).
*/
export interface Emphasis {
/**
* The type discriminator for Emphasis nodes.
*/
type: "Emphasis";
/**
* A unique identifier for the node.
*/
id?: string;
/**
* A list of class names for styling or semantics.
*/
classes?: string[];
/**
* Arbitrary key-value data attached to the node.
*/
data?: Record<string, unknown>;
/**
* The inline content to emphasize.
*/
children: Inline[];
}

/**
* A heading with a level and inline content.
*/
Expand Down Expand Up @@ -155,4 +181,4 @@ export type Block = Heading | Paragraph;
/**
* Union of all inline content types.
*/
export type Inline = Text | Strong;
export type Inline = Text | Emphasis | Strong;
29 changes: 29 additions & 0 deletions schema/Emphasis.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
$schema: "http://json-schema.org/draft-07/schema#"
$id: Emphasis
title: Emphasis
description: Emphasized content (typically italicized).
type: object
properties:
type:
description: The type discriminator for Emphasis nodes.
enum: [Emphasis]
id:
description: A unique identifier for the node.
type: string
classes:
description: A list of class names for styling or semantics.
type: array
items:
type: string
data:
description: Arbitrary key-value data attached to the node.
type: object
additionalProperties: true
children:
description: The inline content to emphasize.
type: array
items:
$ref: "./Inline.yaml"
required:
- type
- children
1 change: 1 addition & 0 deletions schema/Inline.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ title: Inline
description: Union of all inline content types.
anyOf:
- $ref: "./Text.yaml"
- $ref: "./Emphasis.yaml"
- $ref: "./Strong.yaml"
38 changes: 38 additions & 0 deletions schema/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,41 @@
},
"required": ["type", "children"]
},
"Emphasis": {
"title": "Emphasis",
"description": "Emphasized content (typically italicized).",
"type": "object",
"properties": {
"type": {
"description": "The type discriminator for Emphasis nodes.",
"enum": ["Emphasis"]
},
"id": {
"description": "A unique identifier for the node.",
"type": "string"
},
"classes": {
"description": "A list of class names for styling or semantics.",
"type": "array",
"items": {
"type": "string"
}
},
"data": {
"description": "Arbitrary key-value data attached to the node.",
"type": "object",
"additionalProperties": true
},
"children": {
"description": "The inline content to emphasize.",
"type": "array",
"items": {
"$ref": "#/definitions/Inline"
}
}
},
"required": ["type", "children"]
},
"Heading": {
"title": "Heading",
"description": "A heading with a level and inline content.",
Expand Down Expand Up @@ -112,6 +147,9 @@
{
"$ref": "#/definitions/Text"
},
{
"$ref": "#/definitions/Emphasis"
},
{
"$ref": "#/definitions/Strong"
}
Expand Down