-
Notifications
You must be signed in to change notification settings - Fork 874
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
TOC extension: Add new boolean option permalink_prepend #1339
Conversation
Interesting feature request. Can't say that it would have ever occurred to me to add this. Although, I do have one question: is this necessary? Isn't there a way to accomplish this with CSS alone? I realize the CSS would be much more complex that a simple setting but I'm just making sure it makes sense to add this. I also hesitate regarding the name of the feature:
Yeah, our guide probably needs more details, but thank you for checking. The change_log is manually edited. As you are adding a new feature, this would then need to be part of a point release (3.5). As no release notes yet exist for that version, you would need to create the file at |
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.
The code looks good. If you add release notes and address the spelling issue, this could be ready to go assuming my other concerns are satisfied.
Fair question. I don't believe there's any clean way to accomplish this with CSS alone, no matter how complex. The side-effects of having the link tag at the end of the header content are too great to easily overcome. (For example, the trailing tag could be positioned to the left of the heading... but if it had been word-wrapped to a second line, it would remain aligned with the second line of the heading, instead of the first as intended.) As noted, I took inspiration from GitHub's own Markdown rendering, which places the permalink
I thought about that, too. I should've included some proposals for alternatives in the original PR note. Such as:
Gotcha, thanks. I'll take care of that and any other changes requested. |
I would be okay with either of those. I think I prefer them to I think maybe the issue I have with |
As a little more on this, the PR grew out of an issue with That works fine, for simple headings. But, here's what was happening when that (I've since discovered that styling the So, that aside, we've chosen to just remove the But we'd really prefer to move the permalinks slightly outside the heading, |
I quickly decided to avoid anything that didn't start with I've changed it to
The only remaining uncertainty I have is whether I should make |
Definitely ignore Also, thank you for the detailed explanation of the CSS issue. I'm not surprised by it, but wanted to at least ensure some thought was given to it before accepting this. This is clearly the better solution. |
@waylan OK, I believe I've addressed everything and this should be ready for re-review. Thanks for all of your guidance on this! |
Boolean flag which, when set to True, will cause permalink anchors to be inserted at the start of heading elements, rather than at the end (the default).
It looks like the spellchecker is failing on your code comments. We use Markdown syntax in our comments. You may need to add a few code spans to your comments. Also, please don't force push. Instead push new commits which address the requested changes. Then we can review those changes in isolation if need be. It hasn't been an issue in this PR, but that is best practice. We will squash the commits when we merge. |
Thanks for your work on this. It is ready to go. However, I am not sure when we will be making our next point release. Therefore I am not going to merge this immediately. I have added it to the 3.5 Milestone so we won't forget about it. |
This PR adds a new boolean to the TOC extension configuration. As described in the documentation:
permalink_prepend
:Set to
True
if the generated permalinks should be placed at thestart of the header, rather than at the end. Default is
False
.Basically, if the output of the conversion with
permalink
set toTrue
would be this:Then, also setting
permalink_prepend
toTrue
would transform that into this:This creates permalinks similar to the GitHub-Flavored Markdown converter's output, allowing them to be styled in the manner of
list-marker
symbols: They can be placed slightly outside of the heading's own content by means of a hanging indent created with negative margins.(See, for example, the section link anchors in this repo's own
README.md
, as rendered at https://github.com/Python-Markdown/markdown/.)Documentation updates are included for the new option, along with four new tests added to the TOC extension suite:
permalink
by itself, on a simple text headerpermalink
withpermalink_prepend
, on a simple text headerpermalink
alone, on a header with inline markup (`fenced code`)permalink
+permalink_prepend
, on a header with inline markup (`fenced code`)All four tests are passing and the extension's coverage remains at 100%.
The contributing guide also mentions adding a note to the release notes, but I checked out
docs/change_log/index.md
and got the impression that it was probably autogenerated, so I didn't touch it. If that's wrong, I'll happily add a line about this change.