Skip to content

Commit

Permalink
Doc Anchor Enhancement
Browse files Browse the repository at this point in the history
This patch makes the documentation's anchors behave like those found in
Markdown when hosted on GitHub.
  • Loading branch information
akutz committed Oct 16, 2017
1 parent 84ee492 commit 36c6cb8
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 2 deletions.
21 changes: 21 additions & 0 deletions .docs/css/anchor.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
.svg-anchor {
float: left;
padding-right: 4px;
margin-left: -20px;
line-height: 1;

opacity: 0;
/*
-webkit-transition: opacity 0.2s ease-in-out 0.1s;
-moz-transition: opacity 0.2s ease-in-out 0.1s;
-ms-transition: opacity 0.2s ease-in-out 0.1s;
*/
}

h2:hover .svg-anchor,
h3:hover .svg-anchor,
h4:hover .svg-anchor,
h5:hover .svg-anchor,
h6:hover .svg-anchor {
opacity: 1;
}
11 changes: 11 additions & 0 deletions .docs/js/anchor.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
$("h2, h3, h4, h5, h6").each(function(i, el) {
var $el, svg, id;
$el = $(el);
id = $el.attr('id');
svg = '<svg aria-hidden="true" class="octicon octicon-link" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg>';
if (id) {
return $el.prepend($("<a />").addClass(
"svg-anchor").attr("aria-hidden", "true").attr(
"href", "#" + id).html(svg));
}
});
5 changes: 3 additions & 2 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@ site_favicon: favicon.png
extra_css:
- css/thecodeteam.css
- css/thecodeteam-font.css
- css/anchor.css
- css/hX.css
- css/first-of-type.css
- css/hide-rtd-footer.css
- css/dropdown.css
extra_javascript:
- js/anchor.js
markdown_extensions:
- admonition
- toc:
permalink: true
pages:
- Home: index.md
- User Guide:
Expand Down

0 comments on commit 36c6cb8

Please sign in to comment.