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

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from

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

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

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
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