From 797ba02b57b49fae72c548437fb8c65fe1f7c924 Mon Sep 17 00:00:00 2001 From: Ville Rantanen Date: Tue, 3 Jan 2023 14:05:25 +0200 Subject: [PATCH] fix links --- reporting/md-toc | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/reporting/md-toc b/reporting/md-toc index 8532465..e40296d 100755 --- a/reporting/md-toc +++ b/reporting/md-toc @@ -2,7 +2,7 @@ import argparse import sys - +import re def get_opts(): @@ -30,11 +30,13 @@ def main(): bullet = "-" counters = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0] lastlev = 0 + re_anchor = re.compile('[^0-9a-z-]') for row in fp: if row.startswith("#"): headers, title = row.strip().split(" ", 1) if opts.l: - title = "[{}](#{})".format(title, title.lower().replace(" ", "-")) + anchor = re_anchor.sub('' , title.lower().replace(" ", "-")) + title = "[{}](#{})".format(title, anchor) pad = headers.count("#") - 1 if pad < lastlev: counters = [x if i <= pad else 0 for i, x in enumerate(counters)]