Skip to content

refactor: simplify auto header insertion logic #2578

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 2, 2025
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
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
  • Loading branch information
sy-records committed Jul 30, 2025
commit b3159b14b8d8dce0ddd93e1e8c0753f13112b3d7
14 changes: 9 additions & 5 deletions src/core/render/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -342,11 +342,15 @@ export function Render(Base) {

if (autoHeader && activeEl) {
const main = dom.getNode('#main');
const firstNode = main.children[0];
if (firstNode && firstNode.tagName !== 'H1') {
const h1 = this.compiler.header(activeEl.innerText, 1);
const wrapper = dom.create('div', h1);
dom.before(main, wrapper.children[0]);
const hasH1 = main.querySelector('h1');

if (!hasH1) {
const h1HTML = this.compiler.header(activeEl.innerText, 1);
const h1Node = dom.create('div', h1HTML).firstElementChild;

if (h1Node) {
dom.before(main, h1Node);
}
}
}
}
Expand Down
Loading
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