From 5d1492b9130ef665a86705ffe0c0a2e2dd8a0cbf Mon Sep 17 00:00:00 2001 From: Miguel Angel Reina Ortega <miguelangel.reinaortega@etsi.org> Date: Thu, 24 Oct 2024 16:17:53 +0000 Subject: [PATCH] Debugging links --- generateChangemarks/generateTOC.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/generateChangemarks/generateTOC.py b/generateChangemarks/generateTOC.py index f49915f..54e67fc 100644 --- a/generateChangemarks/generateTOC.py +++ b/generateChangemarks/generateTOC.py @@ -64,7 +64,7 @@ def processDocument(args:argparse.Namespace) -> None: # Read the document headers:list[Tuple[str, int]] = [] # Note: We use utf-8 and replace errors to avoid problems with special or unknown characters. - with open(args.document, 'r', encoding='utf-8', errors='replace') as f: + with open(args.document, 'w', encoding='utf-8', errors='replace') as f: document = f.readlines() for line in document: _l = line.strip() @@ -78,7 +78,10 @@ def processDocument(args:argparse.Namespace) -> None: # Skip the Contents headline if necessary if (headline := _l.lstrip('#').strip()) == 'Contents' and not args.contents: continue - headers.append((headline, level)) + headers.append((headline, level, prepareTOClink(h[0]))) + f.write(line+f'\{#{h[2]}\}') + continue + f.write(line) # Prepare and Print the table of contents toc = '# Contents\n\n' @@ -91,8 +94,9 @@ def processDocument(args:argparse.Namespace) -> None: heading_link=prepareTOClink(_h) print(_h) print(heading_link) + print(h[2]) # toc += ' ' * (h[1] * args.indent) + f'[{h[0]}](#{prepareTOClink(h[0])}) \n' - toc += ' ' * (h[1] * args.indent) + f'[{_h}](#{heading_link}) \n' + toc += ' ' * (h[1] * args.indent) + f'[{_h}](#{h[2]}) \n' toc = re.sub('<[^<]+?>', '', toc) toc += '\n' -- GitLab