0.13.4-next.12 • Published 1 month ago

@emailsenderlab/html v0.13.4-next.12

Weekly downloads
-
License
MIT
Repository
github
Last release
1 month ago

@lexical/html

HTML

This package exports utility functions for converting Lexical -> HTML and HTML -> Lexical. These same functions are also used in the lexical-clipboard package for copy and paste.

Full documentation can be found here.

Exporting

// In a headless mode, you need to initialize a headless browser implementation such as JSDom.
const dom = new JSDOM();
// @ts-expect-error
global.window = dom.window;
global.document = dom.window.document;
// You may also need to polyfill DocumentFragment or navigator in certain cases.

// When converting to HTML you can pass in a selection object to narrow it
// down to a certain part of the editor's contents.
const htmlString = $generateHtmlFromNodes(editor, selection | null);

Importing

First we need to parse the HTML string into a DOM instance.

// In the browser you can use the native DOMParser API to parse the HTML string.
const parser = new DOMParser();
const dom = parser.parseFromString(htmlString, textHtmlMimeType);

// In a headless environment you can use a package such as JSDom to parse the HTML string.
const dom = new JSDOM(htmlString);

And once you have the DOM instance.

const nodes = $generateNodesFromDOM(editor, dom);

// Once you have the lexical nodes you can initialize an editor instance with the parsed nodes.
const editor = createEditor({ ...config, nodes });

// Or insert them at a selection.
$insertNodes(nodes);
0.13.4-next.12

1 month ago

0.13.4-next.11

1 month ago

0.13.4-next.10

2 months ago

0.13.4-next.9

2 months ago

0.13.4-next.8

2 months ago

0.13.4-next.5

2 months ago

0.13.4-next.7

2 months ago

0.13.4-next.6

2 months ago

0.13.4-next.4

3 months ago

0.13.4-next.1

3 months ago

0.13.4-next.0

3 months ago

0.13.4-next.3

3 months ago

0.13.4-next.2

3 months ago

0.13.3

3 months ago

0.13.2-next.1

3 months ago

0.13.2-next.0

3 months ago

0.0.4-next.0

6 months ago

0.12.3-next.0

6 months ago