0.1.3 • Published 5 months ago

@platecms/delta-cast-util-to-plaintext v0.1.3

Weekly downloads
-
License
UNLICENSED
Repository
bitbucket
Last release
5 months ago

cast-util-to-plaintext

This library is part of the CAST abstract syntax tree utilities. It provides a utility to convert a CAST abstract syntax tree directly to plaintext.

Usage

Using the utility cast to plaintext looks as follows:

/**
 * @import {Root} from 'cast'
 */

import {toPlaintext} from '@platecms/delta-cast-util-to-plaintext'

/** @type {Root} */
const tree = [
    {
        type: 'paragraph',
        children: [
            { text: 'Hello' }
        ]
    },
    {
        type: 'heading',
        level: 1,
        children: [
            {
                type: 'bold',
                children: [
                    { 
                        type: 'text', 
                        text: 'world' 
                    }
                ]
            }
        ]
    }
]

console.info(toPlaintext(tree))

yields:

'Hello world'

Building

Run nx build cast-util-to-plaintext to build the library.

Running unit tests

Run nx test cast-util-to-plaintext to execute the unit tests via Vitest.