mirror of
https://github.com/readthedocs/sphinx_rtd_theme.git
synced 2025-02-25 18:55:21 -06:00
Use the closest section when clicking on a headerlink that isn't in the sidebar
This commit is contained in:
parent
92ac72952f
commit
afaf0dc9bd
@ -32,6 +32,7 @@ extensions = [
|
|||||||
'sphinx.ext.autodoc',
|
'sphinx.ext.autodoc',
|
||||||
'sphinx.ext.mathjax',
|
'sphinx.ext.mathjax',
|
||||||
'sphinx.ext.viewcode',
|
'sphinx.ext.viewcode',
|
||||||
|
'sphinxcontrib.httpdomain',
|
||||||
]
|
]
|
||||||
|
|
||||||
# Math
|
# Math
|
||||||
|
@ -20,7 +20,7 @@ Contents:
|
|||||||
list
|
list
|
||||||
|
|
||||||
.. toctree::
|
.. toctree::
|
||||||
:titlesonly:
|
:maxdepth: 2
|
||||||
|
|
||||||
toc
|
toc
|
||||||
|
|
||||||
|
@ -9,4 +9,16 @@ Two
|
|||||||
---
|
---
|
||||||
|
|
||||||
Three
|
Three
|
||||||
`````
|
.....
|
||||||
|
|
||||||
|
|
||||||
|
Four //five
|
||||||
|
```````````
|
||||||
|
|
||||||
|
|
||||||
|
.. http:post:: /foobar
|
||||||
|
|
||||||
|
:synopsis: Some synopsis
|
||||||
|
|
||||||
|
Some content
|
||||||
|
|
||||||
|
13
js/theme.js
13
js/theme.js
@ -97,6 +97,19 @@ function ThemeNav () {
|
|||||||
try {
|
try {
|
||||||
var link = $('.wy-menu-vertical')
|
var link = $('.wy-menu-vertical')
|
||||||
.find('[href="' + anchor + '"]');
|
.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')
|
$('.wy-menu-vertical li.toctree-l1 li.current')
|
||||||
.removeClass('current');
|
.removeClass('current');
|
||||||
link.closest('li.toctree-l2').addClass('current');
|
link.closest('li.toctree-l2').addClass('current');
|
||||||
|
Loading…
Reference in New Issue
Block a user