From 692d896a4342156c4ed0f49655dcd7bbce96930f Mon Sep 17 00:00:00 2001
From: Thomas J Fan
Date: Sun, 19 Apr 2020 19:41:46 -0400
Subject: [PATCH 01/11] DOC Adjusts toc on left
---
doc/conf.py | 3 +-
doc/contents.rst | 5 +-
doc/data_transforms.rst | 3 +
doc/datasets/index.rst | 3 +
doc/developers/index.rst | 5 +-
doc/inspection.rst | 3 +
doc/model_selection.rst | 3 +
doc/modules/computing.rst | 3 +
doc/preface.rst | 8 +-
doc/sphinxext/add_toctree_functions.py | 119 ++++++++++++++++++
doc/supervised_learning.rst | 3 +
doc/themes/scikit-learn-modern/layout.html | 39 ++++--
.../scikit-learn-modern/static/css/theme.css | 4 +
doc/tutorial/index.rst | 9 --
doc/unsupervised_learning.rst | 3 +
doc/user_guide.rst | 5 +-
doc/visualizations.rst | 3 +
17 files changed, 189 insertions(+), 32 deletions(-)
create mode 100644 doc/sphinxext/add_toctree_functions.py
diff --git a/doc/conf.py b/doc/conf.py
index c3ab17d3e73af..4ffe88e09e34c 100644
--- a/doc/conf.py
+++ b/doc/conf.py
@@ -38,7 +38,8 @@
'sphinx.ext.intersphinx',
'sphinx.ext.imgconverter',
'sphinx_gallery.gen_gallery',
- 'sphinx_issues'
+ 'sphinx_issues',
+ 'add_toctree_functions',
]
# this is needed for some reason...
diff --git a/doc/contents.rst b/doc/contents.rst
index a28634621d558..75c16f3e0b13d 100644
--- a/doc/contents.rst
+++ b/doc/contents.rst
@@ -1,9 +1,8 @@
.. include:: includes/big_toc_css.rst
.. include:: tune_toc.rst
-.. Places global toc into the sidebar
-
-:globalsidebartoc: True
+.. Places parent toc into the sidebar
+:parenttoc: True
=================
Table Of Contents
diff --git a/doc/data_transforms.rst b/doc/data_transforms.rst
index 01547f68008b6..50c93ac935276 100644
--- a/doc/data_transforms.rst
+++ b/doc/data_transforms.rst
@@ -1,3 +1,6 @@
+.. Places parent toc into the sidebar
+:parenttoc: True
+
.. include:: includes/big_toc_css.rst
.. _data-transforms:
diff --git a/doc/datasets/index.rst b/doc/datasets/index.rst
index 88ae88d7a3151..d68c3ea348338 100644
--- a/doc/datasets/index.rst
+++ b/doc/datasets/index.rst
@@ -1,3 +1,6 @@
+.. Places parent toc into the sidebar
+:parenttoc: True
+
.. _datasets:
=========================
diff --git a/doc/developers/index.rst b/doc/developers/index.rst
index e64adf5ac73a9..92c102a1da3da 100644
--- a/doc/developers/index.rst
+++ b/doc/developers/index.rst
@@ -1,6 +1,5 @@
-.. Places global toc into the sidebar
-
-:globalsidebartoc: True
+.. Places parent toc into the sidebar
+:parenttoc: True
.. _developers_guide:
diff --git a/doc/inspection.rst b/doc/inspection.rst
index 1304a1030abb9..3c63ca67782fc 100644
--- a/doc/inspection.rst
+++ b/doc/inspection.rst
@@ -1,3 +1,6 @@
+.. Places parent toc into the sidebar
+:parenttoc: True
+
.. include:: includes/big_toc_css.rst
.. _inspection:
diff --git a/doc/model_selection.rst b/doc/model_selection.rst
index 7b540072c15e5..97b2e40be8cb6 100644
--- a/doc/model_selection.rst
+++ b/doc/model_selection.rst
@@ -1,3 +1,6 @@
+.. Places parent toc into the sidebar
+:parenttoc: True
+
.. include:: includes/big_toc_css.rst
.. _model_selection:
diff --git a/doc/modules/computing.rst b/doc/modules/computing.rst
index 246085d436cde..209d9e544a1a1 100644
--- a/doc/modules/computing.rst
+++ b/doc/modules/computing.rst
@@ -1,3 +1,6 @@
+.. Places parent toc into the sidebar
+:parenttoc: True
+
============================
Computing with scikit-learn
============================
diff --git a/doc/preface.rst b/doc/preface.rst
index 447083a3a8136..9773a53e0f2b4 100644
--- a/doc/preface.rst
+++ b/doc/preface.rst
@@ -1,9 +1,8 @@
.. This helps define the TOC ordering for "about us" sections. Particularly
useful for PDF output as this section is not linked from elsewhere.
-.. Places global toc into the sidebar
-
-:globalsidebartoc: True
+.. Places parent toc into the sidebar
+:parenttoc: True
.. _preface_menu:
@@ -14,8 +13,6 @@
Welcome to scikit-learn
=======================
-|
-
.. toctree::
:maxdepth: 2
@@ -29,4 +26,3 @@ Welcome to scikit-learn
roadmap
governance
-|
diff --git a/doc/sphinxext/add_toctree_functions.py b/doc/sphinxext/add_toctree_functions.py
new file mode 100644
index 0000000000000..c8c4611d80e13
--- /dev/null
+++ b/doc/sphinxext/add_toctree_functions.py
@@ -0,0 +1,119 @@
+import docutils
+
+
+def add_toctree_functions(app, pagename, templatename, context, doctree):
+ """Add functions so Jinja templates can add toctree objects.
+
+ This converts the docutils nodes into a nested dictionary that Jinja can
+ use in our templating.
+ """
+ from sphinx.environment.adapters.toctree import TocTree
+
+ def get_nav_object(maxdepth=None, collapse=True, **kwargs):
+ """Return a list of nav links that can be accessed from Jinja.
+
+ Parameters
+ ----------
+ maxdepth: int
+ How many layers of TocTree will be returned
+ collapse: bool
+ Whether to only include sub-pages of the currently-active page,
+ instead of sub-pages of all top-level pages of the site.
+ kwargs: key/val pairs
+ Passed to the `TocTree.get_toctree_for` Sphinx method
+ """
+ # The TocTree will contain the full site TocTree including sub-pages.
+ # "collapse=True" collapses sub-pages of non-active TOC pages.
+ # maxdepth controls how many TOC levels are returned
+ toctree = TocTree(app.env).get_toctree_for(
+ pagename, app.builder, collapse=collapse, maxdepth=maxdepth, **kwargs
+ )
+ # If no toctree is defined (AKA a single-page site), skip this
+ if toctree is None:
+ return []
+
+ # toctree has this structure
+ #
+ #
+ #
+ #
+ # `list_item`s are the actual TOC links and are the only thing we want
+ toc_items = [item for child in toctree.children for item in child
+ if isinstance(item, docutils.nodes.list_item)]
+
+ # Now convert our docutils nodes into dicts that Jinja can use
+ nav = [docutils_node_to_jinja(child, only_pages=True)
+ for child in toc_items]
+
+ return nav
+
+ def get_page_toc_object():
+ """Return a list of within-page TOC links that can be accessed from Jinja."""
+ self_toc = TocTree(app.env).get_toc_for(pagename, app.builder)
+
+ try:
+ nav = docutils_node_to_jinja(self_toc.children[0])
+ return nav
+ except:
+ return {}
+
+ context["get_nav_object"] = get_nav_object
+ context["get_page_toc_object"] = get_page_toc_object
+
+
+def docutils_node_to_jinja(list_item, only_pages=False):
+ """Convert a docutils node to a structure that can be read by Jinja.
+
+ Parameters
+ ----------
+ list_item : docutils list_item node
+ A parent item, potentially with children, corresponding to the level
+ of a TocTree.
+ only_pages : bool
+ Only include items for full pages in the output dictionary. Exclude
+ anchor links (TOC items with a URL that starts with #)
+
+ Returns
+ -------
+ nav : dict
+ The TocTree, converted into a dictionary with key/values that work
+ within Jinja.
+ """
+ if not list_item.children:
+ return None
+
+ # We assume this structure of a list item:
+ #
+ #
+ # <-- the thing we want
+ reference = list_item.children[0].children[0]
+ title = reference.astext()
+ url = reference.attributes["refuri"]
+ active = "current" in list_item.attributes["classes"]
+
+ # If we've got an anchor link, skip it if we wish
+ if only_pages and '#' in url:
+ return None
+
+ # Converting the docutils attributes into jinja-friendly objects
+ nav = {}
+ nav["title"] = title
+ nav["url"] = url
+ nav["active"] = active
+
+ # Recursively convert children as well
+ # If there are sub-pages for this list_item, there should be two children:
+ # a paragraph, and a bullet_list.
+ nav["children"] = []
+ if len(list_item.children) > 1:
+ # The `.children` of the bullet_list has the nodes of the sub-pages.
+ subpage_list = list_item.children[1].children
+ for sub_page in subpage_list:
+ child_nav = docutils_node_to_jinja(sub_page, only_pages=only_pages)
+ if child_nav is not None:
+ nav["children"].append(child_nav)
+ return nav
+
+
+def setup(app):
+ app.connect("html-page-context", add_toctree_functions)
diff --git a/doc/supervised_learning.rst b/doc/supervised_learning.rst
index b89e9e033e96b..0236320028a98 100644
--- a/doc/supervised_learning.rst
+++ b/doc/supervised_learning.rst
@@ -1,3 +1,6 @@
+.. Places parent toc into the sidebar
+:parenttoc: True
+
.. include:: includes/big_toc_css.rst
.. _supervised-learning:
diff --git a/doc/themes/scikit-learn-modern/layout.html b/doc/themes/scikit-learn-modern/layout.html
index 6f29cf52f7c91..5519b98ab65fc 100644
--- a/doc/themes/scikit-learn-modern/layout.html
+++ b/doc/themes/scikit-learn-modern/layout.html
@@ -87,15 +87,40 @@
Please cite us if you use the software.
- {%- if meta and meta['globalsidebartoc']|tobool %}
-
- {%- else %}
- {%- endif %}
diff --git a/doc/themes/scikit-learn-modern/static/css/theme.css b/doc/themes/scikit-learn-modern/static/css/theme.css
index 2b80d6fe2b762..f1e490a12b3d9 100644
--- a/doc/themes/scikit-learn-modern/static/css/theme.css
+++ b/doc/themes/scikit-learn-modern/static/css/theme.css
@@ -511,6 +511,10 @@ div.sk-sidebar-toc-logo {
height: 52px;
}
+.sk-toc-active {
+ font-weight: bold;
+}
+
div.sk-sidebar-toc-wrapper {
font-size: 0.9rem;
width: 252px;
diff --git a/doc/tutorial/index.rst b/doc/tutorial/index.rst
index cfd63719321f2..b9bf27b6921bb 100644
--- a/doc/tutorial/index.rst
+++ b/doc/tutorial/index.rst
@@ -1,10 +1,5 @@
-.. Places global toc into the sidebar
-
-:globalsidebartoc: True
-
.. _tutorial_menu:
-
.. include:: ../includes/big_toc_css.rst
.. include:: ../tune_toc.rst
@@ -12,8 +7,6 @@
scikit-learn Tutorials
======================
-|
-
.. toctree::
:maxdepth: 2
@@ -23,8 +16,6 @@ scikit-learn Tutorials
machine_learning_map/index
../presentations
-|
-
.. note:: **Doctest Mode**
The code-examples in the above tutorials are written in a
diff --git a/doc/unsupervised_learning.rst b/doc/unsupervised_learning.rst
index e09e13ef1a942..5e5998c9ddf48 100644
--- a/doc/unsupervised_learning.rst
+++ b/doc/unsupervised_learning.rst
@@ -1,3 +1,6 @@
+.. Places parent toc into the sidebar
+:parenttoc: True
+
.. include:: includes/big_toc_css.rst
.. _unsupervised-learning:
diff --git a/doc/user_guide.rst b/doc/user_guide.rst
index 48679aa961782..6e9f06fa18446 100644
--- a/doc/user_guide.rst
+++ b/doc/user_guide.rst
@@ -1,6 +1,5 @@
-.. Places global toc into the sidebar
-
-:globalsidebartoc: True
+.. Places parent toc into the sidebar
+:parenttoc: True
.. title:: User guide: contents
diff --git a/doc/visualizations.rst b/doc/visualizations.rst
index 47d826602b62f..3c3b8e985dd0f 100644
--- a/doc/visualizations.rst
+++ b/doc/visualizations.rst
@@ -1,3 +1,6 @@
+.. Places parent toc into the sidebar
+:parenttoc: True
+
.. include:: includes/big_toc_css.rst
.. _visualizations:
From 1c620db4e5a060c0d7a8360b0a5225cfd5a71171 Mon Sep 17 00:00:00 2001
From: Thomas J Fan
Date: Sun, 19 Apr 2020 19:52:45 -0400
Subject: [PATCH 02/11] DOC Adds support to nav
---
doc/themes/scikit-learn-modern/nav.html | 1 +
1 file changed, 1 insertion(+)
diff --git a/doc/themes/scikit-learn-modern/nav.html b/doc/themes/scikit-learn-modern/nav.html
index 57c631f6cbee7..b85e1df1bd66a 100644
--- a/doc/themes/scikit-learn-modern/nav.html
+++ b/doc/themes/scikit-learn-modern/nav.html
@@ -12,6 +12,7 @@
('Glossary', pathto('glossary')),
('Development', pathto('developers/index')),
('FAQ', pathto('faq')),
+ ('Support', pathto('support')),
('Related packages', pathto('related_projects')),
('Roadmap', pathto('roadmap')),
('About us', pathto('about')),
From 230fcba61d7c5b4536672ea20f763f939aff2212 Mon Sep 17 00:00:00 2001
From: Thomas J Fan
Date: Sun, 19 Apr 2020 19:56:32 -0400
Subject: [PATCH 03/11] DOC Adds license
---
doc/sphinxext/add_toctree_functions.py | 48 +++++++++++++++++++-------
1 file changed, 35 insertions(+), 13 deletions(-)
diff --git a/doc/sphinxext/add_toctree_functions.py b/doc/sphinxext/add_toctree_functions.py
index c8c4611d80e13..efdce234e32a7 100644
--- a/doc/sphinxext/add_toctree_functions.py
+++ b/doc/sphinxext/add_toctree_functions.py
@@ -1,3 +1,36 @@
+"""Inspired by https://github.com/pandas-dev/pydata-sphinx-theme
+
+BSD 3-Clause License
+
+Copyright (c) 2018, pandas
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+
+* Redistributions of source code must retain the above copyright notice, this
+ list of conditions and the following disclaimer.
+
+* Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+
+* Neither the name of the copyright holder nor the names of its
+ contributors may be used to endorse or promote products derived from
+ this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+"""
+
import docutils
@@ -26,8 +59,8 @@ def get_nav_object(maxdepth=None, collapse=True, **kwargs):
# "collapse=True" collapses sub-pages of non-active TOC pages.
# maxdepth controls how many TOC levels are returned
toctree = TocTree(app.env).get_toctree_for(
- pagename, app.builder, collapse=collapse, maxdepth=maxdepth, **kwargs
- )
+ pagename, app.builder, collapse=collapse, maxdepth=maxdepth,
+ **kwargs)
# If no toctree is defined (AKA a single-page site), skip this
if toctree is None:
return []
@@ -47,18 +80,7 @@ def get_nav_object(maxdepth=None, collapse=True, **kwargs):
return nav
- def get_page_toc_object():
- """Return a list of within-page TOC links that can be accessed from Jinja."""
- self_toc = TocTree(app.env).get_toc_for(pagename, app.builder)
-
- try:
- nav = docutils_node_to_jinja(self_toc.children[0])
- return nav
- except:
- return {}
-
context["get_nav_object"] = get_nav_object
- context["get_page_toc_object"] = get_page_toc_object
def docutils_node_to_jinja(list_item, only_pages=False):
From 46f124cba5869f5268e4feaf4126447e41fad793 Mon Sep 17 00:00:00 2001
From: Thomas J Fan
Date: Mon, 20 Apr 2020 20:33:25 -0400
Subject: [PATCH 04/11] STY Fixes rst formating
---
doc/contents.rst | 1 +
doc/data_transforms.rst | 1 +
doc/datasets/index.rst | 1 +
doc/developers/index.rst | 1 +
doc/inspection.rst | 1 +
doc/model_selection.rst | 1 +
doc/modules/computing.rst | 1 +
doc/preface.rst | 1 +
doc/supervised_learning.rst | 1 +
doc/unsupervised_learning.rst | 1 +
doc/user_guide.rst | 1 +
doc/visualizations.rst | 1 +
12 files changed, 12 insertions(+)
diff --git a/doc/contents.rst b/doc/contents.rst
index 75c16f3e0b13d..829fbc7e3dc98 100644
--- a/doc/contents.rst
+++ b/doc/contents.rst
@@ -2,6 +2,7 @@
.. include:: tune_toc.rst
.. Places parent toc into the sidebar
+
:parenttoc: True
=================
diff --git a/doc/data_transforms.rst b/doc/data_transforms.rst
index 50c93ac935276..084214cb094f5 100644
--- a/doc/data_transforms.rst
+++ b/doc/data_transforms.rst
@@ -1,4 +1,5 @@
.. Places parent toc into the sidebar
+
:parenttoc: True
.. include:: includes/big_toc_css.rst
diff --git a/doc/datasets/index.rst b/doc/datasets/index.rst
index d68c3ea348338..ff66fd20ed9d7 100644
--- a/doc/datasets/index.rst
+++ b/doc/datasets/index.rst
@@ -1,4 +1,5 @@
.. Places parent toc into the sidebar
+
:parenttoc: True
.. _datasets:
diff --git a/doc/developers/index.rst b/doc/developers/index.rst
index 92c102a1da3da..a9e691968a6ff 100644
--- a/doc/developers/index.rst
+++ b/doc/developers/index.rst
@@ -1,4 +1,5 @@
.. Places parent toc into the sidebar
+
:parenttoc: True
.. _developers_guide:
diff --git a/doc/inspection.rst b/doc/inspection.rst
index 3c63ca67782fc..72305bec73a10 100644
--- a/doc/inspection.rst
+++ b/doc/inspection.rst
@@ -1,4 +1,5 @@
.. Places parent toc into the sidebar
+
:parenttoc: True
.. include:: includes/big_toc_css.rst
diff --git a/doc/model_selection.rst b/doc/model_selection.rst
index 97b2e40be8cb6..04e41c454419e 100644
--- a/doc/model_selection.rst
+++ b/doc/model_selection.rst
@@ -1,4 +1,5 @@
.. Places parent toc into the sidebar
+
:parenttoc: True
.. include:: includes/big_toc_css.rst
diff --git a/doc/modules/computing.rst b/doc/modules/computing.rst
index 209d9e544a1a1..f15f4c95fa6ac 100644
--- a/doc/modules/computing.rst
+++ b/doc/modules/computing.rst
@@ -1,4 +1,5 @@
.. Places parent toc into the sidebar
+
:parenttoc: True
============================
diff --git a/doc/preface.rst b/doc/preface.rst
index 9773a53e0f2b4..08100c028e40c 100644
--- a/doc/preface.rst
+++ b/doc/preface.rst
@@ -2,6 +2,7 @@
useful for PDF output as this section is not linked from elsewhere.
.. Places parent toc into the sidebar
+
:parenttoc: True
.. _preface_menu:
diff --git a/doc/supervised_learning.rst b/doc/supervised_learning.rst
index 0236320028a98..d6e907f60cf84 100644
--- a/doc/supervised_learning.rst
+++ b/doc/supervised_learning.rst
@@ -1,4 +1,5 @@
.. Places parent toc into the sidebar
+
:parenttoc: True
.. include:: includes/big_toc_css.rst
diff --git a/doc/unsupervised_learning.rst b/doc/unsupervised_learning.rst
index 5e5998c9ddf48..9c1de0c134623 100644
--- a/doc/unsupervised_learning.rst
+++ b/doc/unsupervised_learning.rst
@@ -1,4 +1,5 @@
.. Places parent toc into the sidebar
+
:parenttoc: True
.. include:: includes/big_toc_css.rst
diff --git a/doc/user_guide.rst b/doc/user_guide.rst
index 6e9f06fa18446..cd65983d1ee86 100644
--- a/doc/user_guide.rst
+++ b/doc/user_guide.rst
@@ -1,4 +1,5 @@
.. Places parent toc into the sidebar
+
:parenttoc: True
.. title:: User guide: contents
diff --git a/doc/visualizations.rst b/doc/visualizations.rst
index 3c3b8e985dd0f..b16aafa9a05c8 100644
--- a/doc/visualizations.rst
+++ b/doc/visualizations.rst
@@ -1,4 +1,5 @@
.. Places parent toc into the sidebar
+
:parenttoc: True
.. include:: includes/big_toc_css.rst
From eab7f44713c98a93239f8f380a9e0d2b4e24c104 Mon Sep 17 00:00:00 2001
From: Thomas J Fan
Date: Wed, 22 Apr 2020 19:17:28 -0400
Subject: [PATCH 05/11] ENH Adds global back in
---
doc/contents.rst | 4 ++--
doc/preface.rst | 4 ++--
doc/themes/scikit-learn-modern/layout.html | 12 ++++++++----
3 files changed, 12 insertions(+), 8 deletions(-)
diff --git a/doc/contents.rst b/doc/contents.rst
index 829fbc7e3dc98..a28634621d558 100644
--- a/doc/contents.rst
+++ b/doc/contents.rst
@@ -1,9 +1,9 @@
.. include:: includes/big_toc_css.rst
.. include:: tune_toc.rst
-.. Places parent toc into the sidebar
+.. Places global toc into the sidebar
-:parenttoc: True
+:globalsidebartoc: True
=================
Table Of Contents
diff --git a/doc/preface.rst b/doc/preface.rst
index 08100c028e40c..ce3bf6c73092f 100644
--- a/doc/preface.rst
+++ b/doc/preface.rst
@@ -1,9 +1,9 @@
.. This helps define the TOC ordering for "about us" sections. Particularly
useful for PDF output as this section is not linked from elsewhere.
-.. Places parent toc into the sidebar
+.. Places global toc into the sidebar
-:parenttoc: True
+:globalsidebartoc: True
.. _preface_menu:
diff --git a/doc/themes/scikit-learn-modern/layout.html b/doc/themes/scikit-learn-modern/layout.html
index 5519b98ab65fc..e930bab6b53ce 100644
--- a/doc/themes/scikit-learn-modern/layout.html
+++ b/doc/themes/scikit-learn-modern/layout.html
@@ -87,10 +87,10 @@
Please cite us if you use the software.
-
From 9755d58a9f27c36dcf3d2d7ebd8b40f909aadb32 Mon Sep 17 00:00:00 2001
From: Thomas J Fan
Date: Wed, 22 Apr 2020 19:20:15 -0400
Subject: [PATCH 06/11] REV Less diffs
---
doc/preface.rst | 3 +++
doc/tutorial/index.rst | 9 +++++++++
2 files changed, 12 insertions(+)
diff --git a/doc/preface.rst b/doc/preface.rst
index ce3bf6c73092f..447083a3a8136 100644
--- a/doc/preface.rst
+++ b/doc/preface.rst
@@ -14,6 +14,8 @@
Welcome to scikit-learn
=======================
+|
+
.. toctree::
:maxdepth: 2
@@ -27,3 +29,4 @@ Welcome to scikit-learn
roadmap
governance
+|
diff --git a/doc/tutorial/index.rst b/doc/tutorial/index.rst
index b9bf27b6921bb..cfd63719321f2 100644
--- a/doc/tutorial/index.rst
+++ b/doc/tutorial/index.rst
@@ -1,5 +1,10 @@
+.. Places global toc into the sidebar
+
+:globalsidebartoc: True
+
.. _tutorial_menu:
+
.. include:: ../includes/big_toc_css.rst
.. include:: ../tune_toc.rst
@@ -7,6 +12,8 @@
scikit-learn Tutorials
======================
+|
+
.. toctree::
:maxdepth: 2
@@ -16,6 +23,8 @@ scikit-learn Tutorials
machine_learning_map/index
../presentations
+|
+
.. note:: **Doctest Mode**
The code-examples in the above tutorials are written in a
From 25a9d27801cb83c6444d17c2212731163a3d7319 Mon Sep 17 00:00:00 2001
From: "Thomas J. Fan"
Date: Sat, 25 Jul 2020 11:51:08 -0400
Subject: [PATCH 07/11] DOC Adds section numbers
---
doc/sphinxext/add_toctree_functions.py | 15 +++++++++++----
doc/themes/scikit-learn-modern/layout.html | 2 +-
.../scikit-learn-modern/static/css/theme.css | 1 -
3 files changed, 12 insertions(+), 6 deletions(-)
diff --git a/doc/sphinxext/add_toctree_functions.py b/doc/sphinxext/add_toctree_functions.py
index efdce234e32a7..88110e4207c73 100644
--- a/doc/sphinxext/add_toctree_functions.py
+++ b/doc/sphinxext/add_toctree_functions.py
@@ -42,7 +42,7 @@ def add_toctree_functions(app, pagename, templatename, context, doctree):
"""
from sphinx.environment.adapters.toctree import TocTree
- def get_nav_object(maxdepth=None, collapse=True, **kwargs):
+ def get_nav_object(maxdepth=None, collapse=True, numbered=False, **kwargs):
"""Return a list of nav links that can be accessed from Jinja.
Parameters
@@ -75,7 +75,8 @@ def get_nav_object(maxdepth=None, collapse=True, **kwargs):
if isinstance(item, docutils.nodes.list_item)]
# Now convert our docutils nodes into dicts that Jinja can use
- nav = [docutils_node_to_jinja(child, only_pages=True)
+ nav = [docutils_node_to_jinja(child, only_pages=True,
+ numbered=numbered)
for child in toc_items]
return nav
@@ -83,7 +84,7 @@ def get_nav_object(maxdepth=None, collapse=True, **kwargs):
context["get_nav_object"] = get_nav_object
-def docutils_node_to_jinja(list_item, only_pages=False):
+def docutils_node_to_jinja(list_item, only_pages=False, numbered=False):
"""Convert a docutils node to a structure that can be read by Jinja.
Parameters
@@ -113,6 +114,11 @@ def docutils_node_to_jinja(list_item, only_pages=False):
url = reference.attributes["refuri"]
active = "current" in list_item.attributes["classes"]
+ secnumber = reference.attributes.get("secnumber", None)
+ if numbered and secnumber is not None:
+ secnumber = ".".join(str(n) for n in secnumber)
+ title = f"{secnumber}. {title}"
+
# If we've got an anchor link, skip it if we wish
if only_pages and '#' in url:
return None
@@ -131,7 +137,8 @@ def docutils_node_to_jinja(list_item, only_pages=False):
# The `.children` of the bullet_list has the nodes of the sub-pages.
subpage_list = list_item.children[1].children
for sub_page in subpage_list:
- child_nav = docutils_node_to_jinja(sub_page, only_pages=only_pages)
+ child_nav = docutils_node_to_jinja(sub_page, only_pages=only_pages,
+ numbered=numbered)
if child_nav is not None:
nav["children"].append(child_nav)
return nav
diff --git a/doc/themes/scikit-learn-modern/layout.html b/doc/themes/scikit-learn-modern/layout.html
index c2fdaf1073c7a..a4b9733b68709 100644
--- a/doc/themes/scikit-learn-modern/layout.html
+++ b/doc/themes/scikit-learn-modern/layout.html
@@ -88,7 +88,7 @@
{%- if meta and meta['parenttoc']|tobool %}