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
Add TOC depth option #282
Merged
Merged
Add TOC depth option #282
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<h1 id="readme-for-blah">README for Blah</h1> | ||
|
||
<h2 id="introduction">Introduction</h2> | ||
|
||
<h2 id="the-meat">The Meat</h2> | ||
|
||
<h3 id="beef">Beef</h3> | ||
|
||
<h5 id="steak">Steak</h5> | ||
|
||
<h5 id="burgers">Burgers</h5> | ||
|
||
<h3 id="chicken">Chicken</h3> | ||
|
||
<h3 id="pork">Pork</h3> | ||
|
||
<h4 id="mmmmmmmm-bacon">Mmmmmmmm, bacon</h4> | ||
|
||
<h1 id="at-the-top-level-again">At the <em>top</em> level again!?</h1> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"extras": { | ||
"toc": {"depth": 3} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
toc extra |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# README for Blah | ||
|
||
## Introduction | ||
|
||
## The Meat | ||
|
||
### Beef | ||
|
||
##### Steak | ||
|
||
##### Burgers | ||
|
||
### Chicken | ||
|
||
### Pork | ||
|
||
#### Mmmmmmmm, bacon | ||
|
||
# At the *top* level again!? | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<ul> | ||
<li><a href="#readme-for-blah">README for Blah</a> | ||
<ul> | ||
<li><a href="#introduction">Introduction</a></li> | ||
<li><a href="#the-meat">The Meat</a> | ||
<ul> | ||
<li><a href="#beef">Beef</a></li> | ||
<li><a href="#chicken">Chicken</a></li> | ||
<li><a href="#pork">Pork</a></li> | ||
</ul></li> | ||
</ul></li> | ||
<li><a href="#at-the-top-level-again">At the <em>top</em> level again!?</a></li> | ||
</ul> |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
What exactly is
if self.extras["toc"] is None
checking for? Some testing on my own and it doesn't seem to catch ifextras = {'toc': {}}
or ifextras=['toc']
. This might need to be more robust. Maybe something like (pseudo):What's the default depth in master branch right now? Is 6 an appropriate default?
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.
I believe both cases you mention are actually are covered:
extras=['toc']
-> at this point in the code,self.extras
has been coerced to a dictionary (there's even an assert on line 243)extras={'toc': {}}
-> this will be caught by the call to.get()
, which returns 6 if the dictionary doesn't contain the keydepth
.The check is for the case where the user supplied a list, in which case it will be converted by code above (lines 238/241) to a dict with all values set to
None
, or simply if the user passedextras={'toc': None}
. I can still add exception-catching if you'd like, but I don't think it's necessary unless the user is passing strange values in theextras
dict.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.
Ah, good look, you're right. I made an assumption that it was still a possible list at that point. No change necessary there.
In regards to the default depth, where did 6 come from? In master is the depth just 1?
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.
Oh I've taken the convention that depth = maximum header level that will be included in the TOC. I believe 6 is the maximum header level, so setting the depth to 6 (or more) will just include all headers in the TOC.