-
Notifications
You must be signed in to change notification settings - Fork 31
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
Enable nested headings using the isNested
option
#227
Conversation
☁️ Nx Cloud ReportCI is running/has finished running commands for commit 50c8fbe. As they complete they will appear below. Click to see the status, the terminal output, and the build insights. 📂 See all runs for this branch ✅ Successfully ran 1 targetSent with 💌 from NxCloud. |
I suggest changing the option name to
|
Something that comes to mind is that we lose type safety since there's no straightforward way for Perhaps it would make sense to publish separately as This module would share and reuse code with |
@ElMassimo the type @ouuan I don't know how |
Maybe we can simply provide a function that converts the flat format to the tree format? |
That was my first approach and it would be enough if the only requirement was to tree the flat list of headings but my usecase needed me to make modifications to the HTML node like adding data-attrs for the indices. |
I didn't notice this. It sounds like a very specific use case and not all users would want it. Maybe we can have something more generic, like customizing the HTML elements by a function based on some context. Actually, I also want this feature for my use case. |
What about adding these two features:
|
@ouuan what you are describing in point 2 could potentially be accomplished with some tweaking of the existing If you prefer, feel free to close this PR because this is very different from your idea of the ideal implementation. |
Description 📖
This pull request adds a new
isNested
boolean option the@islands/headings
module. It can be used as follows:Background 📜
See #226
The Fix 🔨
By changing the
rehypePlugin
to automatically insert the current heading as a child of the last known heading of higher level, the structure of theheadings
object becomes a tree instead of a list. Now theheadings
only contains the list of top-level headings, with all others available inside theirchildren
field recursively.Screenshots 📷
See the following Debug output from a dummy post in my îles blog project.