Skip to content

Commit b3159b1

Browse files
committed
refactor: simplify auto header insertion logic
- Use querySelector instead of getElementsByTagName for clarity - Avoid redundant DOM wrapping by directly accessing firstElementChild - Add null check to prevent potential DOM insertion errors
1 parent 77420df commit b3159b1

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

src/core/render/index.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -342,11 +342,15 @@ export function Render(Base) {
342342

343343
if (autoHeader && activeEl) {
344344
const main = dom.getNode('#main');
345-
const firstNode = main.children[0];
346-
if (firstNode && firstNode.tagName !== 'H1') {
347-
const h1 = this.compiler.header(activeEl.innerText, 1);
348-
const wrapper = dom.create('div', h1);
349-
dom.before(main, wrapper.children[0]);
345+
const hasH1 = main.querySelector('h1');
346+
347+
if (!hasH1) {
348+
const h1HTML = this.compiler.header(activeEl.innerText, 1);
349+
const h1Node = dom.create('div', h1HTML).firstElementChild;
350+
351+
if (h1Node) {
352+
dom.before(main, h1Node);
353+
}
350354
}
351355
}
352356
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy