Commit f66a2c55 authored by ankraft's avatar ankraft
Browse files

Added -contents / -c CLA. Printing the link to the "Contents" section is now...

Added -contents / -c CLA. Printing the link to the "Contents" section is now not added by default, but can be enabled
parent 761d5802
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -19,7 +19,7 @@ $ python generateTOC.py <document path>
## Command Line Options

```
usage: generateTOC.py [-h] [--add-content] [--indent <indent>] document
usage: generateTOC.py [-h] [--add-content] [--indent <indent>] [--contents] document

positional arguments:
  document              document to parse
@@ -29,4 +29,5 @@ options:
  --add-content, -a     add TOC to "# Content" section in the document (default: False)
  --indent <indent>, -i <indent>
                        indent spaces for each level (default: 4)
  --contents, -c        add link to "Contents" section in the generated TOC (default: False)
```
 No newline at end of file
+4 −1
Original line number Diff line number Diff line
@@ -51,7 +51,9 @@ def processDocument(args:argparse.Namespace) -> None:
			_l = line.strip()
			if _l.startswith('#'):
				level = len(_l) - len(_l.lstrip('#')) - 1 # level is number of # - 1
				headers.append((_l.lstrip('#').strip(), level))
				if (headline := _l.lstrip('#').strip()) == 'Contents' and not args.contents:
					continue
				headers.append((headline, level))
	
	# Prepare and Print the table of contents
	to = '# Contents\n\n'
@@ -93,6 +95,7 @@ if __name__ == '__main__':
	parser = argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter)
	parser.add_argument('--add-content', '-a', action='store_true', dest='addContent', default = False,  help = 'add TOC to "# Content" section in the document')
	parser.add_argument('--indent', '-i', action='store', dest='indent', default = 4, metavar = '<indent>', help = 'indent spaces for each level')
	parser.add_argument('--contents', '-c', action='store_true', dest='contents',  default = False, help = 'add link to "Contents" section in the generated TOC')

	parser.add_argument('document', help = 'document to parse')
	args = parser.parse_args()