From 4bd0eab865936f1029f5619e8b7003cb3dd4aa25 Mon Sep 17 00:00:00 2001 From: Tommy Beadle Date: Fri, 21 Jun 2019 15:12:08 -0400 Subject: [PATCH] Allow the Auto TOC maxdepth to be configurable. This adds the 'auto_toc_maxdepth' config option (defaults to 1) that will set the max depth for the auto-generated table of contents. --- README.md | 1 + recommonmark/transform.py | 6 +++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index e1e4214..948f5cc 100644 --- a/README.md +++ b/README.md @@ -105,6 +105,7 @@ See https://github.com/rtfd/recommonmark/blob/master/docs/conf.py for a full exa AutoStructify comes with the following options. See [http://recommonmark.readthedocs.org/en/latest/auto_structify.html](http://recommonmark.readthedocs.org/en/latest/auto_structify.html) for more information about the specific features. * __enable_auto_toc_tree__: enable the Auto Toc Tree feature. +* __auto_toc_maxdepth__: The max depth of the Auto Toc. Defaults to 1. * __auto_toc_tree_section__: when True, Auto Toc Tree will only be enabled on section that matches the title. * __enable_auto_doc_ref__: enable the Auto Doc Ref feature. **Deprecated** * __enable_math__: enable the Math Formula feature. diff --git a/recommonmark/transform.py b/recommonmark/transform.py index dc15427..92409a0 100644 --- a/recommonmark/transform.py +++ b/recommonmark/transform.py @@ -41,6 +41,7 @@ class AutoStructify(transforms.Transform): default_config = { 'enable_auto_doc_ref': False, + 'auto_toc_maxdepth': 1, 'auto_toc_tree_section': None, 'enable_auto_toc_tree': True, 'enable_eval_rst': True, @@ -179,7 +180,10 @@ class AutoStructify(transforms.Transform): self.current_level) return self.state_machine.run_directive( 'toctree', - options={'maxdepth': 1, 'numbered': numbered}, + options={ + 'maxdepth': self.config['auto_toc_maxdepth'], + 'numbered': numbered, + }, content=['%s <%s>' % (k, v) for k, v in refs]) def auto_inline_code(self, node):