diff --git a/doorstop/cli/commands.py b/doorstop/cli/commands.py index 06c4f4d7..3c57a776 100644 --- a/doorstop/cli/commands.py +++ b/doorstop/cli/commands.py @@ -563,6 +563,8 @@ def run_publish(args, cwd, error, catch=True): kwargs = {} if args.width: kwargs["width"] = args.width + if args.no_toc: + kwargs["toc"] = False if args.index: kwargs["index"] = True diff --git a/doorstop/cli/main.py b/doorstop/cli/main.py index eb5756aa..6614e593 100644 --- a/doorstop/cli/main.py +++ b/doorstop/cli/main.py @@ -543,6 +543,11 @@ def _publish(subs, shared): help="Generate top level index (when producing markdown).", action="store_true", ) + sub.add_argument( + "--no-toc", + action="store_true", + help="do not include a table-of-contents in the output", + ) if __name__ == "__main__": diff --git a/doorstop/cli/tests/test_all.py b/doorstop/cli/tests/test_all.py index 7b6d046a..93f0e42d 100644 --- a/doorstop/cli/tests/test_all.py +++ b/doorstop/cli/tests/test_all.py @@ -796,6 +796,23 @@ def test_publish_document_html_file(self): filePath = os.path.join(self.temp, "documents", "req.html") self.assertTrue(os.path.isfile(filePath)) + def test_publish_document_md_file_no_toc(self): + """Verify 'doorstop publish --no-toc' creates an MarkDownfile with no TOC.""" + path = os.path.join(self.temp, "req.md") + self.assertIs(None, main(["publish", "--no-toc", "req", path])) + self.assertTrue(os.path.isfile(path)) + text = common.read_text(path) + self.assertNotIn("Table of Contents", text) + + def test_publish_document_html_file_no_toc(self): + """Verify 'doorstop publish --no-toc' creates an HTML file with no TOC.""" + path = os.path.join(self.temp, "req.html") + self.assertIs(None, main(["publish", "--no-toc", "req", path])) + filePath = os.path.join(self.temp, "documents", "req.html") + self.assertTrue(os.path.isfile(filePath)) + text = common.read_text(filePath) + self.assertNotIn("Table of Contents", text) + def test_publish_tree_html(self): """Verify 'doorstop publish' can create an HTML directory.""" path = os.path.join(self.temp, "all") @@ -842,6 +859,13 @@ def test_publish_markdown_tree_no_path(self): ], ) + def test_publish_tree_html_no_toc(self): + """Verify 'doorstop publish --no-toc' returns a html document with no toc.""" + path = os.path.join(self.temp, "all") + self.assertIs(None, main(["publish", "--no-toc", "all", path])) + self.assertTrue(os.path.isdir(path)) + self.assertTrue(os.path.isfile(os.path.join(path, "index.html"))) + class TestPublishCommand(TempTestCase): """Tests 'doorstop publish' options toc and template"""