Created
January 12, 2022 18:47
-
-
Save RonenNess/313348f2c807536961bc06c21aeb07dd to your computer and use it in GitHub Desktop.
A very basic python script to generate ToC from markdown file. Only works for simple cases and 2 level of titles (# and ##).
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def generate_link(title): | |
return "[" + title + "](#" + title.lower().replace(' ', '-') + ")" | |
print ("# Table Of Content") | |
with open("README.md", 'r') as infile: | |
for line in infile: | |
line = line.strip() | |
if line.startswith('## '): | |
print (" - " + generate_link(line[3:])) | |
elif line.startswith('# '): | |
print ("- " + generate_link(line[2:])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment