Permalink
Browse files

Use the closest section when clicking on a headerlink that isn't in t…

…he sidebar
  • Loading branch information...
magopian authored and agjohnson committed Sep 30, 2016
1 parent 92ac729 commit afaf0dc9bddf19e34658e661b3c3c2a7d4dfa265
Showing with 28 additions and 2 deletions.
  1. +1 −0 demo_docs/source/conf.py
  2. +1 −1 demo_docs/source/index.rst
  3. +13 −1 demo_docs/source/toc.rst
  4. +13 −0 js/theme.js
View
@@ -32,6 +32,7 @@
'sphinx.ext.autodoc',
'sphinx.ext.mathjax',
'sphinx.ext.viewcode',
+ 'sphinxcontrib.httpdomain',
]
# Math
@@ -20,7 +20,7 @@ Contents:
list
.. toctree::
- :titlesonly:
+ :maxdepth: 2
toc
View
@@ -9,4 +9,16 @@ Two
---
Three
-`````
+.....
+
+
+Four //five
+```````````
+
+
+.. http:post:: /foobar
+
+ :synopsis: Some synopsis
+
+ Some content
+
View
@@ -97,6 +97,19 @@ function ThemeNav () {
try {
var link = $('.wy-menu-vertical')
.find('[href="' + anchor + '"]');
+ // If we didn't find a link, it may be because we clicked on
+ // something that is not in the sidebar (eg: when using
+ // sphinxcontrib.httpdomain it generates headerlinks but those
+ // aren't picked up and placed in the toctree). So let's find
+ // the closest header in the document and try with that one.
+ if (link.length === 0) {
+ var doc_link = $('.document a[href="' + anchor + '"]');
+ var closest_section = doc_link.closest('div.section');
+ // Try again with the closest section entry.
+ link = $('.wy-menu-vertical')
+ .find('[href="#' + closest_section.attr("id") + '"]');
+
+ }
$('.wy-menu-vertical li.toctree-l1 li.current')
.removeClass('current');
link.closest('li.toctree-l2').addClass('current');

0 comments on commit afaf0dc

Please sign in to comment.