# coding: utf8 """Extrait une strophe du fichier info.md et l'affiche dans firefox Usage: python3 md2html.py nom_fichier.md [numéro_strophe] La strophe à afficher est encadrée par un commentaire spécial dans info.md : strophe L'appel sans numéro de strophe donne la table des matières . Auteur: B. Cordeau sur une idée de L. Pointal """ # Import ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ import sys import re from pathlib import Path from markdown import markdown import webbrowser # Programme principal ========================================================= fichier_md = sys.argv[1] motif = 'toc' if len(sys.argv) == 2 else sys.argv[2] motif_deb = r"" motif_fin = r"" deb = re.compile(motif_deb) fin = re.compile(motif_fin) infos = "" # chaîne résultat dedans = False with open(fichier_md, encoding='utf-8') as f: for line in f: if fin.match(line): break if dedans: infos += line if deb.match(line): dedans = True path = Path(sys.argv[1]) fichier = path.name.split(".")[0] titre = "TOC" if len(sys.argv) == 2 else fichier + " n° " + sys.argv[2] entete = """\