diff --git a/ghost/admin/app/components/koenig-lexical-editor-input.js b/ghost/admin/app/components/koenig-lexical-editor-input.js index 0532d336ad..47681b69fa 100644 --- a/ghost/admin/app/components/koenig-lexical-editor-input.js +++ b/ghost/admin/app/components/koenig-lexical-editor-input.js @@ -125,8 +125,20 @@ export default class KoenigLexicalEditorInput extends Component { props.onChangeHtml?.(cleanedHtml); }; - // wrap in a paragraph, so it gets parsed correctly - const initialHtml = props.html ? `

${props.html}

` : null; + const hasParagraphWrapper = (html) => { + const domParser = new DOMParser(); + const doc = domParser.parseFromString(html, 'text/html'); + + return doc.body.firstElementChild.tagName === 'P'; + }; + + const getInitialHtml = () => { + if (!props.html) { + return null; + } + // wrap in a paragraph, so it gets parsed correctly + return hasParagraphWrapper(props.html) ? props.html : `

${props.html}

`; + }; return (
@@ -146,7 +158,7 @@ export default class KoenigLexicalEditorInput extends Component { placeholderText={props.placeholderText} placeholderClassName="koenig-lexical-editor-input-placeholder" > - +