diff --git a/ghost/admin/app/components/koenig-lexical-editor-input.js b/ghost/admin/app/components/koenig-lexical-editor-input.js index 1ff346d592..0532d336ad 100644 --- a/ghost/admin/app/components/koenig-lexical-editor-input.js +++ b/ghost/admin/app/components/koenig-lexical-editor-input.js @@ -1,6 +1,7 @@ import * as Sentry from '@sentry/ember'; import Component from '@glimmer/component'; import React, {Suspense} from 'react'; +import cleanBasicHtml from '@tryghost/kg-clean-basic-html'; import {action} from '@ember/object'; import {inject} from 'ghost-admin/decorators/inject'; import {inject as service} from '@ember/service'; @@ -117,7 +118,16 @@ export default class KoenigLexicalEditorInput extends Component { // don't rethrow, Lexical will attempt to gracefully recover } - ReactComponent = (props) => { + ReactComponent = (props = {}) => { + // remove `p` wrapper + const cleanHtml = (html) => { + const cleanedHtml = cleanBasicHtml(html || '', {firstChildInnerContent: true}); + props.onChangeHtml?.(cleanedHtml); + }; + + // wrap in a paragraph, so it gets parsed correctly + const initialHtml = props.html ? `
${props.html}
` : null; + return (