From 4fe991d622924cdb9da27b8a77670ea240673125 Mon Sep 17 00:00:00 2001 From: 84524221613d58c87acfb7d2d0777c72 <84524221613d58c87acfb7d2d0777c72@app-learninglab.inria.fr> Date: Sat, 28 Mar 2020 12:36:29 +0000 Subject: [PATCH] Upload New File --- journal/md2html.py | 74 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 journal/md2html.py diff --git a/journal/md2html.py b/journal/md2html.py new file mode 100644 index 0000000..ca43013 --- /dev/null +++ b/journal/md2html.py @@ -0,0 +1,74 @@ +# 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 = """\ + + +
+ +