ENT-1955 - Fix TOC for HTML and PDF (#1244)

This commit is contained in:
Tommy Lillehagen
2018-07-10 13:30:08 +01:00
committed by Michele Sollecito
parent 1751b59694
commit e51ef04560
4 changed files with 97 additions and 57 deletions

View File

@ -0,0 +1,37 @@
import re
from docutils.parsers.rst import directives
from sphinx.directives.other import TocTree
def setup(app):
app.add_directive('conditional-toctree', ConditionalTocTree)
ConditionalTocTree.defined_tags = app.tags.tags.keys()
return {'version': '1.0.0'}
def tag(argument):
return directives.choice(argument, ('htmlmode', 'pdfmode'))
class ConditionalTocTree(TocTree):
defined_tags = []
has_content = True
required_arguments = 0
optional_arguments = 0
final_argument_whitespace = False
option_spec = {
'maxdepth': int,
'name': directives.unchanged,
'caption': directives.unchanged_required,
'glob': directives.flag,
'hidden': directives.flag,
'includehidden': directives.flag,
'titlesonly': directives.flag,
'reversed': directives.flag,
'if_tag': tag,
}
def run(self):
if_tag = self.options.get('if_tag')
if if_tag in self.defined_tags:
return TocTree.run(self)
else:
return []