From 75c649be39d577f3e5233403edb2c2712db6200e Mon Sep 17 00:00:00 2001 From: Cyril Date: Wed, 25 Mar 2026 10:00:10 +0100 Subject: [PATCH] =?UTF-8?q?=E2=99=BF=EF=B8=8F(frontend)=20fix=20empty=20he?= =?UTF-8?q?ading=20before=20section=20titles=20in=20HTML=20export?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Avoid nested headings: full HTML already wraps content in h1–h6; unwrap --- CHANGELOG.md | 2 ++ .../src/features/docs/doc-export/utils_html.ts | 16 ++++++++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) 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); });