Skip to content
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

Prevent the generation of empty anchor links #176

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ They are of the form:

```html
<a class="anchor" href="#heading1-1" aria-hidden="true">
<span class="octicon octicon-link"></span>
<span class="octicon octicon-link">Link to Heading1 1 section</span>
</a>
```

Expand Down
2 changes: 1 addition & 1 deletion lib/table_of_contents/parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def inject_anchors_into_html
@entries.each do |entry|
# NOTE: `entry[:id]` is automatically URL encoded by Nokogiri
entry[:header_content].add_previous_sibling(
%(<a class="anchor" href="##{entry[:id]}" aria-hidden="true"><span class="octicon octicon-link"></span></a>)
%(<a class="anchor" href="##{entry[:id]}" aria-hidden="true"><span class="octicon octicon-link">Link to #{entry[:text]} section</span></a>)
)
end

Expand Down
2 changes: 1 addition & 1 deletion test/parser/test_inject_anchors_filter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def setup
def test_injects_anchors_into_content
html = @parser.inject_anchors_into_html

assert_match(%r{<a class="anchor" href="#simple-h1" aria-hidden="true"><span.*span></a>Simple H1}, html)
assert_match(%r{<a class="anchor" href="#simple-h1" aria-hidden="true"><span>Link to Simple H1 section<span></a>Simple H1}, html)
end

def test_does_not_inject_toc
Expand Down