From 76b9992384e972acbd5d853dfb490c91345413ee Mon Sep 17 00:00:00 2001 From: Takeshi KOMIYA Date: Tue, 7 Jun 2016 11:02:07 +0900 Subject: [PATCH] Fix #2633: Sphinx crashes with old styled indices --- CHANGES | 1 + sphinx/io.py | 4 ++-- sphinx/transforms.py | 18 ++++++++++++++++++ 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/CHANGES b/CHANGES index 1e5295cb1..f28b98652 100644 --- a/CHANGES +++ b/CHANGES @@ -6,6 +6,7 @@ Bugs fixed * #2630: Latex sphinx.sty Notice Enviroment formatting problem * #2632: Warning directives fail in quote environment latex build +* #2633: Sphinx crashes with old styled indices Release 1.4.3 (released Jun 5, 2016) diff --git a/sphinx/io.py b/sphinx/io.py index 8d9970e80..56d133641 100644 --- a/sphinx/io.py +++ b/sphinx/io.py @@ -15,7 +15,7 @@ from six import string_types, text_type from sphinx.transforms import ApplySourceWorkaround, ExtraTranslatableNodes, Locale, \ CitationReferences, DefaultSubstitutions, MoveModuleTargets, HandleCodeBlocks, \ - AutoNumbering, SortIds, RemoveTranslatableInline + AutoNumbering, AutoIndexUpgrader, SortIds, RemoveTranslatableInline from sphinx.util import import_object, split_docinfo @@ -59,7 +59,7 @@ class SphinxStandaloneReader(SphinxBaseReader): """ transforms = [ApplySourceWorkaround, ExtraTranslatableNodes, Locale, CitationReferences, DefaultSubstitutions, MoveModuleTargets, HandleCodeBlocks, - AutoNumbering, SortIds, RemoveTranslatableInline] + AutoNumbering, AutoIndexUpgrader, SortIds, RemoveTranslatableInline] class SphinxI18nReader(SphinxBaseReader): diff --git a/sphinx/transforms.py b/sphinx/transforms.py index abeab7dab..cb4a5779b 100644 --- a/sphinx/transforms.py +++ b/sphinx/transforms.py @@ -170,6 +170,24 @@ class ApplySourceWorkaround(Transform): apply_source_workaround(n) +class AutoIndexUpgrader(Transform): + """ + Detect old style; 4 column based indices and automatically upgrade to new style. + """ + default_priority = 210 + + def apply(self): + env = self.document.settings.env + for node in self.document.traverse(addnodes.index): + if 'entries' in node and any(len(entry) == 4 for entry in node['entries']): + msg = ('4 column based index found. ' + 'It might be a bug of extensions you use: %r' % node['entries']) + env.warn_node(msg, node) + for i, entry in enumerate(node['entries']): + if len(entry) == 4: + node['entries'][i] = entry + (None,) + + class ExtraTranslatableNodes(Transform): """ make nodes translatable