Skip to content

Conversation

@sy-records
Copy link
Member

  • Use querySelector instead of getElementsByTagName for clarity
  • Avoid redundant DOM wrapping by directly accessing firstElementChild
  • Add null check to prevent potential DOM insertion errors

Close #810

@vercel
Copy link

vercel bot commented Jul 24, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
docsify-preview ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 30, 2025 3:01am

Copy link
Member

@Koooooo-7 Koooooo-7 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the main.children[0] seems more reasonable/semantic to determine if there contains a Header (although other plugin may broken it, maybe we need distinguish docsify owned doms).
If we change to search h1 in whole content, it seems we breaks the behavior since we don't allow user to use autoHeader for those content which contains h1 for different purpose.

// # AutoHeader add from _sidebar.md
this is a summary for the whole content.

# There is a new section for the next content below
Should I never use the H1 in this content anymore? 

Maybe we need keep this behavior? or update the docs for the autoHeader, but it will constrict the users' content tho.

- Use querySelector instead of getElementsByTagName for clarity
- Avoid redundant DOM wrapping by directly accessing firstElementChild
- Add null check to prevent potential DOM insertion errors
@sy-records
Copy link
Member Author

Searching for a does not solve the problem.
image

@Koooooo-7
Copy link
Member

Searching for a does not solve the problem.
image

I understand that, since it's strict for the first item, which may exchanged by plugins. It's fine to change the behavior in v5 that we only support autoHeader in the content without any H1 heading presently.

@sy-records sy-records merged commit b468bcd into docsifyjs:develop Aug 2, 2025
8 checks passed
@sy-records sy-records deleted the fix/autoHeader branch August 2, 2025 07:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

autoHeader not compatible with plugins that write before md content

2 participants