Skip to content

Instantly share code, notes, and snippets.

@gvergnaud
Created February 27, 2024 23:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gvergnaud/9e43fbee90a3a0b837d5ebd7a150d4fb to your computer and use it in GitHub Desktop.
Save gvergnaud/9e43fbee90a3a0b837d5ebd7a150d4fb to your computer and use it in GitHub Desktop.
prose-mirror-json-schema
type TextMarks =
| { type: "bold" }
| { type: "italic" }
| { type: "code" }
| { type: "strike" }
| { type: "textStyle"; attrs: Partial<CSSStyleDeclaration> }
| {
type: "link";
attrs: {
href: string;
target?: string | null;
rel?: string | null;
class?: string | null;
};
};
type TextNode = {
type: "text";
text: string;
marks?: TextMarks[];
};
type HardBreakNode = {
type: "hardBreak";
};
type CodeBlockAttributes = {
language?: string | null;
};
type CodeBlockNode = {
type: "codeBlock";
content: (BlockNode | InlineNode)[];
attrs: CodeBlockAttributes;
};
type ParagraphNode = {
type: "paragraph";
content?: InlineNode[];
};
type HeadingNode = {
type: "heading";
content: InlineNode[];
attrs: {
level: 1 | 2 | 3 | 4 | 5 | 6;
};
};
type BulletListItemAttributes = {
level: number;
};
type BulletListItemNode = {
type: "bulletListItem";
content: BlockNode[];
attrs: BulletListItemAttributes;
};
type BulletListNode = {
type: "bulletList";
content: BulletListItemNode[];
};
type TableAttrs = {
colspan: number;
rowspan: number;
colwidth: number | null;
};
type TableHeaderNode = {
type: "tableHeader";
content: BlockNode[];
attrs: TableAttrs;
};
type TableCellNode = {
type: "tableCell";
content: BlockNode[];
attrs: TableAttrs;
};
type TableRowNode = {
type: "tableRow";
content: (TableHeaderNode | TableCellNode)[];
};
type TableNode = {
type: "table";
content: TableRowNode[];
};
type BlockquoteNode = {
type: "blockquote";
content: BlockNode[];
};
type TaskList = {
type: "taskList";
content: TaskListItem[];
};
type TaskListItemAttributes = {
level: number;
checked: boolean;
};
type TaskListItem = {
type: "taskListItem";
content: BlockNode[];
attrs: TaskListItemAttributes;
};
export type GraphCellNodeAttributes = {
cellId: string;
};
export type GraphCellNode = {
type: "graph-cell";
attrs: GraphCellNodeAttributes;
};
export type RteCellAttributes = {
cellId: string;
};
export type RteCellNode = {
type: "rte-cell";
attrs: RteCellAttributes;
content: (BlockNode | InlineNode)[];
};
type InlineNode = TextNode | HardBreakNode;
type BlockNode =
| ParagraphNode
| CodeBlockNode
| HeadingNode
| BulletListNode
| BlockquoteNode
| TableNode
| TaskList
| TaskListItem;
type CellNode = GraphCellNode | RteCellNode;
export type ProseMirrorNode = InlineNode | BlockNode | CellNode;
export type ProseMirrorDocument = {
type: "doc";
content: ProseMirrorNode[];
};
npx typescript-json-schema ./0_types.ts ProseMirrorDocument > 2_json-schema.json
{
"$schema": "http://json-schema.org/draft-07/schema#",
"definitions": {
"BlockNode": {
"anyOf": [
{
"properties": {
"content": {
"items": {
"$ref": "#/definitions/InlineNode"
},
"type": "array"
},
"type": {
"enum": [
"paragraph"
],
"type": "string"
}
},
"type": "object"
},
{
"$ref": "#/definitions/CodeBlockNode"
},
{
"properties": {
"attrs": {
"properties": {
"level": {
"enum": [
1,
2,
3,
4,
5,
6
],
"type": "number"
}
},
"type": "object"
},
"content": {
"items": {
"$ref": "#/definitions/InlineNode"
},
"type": "array"
},
"type": {
"enum": [
"heading"
],
"type": "string"
}
},
"type": "object"
},
{
"$ref": "#/definitions/BulletListNode"
},
{
"properties": {
"content": {
"items": {
"$ref": "#/definitions/BlockNode"
},
"type": "array"
},
"type": {
"enum": [
"blockquote"
],
"type": "string"
}
},
"type": "object"
},
{
"properties": {
"content": {
"items": {
"properties": {
"content": {
"items": {
"anyOf": [
{
"properties": {
"attrs": {
"properties": {
"colspan": {
"type": "number"
},
"colwidth": {
"type": "number"
},
"rowspan": {
"type": "number"
}
},
"type": "object"
},
"content": {
"items": {
"$ref": "#/definitions/BlockNode"
},
"type": "array"
},
"type": {
"enum": [
"tableHeader"
],
"type": "string"
}
},
"type": "object"
},
{
"properties": {
"attrs": {
"properties": {
"colspan": {
"type": "number"
},
"colwidth": {
"type": "number"
},
"rowspan": {
"type": "number"
}
},
"type": "object"
},
"content": {
"items": {
"$ref": "#/definitions/BlockNode"
},
"type": "array"
},
"type": {
"enum": [
"tableCell"
],
"type": "string"
}
},
"type": "object"
}
]
},
"type": "array"
},
"type": {
"enum": [
"tableRow"
],
"type": "string"
}
},
"type": "object"
},
"type": "array"
},
"type": {
"enum": [
"table"
],
"type": "string"
}
},
"type": "object"
},
{
"properties": {
"content": {
"items": {
"properties": {
"attrs": {
"properties": {
"checked": {
"type": "boolean"
},
"level": {
"type": "number"
}
},
"type": "object"
},
"content": {
"items": {
"$ref": "#/definitions/BlockNode"
},
"type": "array"
},
"type": {
"enum": [
"taskListItem"
],
"type": "string"
}
},
"type": "object"
},
"type": "array"
},
"type": {
"enum": [
"taskList"
],
"type": "string"
}
},
"type": "object"
},
{
"properties": {
"attrs": {
"properties": {
"checked": {
"type": "boolean"
},
"level": {
"type": "number"
}
},
"type": "object"
},
"content": {
"items": {
"$ref": "#/definitions/BlockNode"
},
"type": "array"
},
"type": {
"enum": [
"taskListItem"
],
"type": "string"
}
},
"type": "object"
}
]
},
"BulletListItemNode": {
"properties": {
"attrs": {
"properties": {
"level": {
"type": "number"
}
},
"type": "object"
},
"content": {
"items": {
"$ref": "#/definitions/BlockNode"
},
"type": "array"
},
"type": {
"enum": [
"bulletListItem"
],
"type": "string"
}
},
"type": "object"
},
"BulletListNode": {
"properties": {
"content": {
"items": {
"$ref": "#/definitions/BulletListItemNode"
},
"type": "array"
},
"type": {
"enum": [
"bulletList"
],
"type": "string"
}
},
"type": "object"
},
"CodeBlockNode": {
"properties": {
"attrs": {
"properties": {
"language": {
"type": "string"
}
},
"type": "object"
},
"content": {
"items": {
"anyOf": [
{
"properties": {
"marks": {
"items": {
"$ref": "#/definitions/TextMarks"
},
"type": "array"
},
"text": {
"type": "string"
},
"type": {
"enum": [
"text"
],
"type": "string"
}
},
"type": "object"
},
{
"properties": {
"type": {
"enum": [
"hardBreak"
],
"type": "string"
}
},
"type": "object"
},
{
"properties": {
"content": {
"items": {
"$ref": "#/definitions/InlineNode"
},
"type": "array"
},
"type": {
"enum": [
"paragraph"
],
"type": "string"
}
},
"type": "object"
},
{
"$ref": "#/definitions/CodeBlockNode"
},
{
"properties": {
"attrs": {
"properties": {
"level": {
"enum": [
1,
2,
3,
4,
5,
6
],
"type": "number"
}
},
"type": "object"
},
"content": {
"items": {
"$ref": "#/definitions/InlineNode"
},
"type": "array"
},
"type": {
"enum": [
"heading"
],
"type": "string"
}
},
"type": "object"
},
{
"$ref": "#/definitions/BulletListNode"
},
{
"properties": {
"content": {
"items": {
"$ref": "#/definitions/BlockNode"
},
"type": "array"
},
"type": {
"enum": [
"blockquote"
],
"type": "string"
}
},
"type": "object"
},
{
"properties": {
"content": {
"items": {
"properties": {
"content": {
"items": {
"anyOf": [
{
"properties": {
"attrs": {
"properties": {
"colspan": {
"type": "number"
},
"colwidth": {
"type": "number"
},
"rowspan": {
"type": "number"
}
},
"type": "object"
},
"content": {
"items": {
"$ref": "#/definitions/BlockNode"
},
"type": "array"
},
"type": {
"enum": [
"tableHeader"
],
"type": "string"
}
},
"type": "object"
},
{
"properties": {
"attrs": {
"properties": {
"colspan": {
"type": "number"
},
"colwidth": {
"type": "number"
},
"rowspan": {
"type": "number"
}
},
"type": "object"
},
"content": {
"items": {
"$ref": "#/definitions/BlockNode"
},
"type": "array"
},
"type": {
"enum": [
"tableCell"
],
"type": "string"
}
},
"type": "object"
}
]
},
"type": "array"
},
"type": {
"enum": [
"tableRow"
],
"type": "string"
}
},
"type": "object"
},
"type": "array"
},
"type": {
"enum": [
"table"
],
"type": "string"
}
},
"type": "object"
},
{
"properties": {
"content": {
"items": {
"properties": {
"attrs": {
"properties": {
"checked": {
"type": "boolean"
},
"level": {
"type": "number"
}
},
"type": "object"
},
"content": {
"items": {
"$ref": "#/definitions/BlockNode"
},
"type": "array"
},
"type": {
"enum": [
"taskListItem"
],
"type": "string"
}
},
"type": "object"
},
"type": "array"
},
"type": {
"enum": [
"taskList"
],
"type": "string"
}
},
"type": "object"
},
{
"properties": {
"attrs": {
"properties": {
"checked": {
"type": "boolean"
},
"level": {
"type": "number"
}
},
"type": "object"
},
"content": {
"items": {
"$ref": "#/definitions/BlockNode"
},
"type": "array"
},
"type": {
"enum": [
"taskListItem"
],
"type": "string"
}
},
"type": "object"
}
]
},
"type": "array"
},
"type": {
"enum": [
"codeBlock"
],
"type": "string"
}
},
"type": "object"
},
"InlineNode": {
"anyOf": [
{
"properties": {
"marks": {
"items": {
"$ref": "#/definitions/TextMarks"
},
"type": "array"
},
"text": {
"type": "string"
},
"type": {
"enum": [
"text"
],
"type": "string"
}
},
"type": "object"
},
{
"properties": {
"type": {
"enum": [
"hardBreak"
],
"type": "string"
}
},
"type": "object"
}
]
},
"ProseMirrorNode": {
"anyOf": [
{
"properties": {
"marks": {
"items": {
"$ref": "#/definitions/TextMarks"
},
"type": "array"
},
"text": {
"type": "string"
},
"type": {
"enum": [
"text"
],
"type": "string"
}
},
"type": "object"
},
{
"properties": {
"type": {
"enum": [
"hardBreak"
],
"type": "string"
}
},
"type": "object"
},
{
"properties": {
"content": {
"items": {
"$ref": "#/definitions/InlineNode"
},
"type": "array"
},
"type": {
"enum": [
"paragraph"
],
"type": "string"
}
},
"type": "object"
},
{
"$ref": "#/definitions/CodeBlockNode"
},
{
"properties": {
"attrs": {
"properties": {
"level": {
"enum": [
1,
2,
3,
4,
5,
6
],
"type": "number"
}
},
"type": "object"
},
"content": {
"items": {
"$ref": "#/definitions/InlineNode"
},
"type": "array"
},
"type": {
"enum": [
"heading"
],
"type": "string"
}
},
"type": "object"
},
{
"$ref": "#/definitions/BulletListNode"
},
{
"properties": {
"content": {
"items": {
"$ref": "#/definitions/BlockNode"
},
"type": "array"
},
"type": {
"enum": [
"blockquote"
],
"type": "string"
}
},
"type": "object"
},
{
"properties": {
"content": {
"items": {
"properties": {
"content": {
"items": {
"anyOf": [
{
"properties": {
"attrs": {
"properties": {
"colspan": {
"type": "number"
},
"colwidth": {
"type": "number"
},
"rowspan": {
"type": "number"
}
},
"type": "object"
},
"content": {
"items": {
"$ref": "#/definitions/BlockNode"
},
"type": "array"
},
"type": {
"enum": [
"tableHeader"
],
"type": "string"
}
},
"type": "object"
},
{
"properties": {
"attrs": {
"properties": {
"colspan": {
"type": "number"
},
"colwidth": {
"type": "number"
},
"rowspan": {
"type": "number"
}
},
"type": "object"
},
"content": {
"items": {
"$ref": "#/definitions/BlockNode"
},
"type": "array"
},
"type": {
"enum": [
"tableCell"
],
"type": "string"
}
},
"type": "object"
}
]
},
"type": "array"
},
"type": {
"enum": [
"tableRow"
],
"type": "string"
}
},
"type": "object"
},
"type": "array"
},
"type": {
"enum": [
"table"
],
"type": "string"
}
},
"type": "object"
},
{
"properties": {
"content": {
"items": {
"properties": {
"attrs": {
"properties": {
"checked": {
"type": "boolean"
},
"level": {
"type": "number"
}
},
"type": "object"
},
"content": {
"items": {
"$ref": "#/definitions/BlockNode"
},
"type": "array"
},
"type": {
"enum": [
"taskListItem"
],
"type": "string"
}
},
"type": "object"
},
"type": "array"
},
"type": {
"enum": [
"taskList"
],
"type": "string"
}
},
"type": "object"
},
{
"properties": {
"attrs": {
"properties": {
"checked": {
"type": "boolean"
},
"level": {
"type": "number"
}
},
"type": "object"
},
"content": {
"items": {
"$ref": "#/definitions/BlockNode"
},
"type": "array"
},
"type": {
"enum": [
"taskListItem"
],
"type": "string"
}
},
"type": "object"
},
{
"properties": {
"attrs": {
"properties": {
"cellId": {
"type": "string"
}
},
"type": "object"
},
"type": {
"enum": [
"graph-cell"
],
"type": "string"
}
},
"type": "object"
},
{
"properties": {
"attrs": {
"properties": {
"cellId": {
"type": "string"
}
},
"type": "object"
},
"content": {
"items": {
"anyOf": [
{
"properties": {
"marks": {
"items": {
"$ref": "#/definitions/TextMarks"
},
"type": "array"
},
"text": {
"type": "string"
},
"type": {
"enum": [
"text"
],
"type": "string"
}
},
"type": "object"
},
{
"properties": {
"type": {
"enum": [
"hardBreak"
],
"type": "string"
}
},
"type": "object"
},
{
"properties": {
"content": {
"items": {
"$ref": "#/definitions/InlineNode"
},
"type": "array"
},
"type": {
"enum": [
"paragraph"
],
"type": "string"
}
},
"type": "object"
},
{
"$ref": "#/definitions/CodeBlockNode"
},
{
"properties": {
"attrs": {
"properties": {
"level": {
"enum": [
1,
2,
3,
4,
5,
6
],
"type": "number"
}
},
"type": "object"
},
"content": {
"items": {
"$ref": "#/definitions/InlineNode"
},
"type": "array"
},
"type": {
"enum": [
"heading"
],
"type": "string"
}
},
"type": "object"
},
{
"$ref": "#/definitions/BulletListNode"
},
{
"properties": {
"content": {
"items": {
"$ref": "#/definitions/BlockNode"
},
"type": "array"
},
"type": {
"enum": [
"blockquote"
],
"type": "string"
}
},
"type": "object"
},
{
"properties": {
"content": {
"items": {
"properties": {
"content": {
"items": {
"anyOf": [
{
"properties": {
"attrs": {
"properties": {
"colspan": {
"type": "number"
},
"colwidth": {
"type": "number"
},
"rowspan": {
"type": "number"
}
},
"type": "object"
},
"content": {
"items": {
"$ref": "#/definitions/BlockNode"
},
"type": "array"
},
"type": {
"enum": [
"tableHeader"
],
"type": "string"
}
},
"type": "object"
},
{
"properties": {
"attrs": {
"properties": {
"colspan": {
"type": "number"
},
"colwidth": {
"type": "number"
},
"rowspan": {
"type": "number"
}
},
"type": "object"
},
"content": {
"items": {
"$ref": "#/definitions/BlockNode"
},
"type": "array"
},
"type": {
"enum": [
"tableCell"
],
"type": "string"
}
},
"type": "object"
}
]
},
"type": "array"
},
"type": {
"enum": [
"tableRow"
],
"type": "string"
}
},
"type": "object"
},
"type": "array"
},
"type": {
"enum": [
"table"
],
"type": "string"
}
},
"type": "object"
},
{
"properties": {
"content": {
"items": {
"properties": {
"attrs": {
"properties": {
"checked": {
"type": "boolean"
},
"level": {
"type": "number"
}
},
"type": "object"
},
"content": {
"items": {
"$ref": "#/definitions/BlockNode"
},
"type": "array"
},
"type": {
"enum": [
"taskListItem"
],
"type": "string"
}
},
"type": "object"
},
"type": "array"
},
"type": {
"enum": [
"taskList"
],
"type": "string"
}
},
"type": "object"
},
{
"properties": {
"attrs": {
"properties": {
"checked": {
"type": "boolean"
},
"level": {
"type": "number"
}
},
"type": "object"
},
"content": {
"items": {
"$ref": "#/definitions/BlockNode"
},
"type": "array"
},
"type": {
"enum": [
"taskListItem"
],
"type": "string"
}
},
"type": "object"
}
]
},
"type": "array"
},
"type": {
"enum": [
"rte-cell"
],
"type": "string"
}
},
"type": "object"
}
]
},
"TextMarks": {
"anyOf": [
{
"properties": {
"type": {
"enum": [
"bold"
],
"type": "string"
}
},
"type": "object"
},
{
"properties": {
"type": {
"enum": [
"italic"
],
"type": "string"
}
},
"type": "object"
},
{
"properties": {
"type": {
"enum": [
"code"
],
"type": "string"
}
},
"type": "object"
},
{
"properties": {
"type": {
"enum": [
"strike"
],
"type": "string"
}
},
"type": "object"
},
{
"properties": {
"attrs": {
"additionalProperties": false,
"patternProperties": {
"^[0-9]+$": {
"type": "string"
}
},
"type": "object"
},
"type": {
"enum": [
"textStyle"
],
"type": "string"
}
},
"type": "object"
},
{
"properties": {
"attrs": {
"properties": {
"class": {
"type": "string"
},
"href": {
"type": "string"
},
"rel": {
"type": "string"
},
"target": {
"type": "string"
}
},
"type": "object"
},
"type": {
"enum": [
"link"
],
"type": "string"
}
},
"type": "object"
}
]
}
},
"properties": {
"content": {
"items": {
"$ref": "#/definitions/ProseMirrorNode"
},
"type": "array"
},
"type": {
"enum": [
"doc"
],
"type": "string"
}
},
"type": "object"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment