arkynChangelogGuides

toRichTextValue

The toRichTextValue function converts an HTML string into a rich text value array.

Import

ts

import { toRichTextValue } from "@arkyn/shared";

Parameters

The function accepts the following parameter:

html (required)

HTML string to be parsed into rich text nodes.
Type: string

Usage example

The function returns a RichTextValue array generated by parsing the HTML and deserializing each node.
Type: RichTextValue

typescript

import { toRichTextValue } from "@arkyn/shared";
const html = "<p><strong>Hello world</strong></p>";
const richText = toRichTextValue(html);
console.log(richText);
// Output: [{ type: 'paragraph', children: [{ text: 'Hello world', bold: true }] }]

typescript

import { toRichTextValue } from "@arkyn/shared";
const plainText = "Simple text";
const richText = toRichTextValue(plainText);
console.log(richText);
// Output: [{ text: 'Simple text' }]

Notes

  • The function accepts both HTML markup and plain text input.
  • When the parser returns an array, each node is converted individually.
  • When the parser returns a string, the function wraps it in a single text node.
  • Use this function when importing stored HTML back into a rich text editor model.
On this page