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("-n", help="Number TOC", action="store_true")
|
||||||
parser.add_argument("-l", help="TOC as links", 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(
|
parser.add_argument(
|
||||||
"-a", help="Print whole Markdown, with TOC included.", action="store_true"
|
"-a", help="Print whole Markdown, with TOC included.", action="store_true"
|
||||||
)
|
)
|
||||||
@@ -37,7 +38,9 @@ def main():
|
|||||||
fp = open(opts.markdown, "rt")
|
fp = open(opts.markdown, "rt")
|
||||||
markdown = fp.read().splitlines()
|
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]
|
counters = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
|
||||||
lastlev = 0
|
lastlev = 0
|
||||||
re_anchor = re.compile("[^0-9a-z-]")
|
re_anchor = re.compile("[^0-9a-z-]")
|
||||||
@@ -59,8 +62,9 @@ def main():
|
|||||||
lastlev = pad
|
lastlev = pad
|
||||||
if opts.n:
|
if opts.n:
|
||||||
bullet = "{:d}. ".format(counters[pad])
|
bullet = "{:d}. ".format(counters[pad])
|
||||||
|
if opts.f:
|
||||||
entries.append("{}{} {}".format(pad * " ", bullet, title))
|
pad = 0
|
||||||
|
entries.append("{}{}{}{}".format(pad * " ", bullet, title, postspace))
|
||||||
if row == MARKERSTART:
|
if row == MARKERSTART:
|
||||||
marker_found = True
|
marker_found = True
|
||||||
if marker_found and not marker_end_found:
|
if marker_found and not marker_end_found:
|
||||||
|
|||||||
Reference in New Issue
Block a user