This commit is contained in:
Ville Rantanen
2023-04-19 09:04:03 +03:00
parent f06545a491
commit e8725bbeb3

View File

@@ -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-]")
@@ -59,8 +62,9 @@ def main():
lastlev = pad
if opts.n:
bullet = "{:d}. ".format(counters[pad])
entries.append("{}{} {}".format(pad * " ", bullet, title))
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: