Repository navigation
fix: give a heading with no slug-able characters no anchor at all - #176
Open
rahul05ranjan wants to merge 2 commits into
Open
rahul05ranjan wants to merge 2 commits into
rahul05ranjan wants to merge 2 commits into
Conversation
A generated empty slug produced an invalid empty id="" attribute (and a permalink pointing at "#"), while an empty *explicit* ID is already treated as absent. Extend the same doctrine to generated slugs: no id, no permalink, and no "" reservation in the slug set. Fixes executablebooks#175 Co-authored-by: rahul05ranjan <11793455+rahul05ranjan@users.noreply.github.com>
for more information, see https://pre-commit.ci
This branch has not been deployed
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fixes #175
What's wrong
anchors_plugingenerates an emptyidattribute for any selected-level heading whose title has no slug-able characters (## ???,## ***,## $$$…), which is invalid HTML, and a second such heading gets the oddid="-1":With
permalink=Trueit also emits a permalink pointing athref="#"— the top of the page, not the heading.The plugin already documents this doctrine for the explicit-ID path ("an empty explicit ID counts as no ID";
test_explicit_heading_id_edge_casesasserts'id=""' not in rendered), but the generated-slug path never checked for an emptyslugify()result.Fix
Treat a generated empty slug exactly like an empty explicit ID: the heading gets no
idattribute and no permalink.""is also no longer added to the slug set (which is what producedid="-1"for a second such heading).Tests
New
test_empty_generated_slug_gets_no_id(3 cases: no slug-able chars, twice, followed by a real heading):fde61f4) with'id=""' in rendered/id="-1",id="real"(noreal-1),pytest tests/test_anchors.py: 28 passed (25 + 3 new),data_regressionfixture env errors that occur on a clean checkout (markdown-it-py 3.0.0 here, the repo's declared floor).