-
Notifications
You must be signed in to change notification settings - Fork 129
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
A slightly better TOC #298
Conversation
- add intermediate h1 sections - skip subtitles (h1+h2) closes #281
src/render.ts
Outdated
@@ -124,7 +124,7 @@ interface Header { | |||
} | |||
|
|||
function findHeaders(parseResult: ParseResult): Header[] { | |||
return Array.from(parseHTML(parseResult.html).document.querySelectorAll("h2")) | |||
return Array.from(parseHTML(parseResult.html).document.querySelectorAll("h1:not(:first-of-type), h2:not(h1 + h2)")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we could create a shared file with export const selectors = ["h1:not(:first-of-type)", "h2:not(h1 + h2)"]
that we can use on both the client and server?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alternatively it could get baked-in to the generated page code (so that the user can override it), and then passed to enableToc(selectors)
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now passing it via a data-selector property in the toc. Next step would be to make it configurable but this is out of scope for this PR (and I'm not sure we should hurry on configurability).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice.
closes #281