fix links
This commit is contained in:
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
import argparse
|
import argparse
|
||||||
import sys
|
import sys
|
||||||
|
import re
|
||||||
|
|
||||||
def get_opts():
|
def get_opts():
|
||||||
|
|
||||||
@@ -30,11 +30,13 @@ def main():
|
|||||||
bullet = "-"
|
bullet = "-"
|
||||||
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-]')
|
||||||
for row in fp:
|
for row in fp:
|
||||||
if row.startswith("#"):
|
if row.startswith("#"):
|
||||||
headers, title = row.strip().split(" ", 1)
|
headers, title = row.strip().split(" ", 1)
|
||||||
if opts.l:
|
if opts.l:
|
||||||
title = "[{}](#{})".format(title, title.lower().replace(" ", "-"))
|
anchor = re_anchor.sub('' , title.lower().replace(" ", "-"))
|
||||||
|
title = "[{}](#{})".format(title, anchor)
|
||||||
pad = headers.count("#") - 1
|
pad = headers.count("#") - 1
|
||||||
if pad < lastlev:
|
if pad < lastlev:
|
||||||
counters = [x if i <= pad else 0 for i, x in enumerate(counters)]
|
counters = [x if i <= pad else 0 for i, x in enumerate(counters)]
|
||||||
|
|||||||
Reference in New Issue
Block a user