From e2c7b1db4206542c72e0dfbfc78bae9a8d153dfd Mon Sep 17 00:00:00 2001 From: Takeshi KOMIYA Date: Wed, 11 Jan 2017 00:15:34 +0900 Subject: [PATCH] Add IndexEntries adapter --- sphinx/builders/devhelp.py | 3 +- sphinx/builders/html.py | 3 +- sphinx/builders/htmlhelp.py | 3 +- sphinx/builders/qthelp.py | 3 +- sphinx/environment/__init__.py | 14 +- sphinx/environment/adapters/indexentries.py | 157 ++++++++++++++++++++ sphinx/environment/managers/indexentries.py | 134 +---------------- tests/test_environment_indexentries.py | 2 +- 8 files changed, 177 insertions(+), 142 deletions(-) create mode 100644 sphinx/environment/adapters/indexentries.py diff --git a/sphinx/builders/devhelp.py b/sphinx/builders/devhelp.py index af8bcfeed..031c55184 100644 --- a/sphinx/builders/devhelp.py +++ b/sphinx/builders/devhelp.py @@ -22,6 +22,7 @@ from sphinx import addnodes from sphinx.util import logging from sphinx.util.osutil import make_filename from sphinx.builders.html import StandaloneHTMLBuilder +from sphinx.environment.adapters.indexentries import IndexEntries try: import xml.etree.ElementTree as etree @@ -104,7 +105,7 @@ class DevhelpBuilder(StandaloneHTMLBuilder): # Index functions = etree.SubElement(root, 'functions') - index = self.env.create_index(self) + index = IndexEntries(self.env).create_index(self) def write_index(title, refs, subitems): # type: (unicode, List[Any], Any) -> None diff --git a/sphinx/builders/html.py b/sphinx/builders/html.py index 5c3d9601e..062c56669 100644 --- a/sphinx/builders/html.py +++ b/sphinx/builders/html.py @@ -46,6 +46,7 @@ from sphinx.util.console import bold, darkgreen # type: ignore from sphinx.writers.html import HTMLWriter, HTMLTranslator, \ SmartyPantsHTMLTranslator from sphinx.environment.adapters.toctree import TocTree +from sphinx.environment.adapters.indexentries import IndexEntries if False: # For type annotation @@ -542,7 +543,7 @@ class StandaloneHTMLBuilder(Builder): # type: () -> None # the total count of lines for each index letter, used to distribute # the entries into two columns - genindex = self.env.create_index(self) + genindex = IndexEntries(self.env).create_index(self) indexcounts = [] for _k, entries in genindex: indexcounts.append(sum(1 + len(subitems) diff --git a/sphinx/builders/htmlhelp.py b/sphinx/builders/htmlhelp.py index 08e6f9df4..68fd3b1db 100644 --- a/sphinx/builders/htmlhelp.py +++ b/sphinx/builders/htmlhelp.py @@ -19,6 +19,7 @@ from docutils import nodes from sphinx import addnodes from sphinx.builders.html import StandaloneHTMLBuilder +from sphinx.environment.adapters.indexentries import IndexEntries from sphinx.util import logging from sphinx.util.osutil import make_filename from sphinx.util.pycompat import htmlescape @@ -281,7 +282,7 @@ class HTMLHelpBuilder(StandaloneHTMLBuilder): f.write(contents_footer) logger.info('writing index file...') - index = self.env.create_index(self) + index = IndexEntries(self.env).create_index(self) with self.open_file(outdir, outname + '.hhk') as f: f.write('