Renders a lexical editor state string to a HTML string.
This library differs from Lexical's own lexical-html package in a few ways:
- it's output target is not an editor but rendered web pages or emails which means the handling of nodes (especially custom DecoratorNodes) will differ to the node's built-in editor-focused rendering
- render output will vary based on supplied options and targets, e.g. when rendering for email the output may use
<table>
elements in place of modern HTML structure - it's primary usage environment is server-side
npm install @tryghost/kg-lexical-html-renderer --save
or
yarn add @tryghost/kg-lexical-html-renderer
Basic usage:
const LexicalHTMLRenderer = require('@tryghost/kg-lexical-html-renderer');
const renderer = new Renderer();
const lexicalState = '{...}';
const html = await renderer.render(lexicalState);
Options can be passed in as the second argument to .render()
.
const html = await renderer.render(lexicalState, {target: 'email'});
Option | Values |
---|---|
target |
'html' (default), 'email'
|
This is a mono repository, managed with lerna.
Follow the instructions for the top-level repo.
-
git clone
this repo &cd
into it as usual - Run
yarn
to install top-level dependencies.
-
yarn lint
run just eslint -
yarn test
run lint and tests
In order to run local changes, perform the following:
- Run
yarn link
withinkg-lexical-html-renderer
- Run
yarn link @tryghost/kg-lexical-html-renderer
withinghost/core
kg-default-nodes
must also be linked when linking this package as they are codependencies.
Copyright (c) 2013-2023 Ghost Foundation - Released under the MIT license.