summaryrefslogtreecommitdiff
path: root/sphinx/util/compat.py
diff options
context:
space:
mode:
authorTakeshi KOMIYA <i.tkomiya@gmail.com>2018-08-24 18:36:35 +0900
committerTakeshi KOMIYA <i.tkomiya@gmail.com>2018-09-04 01:20:34 +0900
commit80f537192822b15a510e6d483dc200f047566fa7 (patch)
treed58d97f5acc0ddb7dce2dfac6d4af1b2df205f6d /sphinx/util/compat.py
parentbc02abcb77143d12c08265c4c10ba9c6cd003832 (diff)
downloadsphinx-git-80f537192822b15a510e6d483dc200f047566fa7.tar.gz
refactor: Add IndexEntriesMigrator to simplify
Diffstat (limited to 'sphinx/util/compat.py')
-rw-r--r--sphinx/util/compat.py20
1 files changed, 19 insertions, 1 deletions
diff --git a/sphinx/util/compat.py b/sphinx/util/compat.py
index 43ced1f5e..9fa0d56ad 100644
--- a/sphinx/util/compat.py
+++ b/sphinx/util/compat.py
@@ -14,9 +14,12 @@ from __future__ import absolute_import
import sys
import warnings
+from docutils.utils import get_source_line
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
if False:
@@ -52,8 +55,23 @@ def register_application_for_autosummary(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):
# type: (Sphinx) -> Dict[unicode, Any]
+ app.add_transform(IndexEntriesMigrator)
app.connect('config-inited', deprecate_source_parsers)
app.connect('builder-inited', register_application_for_autosummary)