Closed guoyunhe closed 7 months ago
Do you mean something like the following? This would mean the plugin would search for level 1, 2, and 4 headers, but not 3, 5, or 6. It will use the first level 1 header if one is present. If not, it will use the first level 2 header found. If that’s not present either, it will use the first level 4 header found.
await compile(content, {
rehypePlugins: [
[rehypeMdxTitle, { levels: [1, 2, 4] }]
]
})
By default it will only look for a level 1 header.
Or perhaps the configuration should only define one level, which implies all levels up to the one specified. So a level of 4 would mean to look for header levels 1-4.
@remcohaszing it should not be a config option, but a fallback logic.
h1
or #
).This makes it more likely to return a title.
I read your proposal as:
This code yields Level 1
:
### Level 3
## Level 2
# Level 1
This code yields Level 3
:
### Level 3
## Level 2
IMO this is weird. Why not yield Level 2
in the latter example?
What if you find the first heading of the highest rank?
@guoyunhe do you have an actual example of what your users do?
I read your proposal as:
This code yields
Level 1
:### Level 3 ## Level 2 # Level 1
This code yields
Level 3
:### Level 3 ## Level 2
IMO this is weird. Why not yield
Level 2
in the latter example?
Yield Level 2
is also fine for me, better than return nothing.
In my case, I made an internal doc tool to generate websites from markdown. When creating the site navigation menu, here are cases when no title are parsed. Some people prefer writting level 2 or level 3 headings, simply because they think level 1 headings is too big in font size... You cannot really control it.
Released in version 3.1.0 :tada:
In my cases, users may write some document without first level heading:
Can it be supported to parse the first heading? (even if not top level?)