-
Notifications
You must be signed in to change notification settings - Fork 482
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
Allow at-contents to take Depth as a UnitRange #1125
Conversation
At least in the HTML output, Documenter still seems to write them out on the same level. E.g. with I reckon we'd want them to end up on the top level. Not 100% sure at the moment where the issue is coming from though. |
This keeps the list starting at the top-level bullets, even if e.g. `Depth = 2:5` starts only at the second-level headers
I wasn't sure if moving them up a level was desirable or not. But now that you point it out, yeah I think you're right! After a bit of digging, it looks like the change needs to be made in the renderers, e.g. here: Documenter.jl/src/Writers/MarkdownWriter.jl Line 130 in 13ec67e
I've just pushed up a commit that subtracts the starting depth from the level. Let me know if that's a clean way to do it, or if there's a different factoring of the code you'd prefer? :) Thanks! (Also, i'm not really sure how to write unit tests for this... is that something we should do? Thanks) |
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.
Sorry for forgetting to review this. The solution looks fine, except for a minor bug.
Regarding unit tests: yeah, it's hard to test these things. Using it in the test/example
builds is sufficient I'd say.
@@ -1238,7 +1238,7 @@ function domify(ctx, navnode, contents::Documents.ContentsNode) | |||
header = anchor.object | |||
url = string(path, '#', anchor.id, '-', anchor.nth) | |||
node = a[:href=>url](mdconvert(header.text; droplinks=true)) | |||
level = Utilities.header_level(header) | |||
level = Utilities.header_level(header) - contents_header_level_offset(contents) |
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.
This currently errors with
ERROR: LoadError: UndefVarError: contents_header_level_offset not defined
Just needs a using
for it, as the definition is in the Documenter.Documents
module.
What happens when you have
and you have e.g.
? |
Yeah, that's true... Maybe what would be better would be to have an option to drop all preceding headers? That is, to only start the table-of-contents from the current position? So this: # My Page
## Table of Contents
```@contents
Pages = ["index.md"]
OnlyIndexBelow = true
```
# Section 1
## Subheader
...
# Section 2
... Would become:
What do you think about that? The option name needs a bit of work, |
In general, you should not have That is not to say that we couldn't have a fancier option as well for the use case that you have in mind. But you would still need to figure out how to deal with the Just a few thoughts on the second option:
```@contents
PageContents = true
``` or ```@contents
mode = :PageContents
``` It would then automatically figure out which page it is on, so no need to
But all this is quite a bit more work to implement I think. So happy to just go with generalizing the |
closing this stale PR. |
Allow
```@contents
to takeDepth
as a UnitRange:This is useful to allow skipping the title of a page (header level 1) when generating a Table of Contents, since the title is often redundant.
Fixes #245