import os import re import markdown import yaml import shutil import subprocess import unidecode htmltemplate = """ {title} {body}""" settingsfile = "../textes/settings.yml" def apply_html_template(body, title): return htmltemplate.format(body=body, title=title) def md2html(md): return markdown.markdown(md, extensions=['extra', 'nl2br']) def md2gmi(md): gmi = md gmi = re.sub(r'\[(.*)\]\((.*)\)', r'\n=> \2 \1', gmi) gmi = gmi.replace('* * *', '---') gmi = re.sub(r'^\*(.*)\*$', r'> \1', gmi, flags=re.MULTILINE) gmi = re.sub(r'\*(.*)\*', r'\1', gmi) return gmi with open(settingsfile, "r", encoding="utf-8") as file: index = yaml.safe_load(file) htmlhome = "

{}

{}

".format(index['title'], index['description']) gmihome = "# {}\n{}".format(index['title'], index['description']) os.makedirs("out/html", exist_ok=True) os.makedirs("out/gmi", exist_ok=True) for folderinfo in index['folders']: sectiontitle = folderinfo['title'] htmlhome += "\n

{}

\n" with open("out/html/index.html", "w", encoding="utf-8") as htmlindex: htmlindex.write(apply_html_template(htmlhome, index['title'])) with open("out/gmi/index.gmi", "w", encoding="utf-8") as gmiindex: gmiindex.write(gmihome)