Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add commandline option for publish to exclude the TOC #679

Draft
wants to merge 2 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions doorstop/cli/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions doorstop/cli/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__":
Expand Down
24 changes: 24 additions & 0 deletions doorstop/cli/tests/test_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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"""
Expand Down
Loading