flat toc
This commit is contained in:
@@ -15,6 +15,7 @@ def get_opts():
|
||||
)
|
||||
parser.add_argument("-n", help="Number TOC", action="store_true")
|
||||
parser.add_argument("-l", help="TOC as links", action="store_true")
|
||||
parser.add_argument("-f", help="Flat list, i.e. not bulleted list. Good if your headers contain section numbers.", action="store_true")
|
||||
parser.add_argument(
|
||||
"-a", help="Print whole Markdown, with TOC included.", action="store_true"
|
||||
)
|
||||
@@ -37,7 +38,9 @@ def main():
|
||||
fp = open(opts.markdown, "rt")
|
||||
markdown = fp.read().splitlines()
|
||||
|
||||
bullet = "-"
|
||||
|
||||
bullet = "" if opts.f else "- "
|
||||
postspace = " " if opts.f else ""
|
||||
counters = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
|
||||
lastlev = 0
|
||||
re_anchor = re.compile("[^0-9a-z-]")
|
||||
@@ -58,9 +61,10 @@ def main():
|
||||
counters[pad] += 1
|
||||
lastlev = pad
|
||||
if opts.n:
|
||||
bullet = "{:d}.".format(counters[pad])
|
||||
|
||||
entries.append("{}{} {}".format(pad * " ", bullet, title))
|
||||
bullet = "{:d}. ".format(counters[pad])
|
||||
if opts.f:
|
||||
pad = 0
|
||||
entries.append("{}{}{}{}".format(pad * " ", bullet, title, postspace))
|
||||
if row == MARKERSTART:
|
||||
marker_found = True
|
||||
if marker_found and not marker_end_found:
|
||||
|
||||
Reference in New Issue
Block a user