diff --git a/packages/kg-default-nodes/lib/nodes/header/parsers/header-parser.js b/packages/kg-default-nodes/lib/nodes/header/parsers/header-parser.js index 78e83c9050..be444f09bf 100644 --- a/packages/kg-default-nodes/lib/nodes/header/parsers/header-parser.js +++ b/packages/kg-default-nodes/lib/nodes/header/parsers/header-parser.js @@ -51,7 +51,29 @@ export function parseHeaderNode(HeaderNode) { const buttonElement = div.querySelector('.kg-header-card-button'); const alignment = div.classList.contains('kg-align-center') ? 'center' : ''; const backgroundImageSrc = div.querySelector('.kg-header-card-image')?.getAttribute('src'); - const layout = backgroundImageSrc ? 'split' : ''; + + // Determine layout based on classes and DOM structure, not just image presence + let layout = ''; + if (backgroundImageSrc) { + // Check for explicit layout class first + const hasSplitClass = div.classList.contains('kg-layout-split'); + const hasContentWideClass = div.classList.contains('kg-content-wide'); + + // Check DOM structure: picture as direct child = full, picture inside content = split + const picture = div.querySelector('picture'); + const content = div.querySelector('.kg-header-card-content'); + const isPictureDirectChild = picture && picture.parentElement === div; + const isPictureInContent = picture && content && content.contains(picture); + + if (hasSplitClass || isPictureInContent) { + layout = 'split'; + } else if (hasContentWideClass || isPictureDirectChild) { + layout = ''; // full/wide layout (empty string) + } else { + // Fallback to old behavior if structure is ambiguous + layout = 'split'; + } + } const backgroundColor = div.classList.contains('kg-style-accent') ? 'accent' : div.getAttribute('data-background-color'); const buttonColor = buttonElement?.getAttribute('data-button-color') || ''; const textColor = headerElement?.getAttribute('data-text-color') || ''; diff --git a/packages/kg-default-nodes/test/nodes/header.test.js b/packages/kg-default-nodes/test/nodes/header.test.js index b37f191114..05323ec700 100644 --- a/packages/kg-default-nodes/test/nodes/header.test.js +++ b/packages/kg-default-nodes/test/nodes/header.test.js @@ -359,8 +359,8 @@ describe('HeaderNode', function () { it('parses a header card V2', editorTest(function () { const htmlstring = `
-
+

Header

Subheader

@@ -400,6 +400,63 @@ describe('HeaderNode', function () { const node = nodes[0]; node.version.should.equal(1); })); + + it('parses full/wide layout when kg-content-wide class is present', editorTest(function () { + const htmlstring = ` +
+ +
+
+

Title

+

Subtitle

+
+
+
`; + const document = createDocument(htmlstring); + const nodes = $generateNodesFromDOM(editor, document); + nodes.length.should.equal(1); + const node = nodes[0]; + node.layout.should.equal(''); // full/wide layout is empty string + node.backgroundImageSrc.should.equal('https://example.com/image.jpg'); + })); + + it('parses split layout when kg-layout-split class is present', editorTest(function () { + const htmlstring = ` +
+
+ +
+

Title

+

Subtitle

+
+
+
`; + const document = createDocument(htmlstring); + const nodes = $generateNodesFromDOM(editor, document); + nodes.length.should.equal(1); + const node = nodes[0]; + node.layout.should.equal('split'); + node.backgroundImageSrc.should.equal('https://example.com/image.jpg'); + })); + + it('parses full layout when picture is direct child of card', editorTest(function () { + const htmlstring = ` +
+ +
+
+

Title

+

Subtitle

+
+
+
`; + const document = createDocument(htmlstring); + const nodes = $generateNodesFromDOM(editor, document); + nodes.length.should.equal(1); + const node = nodes[0]; + node.layout.should.equal(''); // full layout is empty string + node.backgroundImageSrc.should.equal('https://example.com/image.jpg'); + })); }); describe('getType', function () {