Skip to content
Snippets Groups Projects
Commit 5d1492b9 authored by Miguel Angel Reina Ortega's avatar Miguel Angel Reina Ortega
Browse files

Debugging links

parent 3df93b38
No related branches found
No related tags found
No related merge requests found
Pipeline #1389 passed
...@@ -64,7 +64,7 @@ def processDocument(args:argparse.Namespace) -> None: ...@@ -64,7 +64,7 @@ def processDocument(args:argparse.Namespace) -> None:
# Read the document # Read the document
headers:list[Tuple[str, int]] = [] headers:list[Tuple[str, int]] = []
# Note: We use utf-8 and replace errors to avoid problems with special or unknown characters. # 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() document = f.readlines()
for line in document: for line in document:
_l = line.strip() _l = line.strip()
...@@ -78,7 +78,10 @@ def processDocument(args:argparse.Namespace) -> None: ...@@ -78,7 +78,10 @@ def processDocument(args:argparse.Namespace) -> None:
# Skip the Contents headline if necessary # Skip the Contents headline if necessary
if (headline := _l.lstrip('#').strip()) == 'Contents' and not args.contents: if (headline := _l.lstrip('#').strip()) == 'Contents' and not args.contents:
continue 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 # Prepare and Print the table of contents
toc = '# Contents\n\n' toc = '# Contents\n\n'
...@@ -91,8 +94,9 @@ def processDocument(args:argparse.Namespace) -> None: ...@@ -91,8 +94,9 @@ def processDocument(args:argparse.Namespace) -> None:
heading_link=prepareTOClink(_h) heading_link=prepareTOClink(_h)
print(_h) print(_h)
print(heading_link) 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[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 = re.sub('<[^<]+?>', '', toc)
toc += '\n' toc += '\n'
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment