mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Merge pull request #5386 from tk0miya/add_IndexEntriesMigrator
refactor: Add IndexEntriesMigrator to simplify
This commit is contained in:
commit
9553453424
@ -50,11 +50,7 @@ class IndexEntriesCollector(EnvironmentCollector):
|
|||||||
node.parent.remove(node)
|
node.parent.remove(node)
|
||||||
else:
|
else:
|
||||||
for entry in node['entries']:
|
for entry in node['entries']:
|
||||||
if len(entry) == 5:
|
|
||||||
# Since 1.4: new index structure including index_key (5th column)
|
|
||||||
entries.append(entry)
|
entries.append(entry)
|
||||||
else:
|
|
||||||
entries.append(entry + (None,))
|
|
||||||
|
|
||||||
|
|
||||||
def setup(app):
|
def setup(app):
|
||||||
|
@ -14,9 +14,12 @@ from __future__ import absolute_import
|
|||||||
import sys
|
import sys
|
||||||
import warnings
|
import warnings
|
||||||
|
|
||||||
|
from docutils.utils import get_source_line
|
||||||
from six import string_types, iteritems
|
from six import string_types, iteritems
|
||||||
|
|
||||||
from sphinx.deprecation import RemovedInSphinx30Warning
|
from sphinx import addnodes
|
||||||
|
from sphinx.deprecation import RemovedInSphinx30Warning, RemovedInSphinx40Warning
|
||||||
|
from sphinx.transforms import SphinxTransform
|
||||||
from sphinx.util import import_object
|
from sphinx.util import import_object
|
||||||
|
|
||||||
if False:
|
if False:
|
||||||
@ -52,8 +55,23 @@ def register_application_for_autosummary(app):
|
|||||||
autosummary._app = app
|
autosummary._app = app
|
||||||
|
|
||||||
|
|
||||||
|
class IndexEntriesMigrator(SphinxTransform):
|
||||||
|
"""Migrating indexentries from old style (4columns) to new style (5columns)."""
|
||||||
|
default_priority = 700
|
||||||
|
|
||||||
|
def apply(self):
|
||||||
|
for node in self.document.traverse(addnodes.index):
|
||||||
|
for entries in node['entries']:
|
||||||
|
if len(entries) == 4:
|
||||||
|
source, line = get_source_line(node)
|
||||||
|
warnings.warn('An old styled index node found: %r at (%s:%s)' %
|
||||||
|
(node, source, line), RemovedInSphinx40Warning)
|
||||||
|
entries.extend([None])
|
||||||
|
|
||||||
|
|
||||||
def setup(app):
|
def setup(app):
|
||||||
# type: (Sphinx) -> Dict[unicode, Any]
|
# type: (Sphinx) -> Dict[unicode, Any]
|
||||||
|
app.add_transform(IndexEntriesMigrator)
|
||||||
app.connect('config-inited', deprecate_source_parsers)
|
app.connect('config-inited', deprecate_source_parsers)
|
||||||
app.connect('builder-inited', register_application_for_autosummary)
|
app.connect('builder-inited', register_application_for_autosummary)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user