0.14.5 • Published 23 days ago

@lexical/html v0.14.5

Weekly downloads
-
License
MIT
Repository
github
Last release
23 days ago

@lexical/html

See API Documentation

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.14.5

23 days ago

0.14.4

23 days ago

0.14.3

1 month ago

0.14.2

2 months ago

0.14.0

2 months ago

0.14.1

2 months ago

0.13.1

3 months ago

0.13.0

4 months ago

0.12.6

4 months ago

0.12.5

5 months ago

0.11.2

10 months ago

0.11.3

10 months ago

0.12.0

9 months ago

0.12.1

8 months ago

0.12.2

8 months ago

0.12.3

6 months ago

0.12.4

6 months ago

0.11.0

12 months ago

0.11.1

12 months ago

0.10.0

1 year ago

0.9.0

1 year ago

0.9.2

1 year ago

0.9.1

1 year ago

0.7.9

1 year ago

0.7.8

1 year ago

0.7.7

1 year ago

0.8.1

1 year ago

0.8.0

1 year ago

0.7.6

1 year ago

0.7.5

1 year ago

0.7.2

1 year ago

0.6.3

1 year ago

0.7.1

1 year ago

0.6.2

1 year ago

0.7.4

1 year ago

0.6.5

1 year ago

0.7.3

1 year ago

0.6.4

1 year ago

0.7.0

1 year ago

0.5.1-next.1

2 years ago

0.5.1-next.0

2 years ago

0.5.1-next.2

2 years ago

0.6.1-next.0

2 years ago

0.6.0

2 years ago

0.5.0

2 years ago

0.4.1

2 years ago

0.4.0

2 years ago

0.3.9

2 years ago

0.3.11

2 years ago

0.3.10

2 years ago

0.3.6

2 years ago

0.3.5

2 years ago

0.3.8

2 years ago

0.3.7

2 years ago

0.3.4

2 years ago

0.3.3

2 years ago

0.3.2

2 years ago

0.3.1

2 years ago

0.3.0

2 years ago