diff --git a/CHANGELOG.md b/CHANGELOG.md index c0ddb080..bb7dfff5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,8 @@ and this project adheres to ### Changed - 💄(frontend) improve comments highlights #1961 +- ♿️(frontend) fix empty heading before section titles in HTML export + #2125 ## [v4.8.3] - 2026-03-23 diff --git a/src/frontend/apps/impress/src/features/docs/doc-export/utils_html.ts b/src/frontend/apps/impress/src/features/docs/doc-export/utils_html.ts index fc3c2bf6..f7137bff 100644 --- a/src/frontend/apps/impress/src/features/docs/doc-export/utils_html.ts +++ b/src/frontend/apps/impress/src/features/docs/doc-export/utils_html.ts @@ -145,8 +145,20 @@ export const improveHtmlAccessibility = ( headingBlocks.forEach((block) => { const rawLevel = Number(block.getAttribute('data-level')) || 1; const level = Math.min(Math.max(rawLevel, 1), 6); - const heading = parsedDocument.createElement(`h${level}`); - moveChildNodes(block, heading); + const tag = `h${level}`; + + const existingHeading = block.querySelector('h1, h2, h3, h4, h5, h6'); + const heading = parsedDocument.createElement(tag); + + if (existingHeading) { + if (existingHeading.className) { + heading.className = existingHeading.className; + } + moveChildNodes(existingHeading, heading); + } else { + moveChildNodes(block, heading); + } + block.replaceWith(heading); });