koenig/kg-html-to-lexical/README.md
Converts HTML strings into Lexical editor state, used by imports and the Admin API's ?source=html option.
npm install @tryghost/kg-html-to-lexical
const {htmlToLexical} = require('@tryghost/kg-html-to-lexical');
const state = htmlToLexical('<p>Hello <strong>world</strong></p>');
// {root: {children: [...], type: 'root', ...}}
Returns a serializable editor state object, not a string — JSON.stringify it
before storing. Runs headlessly via JSDOM, so it works server-side.
This package is part of the Ghost monorepo
and resolves through the pnpm workspace — there is no linking or per-package
install step. Run pnpm setup in the monorepo root, then work in
koenig/kg-html-to-lexical.
See the Koenig README for the shared build, test and release workflow.
pnpm test:unit runs the unit testspnpm test runs the unit and type tests, including coverage thresholdspnpm lint runs the lint checksCopyright (c) 2013-2026 Ghost Foundation - Released under the MIT license.