@getplate/cast
v0.4.2
Published
Package containing the definition of CAST
Downloads
582
Readme
CAST (Content Abstract Syntax Tree)
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
Features
Schema
The schema is defined in schema.ts, and is rendered into JSON Schema format in schema.json.
Utils
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.
WIP fromSlate (Or some other editor)
As Delta uses Slate as a wysiwyg editor, we need to convert ~Slate~ documents to CAST documents, in order to process them in Delta.
WIP toSlate
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.
WIP toHast
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);