This package contains the CAST (Content Abstract Syntax Tree) schema and tools for working with it. CAST is a schema that adheres to the Unified collective
The schema is defined in schema.ts, and is rendered into JSON Schema format in schema.json.
To work with CAST documents, we implement the following utitlities:
-
InvalidCastError
: An error that is thrown when a CAST document is invalid. -
validateCast
: Validates any input against the schema. ThrowsInvalidCastError
if the input is invalid.
As Delta uses Slate as a wysiwyg editor, we need to convert Slate documents to CAST
documents, in order to process them in Delta.
As Delta uses Slate as a wysiwyg editor, we need to convert CAST documents to Slate documents, in order to display
them in the editor.
To display CAST documents in a web browser, we need to convert them to HAST. From a HAST tree, we can then use hast-util-to-html to create an HTML string or hast-util-to-dom to create a DOM tree.
Example usage of cast-utils-to-hast to render a CAST tree to a HTML string:
const castTree = {
type: 'root',
children: [
{
type: 'paragraph',
children: [
{ type: 'text', value: 'Hello, world!' }
]
}
]
}
const hast = toHast(castTree);
const htmlString = toHtml(hast);