diff --git a/sphinx_external_toc/events.py b/sphinx_external_toc/events.py index 800396d..b5df275 100644 --- a/sphinx_external_toc/events.py +++ b/sphinx_external_toc/events.py @@ -230,9 +230,9 @@ def insert_toctrees(app: Sphinx, doctree: nodes.document) -> None: subnode["includefiles"] = [] subnode["maxdepth"] = toctree.maxdepth subnode["caption"] = toctree.caption - # TODO this wasn't in the original code, - # but alabaster theme intermittently raised `KeyError('rawcaption')` - subnode["rawcaption"] = toctree.caption or "" + # fix #118: only set rawcaption when a caption is present + if toctree.caption: + subnode["rawcaption"] = toctree.caption subnode["glob"] = any(isinstance(entry, GlobItem) for entry in toctree.items) subnode["hidden"] = False if toc_placeholders else toctree.hidden subnode["includehidden"] = False diff --git a/tests/_toc_files/nested_no_caption.yml b/tests/_toc_files/nested_no_caption.yml new file mode 100644 index 0000000..7a9c9f4 --- /dev/null +++ b/tests/_toc_files/nested_no_caption.yml @@ -0,0 +1,15 @@ +defaults: + titlesonly: true +root: intro +subtrees: +- numbered: true + entries: + - file: doc1 + - file: doc2 + - file: doc3 + subtrees: + - entries: + - file: subfolder/doc4 + - url: https://example.com +meta: + regress: intro diff --git a/tests/test_parsing/test_create_toc_dict_nested_no_caption_.yml b/tests/test_parsing/test_create_toc_dict_nested_no_caption_.yml new file mode 100644 index 0000000..a0bf9d2 --- /dev/null +++ b/tests/test_parsing/test_create_toc_dict_nested_no_caption_.yml @@ -0,0 +1,15 @@ +entries: +- file: doc1 +- file: doc2 +- entries: + - file: subfolder/doc4 + - url: https://example.com + file: doc3 + options: + titlesonly: true +meta: + regress: intro +options: + numbered: true + titlesonly: true +root: intro diff --git a/tests/test_parsing/test_file_to_sitemap_nested_no_caption_.yml b/tests/test_parsing/test_file_to_sitemap_nested_no_caption_.yml new file mode 100644 index 0000000..c957935 --- /dev/null +++ b/tests/test_parsing/test_file_to_sitemap_nested_no_caption_.yml @@ -0,0 +1,48 @@ +documents: + doc1: + docname: doc1 + subtrees: [] + title: null + doc2: + docname: doc2 + subtrees: [] + title: null + doc3: + docname: doc3 + subtrees: + - caption: null + hidden: true + items: + - subfolder/doc4 + - title: null + url: https://example.com + maxdepth: -1 + numbered: false + restart_numbering: null + reversed: false + style: numerical + titlesonly: true + title: null + intro: + docname: intro + subtrees: + - caption: null + hidden: true + items: + - doc1 + - doc2 + - doc3 + maxdepth: -1 + numbered: true + restart_numbering: null + reversed: false + style: numerical + titlesonly: true + title: null + subfolder/doc4: + docname: subfolder/doc4 + subtrees: [] + title: null +meta: + regress: intro +root: intro diff --git a/tests/test_sphinx/test_success_basic_compressed_.xml b/tests/test_sphinx/test_success_basic_compressed_.xml index 97dc357..f5fdcfa 100644 --- a/tests/test_sphinx/test_success_basic_compressed_.xml +++ b/tests/test_sphinx/test_success_basic_compressed_.xml @@ -3,4 +3,4 @@ Heading: intro.rst <compound classes="toctree-wrapper"> - <toctree caption="True" entries="(None,\ 'doc1') (None,\ 'doc2') (None,\ 'doc3')" glob="False" hidden="True" includefiles="doc1 doc2 doc3" includehidden="False" maxdepth="-1" numbered="999" parent="intro" rawcaption="" restart_numbering="True" style="numerical" titlesonly="True"> + <toctree caption="True" entries="(None,\ 'doc1') (None,\ 'doc2') (None,\ 'doc3')" glob="False" hidden="True" includefiles="doc1 doc2 doc3" includehidden="False" maxdepth="-1" numbered="999" parent="intro" restart_numbering="True" style="numerical" titlesonly="True"> diff --git a/tests/test_sphinx/test_success_nested_no_caption_.xml b/tests/test_sphinx/test_success_nested_no_caption_.xml new file mode 100644 index 0000000..f5fdcfa --- /dev/null +++ b/tests/test_sphinx/test_success_nested_no_caption_.xml @@ -0,0 +1,6 @@ +<document source="intro"> + <section ids="heading-intro-rst" names="heading:\ intro.rst"> + <title> + Heading: intro.rst + <compound classes="toctree-wrapper"> + <toctree caption="True" entries="(None,\ 'doc1') (None,\ 'doc2') (None,\ 'doc3')" glob="False" hidden="True" includefiles="doc1 doc2 doc3" includehidden="False" maxdepth="-1" numbered="999" parent="intro" restart_numbering="True" style="numerical" titlesonly="True"> diff --git a/tests/test_sphinx/test_success_tableofcontents_.xml b/tests/test_sphinx/test_success_tableofcontents_.xml index def8428..3c47625 100644 --- a/tests/test_sphinx/test_success_tableofcontents_.xml +++ b/tests/test_sphinx/test_success_tableofcontents_.xml @@ -3,6 +3,6 @@ <title> Heading: intro.rst <compound classes="toctree-wrapper"> - <toctree caption="True" entries="(None,\ 'doc1')" glob="False" hidden="False" includefiles="doc1" includehidden="False" maxdepth="-1" numbered="0" parent="intro" rawcaption="" restart_numbering="True" style="numerical" titlesonly="False"> + <toctree caption="True" entries="(None,\ 'doc1')" glob="False" hidden="False" includefiles="doc1" includehidden="False" maxdepth="-1" numbered="0" parent="intro" restart_numbering="True" style="numerical" titlesonly="False"> <compound classes="toctree-wrapper"> - <toctree caption="True" entries="(None,\ 'doc2')" glob="False" hidden="False" includefiles="doc2" includehidden="False" maxdepth="-1" numbered="0" parent="intro" rawcaption="" restart_numbering="True" style="numerical" titlesonly="False"> + <toctree caption="True" entries="(None,\ 'doc2')" glob="False" hidden="False" includefiles="doc2" includehidden="False" maxdepth="-1" numbered="0" parent="intro" restart_numbering="True" style="numerical" titlesonly="False"> diff --git a/tests/test_tools/test_file_to_sitemap_nested_no_caption_.yml b/tests/test_tools/test_file_to_sitemap_nested_no_caption_.yml new file mode 100644 index 0000000..ea77b73 --- /dev/null +++ b/tests/test_tools/test_file_to_sitemap_nested_no_caption_.yml @@ -0,0 +1,7 @@ +- _toc.yml +- doc1.rst +- doc2.rst +- doc3.rst +- intro.rst +- subfolder +- subfolder/doc4.rst