Repository navigation
Restore numbered section links #355
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
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
5963003
Restore numbered section links
HamptonMakes 02de00c
Keep numbered aliases stable across slides
HamptonMakes f5d83de
Merge remote-tracking branch 'origin/main' into hampton-fix-numbered-…
HamptonMakes 75e7d4a
Exercise numbered links with Markdown fixtures
HamptonMakes File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -373,6 +373,22 @@ def deck(content, **options) | |
| expect(doc.css("h1").map { |h| h["id"] }).to eq(%w[section-1 section-1-2]) | ||
| end | ||
|
|
||
| it "aligns numbered aliases across slides while keeping their heading ids", :heading_slug_ids do | ||
| doc = deck(<<~MARKDOWN) | ||
| See [the second section](#section-4-1-2). | ||
|
|
||
| ## 4.1. First review | ||
|
|
||
| --- | ||
|
|
||
| ## 4.1. Later review | ||
| MARKDOWN | ||
|
|
||
| expect(doc.at_css('h2[id="41-first-review"] > #section-4-1[data-heading-alias]')).to be_present | ||
| expect(doc.at_css('h2[id="41-later-review"] > #section-4-1-2[data-heading-alias]')).to be_present | ||
| expect(doc.at_css('a.reference-anchor--section[href="#section-4-1-2"]')).to be_present | ||
| end | ||
|
|
||
| it "keeps slide heading ids stable when a footnote definition holds a heading" do | ||
| # The definition's heading renders only in the References back matter, | ||
| # so it must not shift the ids of headings the slides actually show. | ||
|
|
@@ -484,6 +500,23 @@ def deck(content, **options) | |
| expect(doc.at_css("#foo-bar").parent.text.squish).to eq("Foo Bar") | ||
| end | ||
|
|
||
| it "drops a numbered alias from the wrong heading when alignment is skipped", :heading_slug_ids do | ||
| # The fallback still has to protect links when the heading sequences cannot be aligned. | ||
| allow(helper).to receive(:align_heading_ids) | ||
| doc = deck(<<~MARKDOWN) | ||
| ## 1. Alpha | ||
|
|
||
| --- | ||
|
|
||
| ## 1. Beta | ||
|
|
||
| ## 1. Gamma | ||
| MARKDOWN | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this feels weird... why do we have HTML as MARKDOWN? |
||
|
|
||
| expect(doc.at_css("#section-1").parent["id"]).to eq("1-alpha") | ||
| expect(doc.at_css("#section-1-2")).to be_nil | ||
| end | ||
|
|
||
| it "does not swap ids between same-text headings whose link destinations differ" do | ||
| # data-footnote-ref on an author link must not hide its href from the | ||
| # alignment gate — genuine refs keep identical #fn-… hrefs in both | ||
|
|
||
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| RSpec.shared_context "Commonmarker heading slug IDs" do | ||
| before do | ||
| # Commonmarker 2.9 moved the slug ID from the self-link to the heading. | ||
| # Exercise that output with real Markdown on either parser version. | ||
| allow(Commonmarker).to receive(:to_html).and_wrap_original do |render, *args, **options| | ||
| html = render.call(*args, **options) | ||
| doc = Nokogiri::HTML.fragment(html) | ||
| anchors = doc.css("a.anchor[id]").select do |anchor| | ||
| anchor.parent.name.match?(/\Ah[1-6]\z/) && !anchor.parent.key?("id") | ||
| end | ||
| next html if anchors.empty? | ||
|
|
||
| anchors.each do |anchor| | ||
| anchor.parent["id"] = anchor.remove_attribute("id").value | ||
| end | ||
| doc.to_html | ||
| end | ||
| end | ||
| end | ||
|
|
||
| RSpec.configure do |config| | ||
| config.include_context "Commonmarker heading slug IDs", :heading_slug_ids | ||
| end |
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
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
Oops, something went wrong.
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.
No test covers the new step that maps a numbered alias in the URL to its heading in the outline. For example, opening
#section-4-1on a heading whose ID is41-findingsmust expand the collapsed outline section that holds that heading. The new browser specs inspec/system/references_spec.rbcheck only that the heading is visible below the sticky header. They do not look at the outline. If this mapping breaks, the alias is not an outline entry, nothing expands, and every test still passes. Add a case next to "unfolds the target of a section link" inspec/system/outline_collapse_spec.rbthat visits a numbered alias fragment on a heading with its own ID. Assert that the outline section that holds it is expanded.