Conversion des URLs http(s) en markdown

This commit is contained in:
Emmanuel Viennet 2021-04-11 18:32:13 +02:00
parent 3c2ffc1867
commit 32b8a1bb9b
2 changed files with 10 additions and 0 deletions

View File

@ -190,6 +190,7 @@ for sem in ressources:
output = r.to_yaml()
if WITH_EXPORT and r.code:
fichier = f"{args.outdir}/{r.code}.yml"
__LOGGER.warning(f"writing '{fichier}")
with open(fichier, "w", encoding="utf8") as fid:
fid.write(output)

View File

@ -150,6 +150,14 @@ class Docx():
output = "\n".join(lignes_finales)
# Remplace http(s) URLs pour markdown
output = re.sub( r"(http(s)?://[\w\d:#@%/;~_?\+-=\\\.&]*)", r"[\1](\1)", output )
# Remplace les guillemets
# ne traite pas tous les cas, mais arrange la majorité
output = re.sub( r"\"(.*?)\"", r"«\", output, flags=re.DOTALL)
# On utilise les guillements français (ajout automatique des bons espaces)
output = output.replace("«", r"\og ").replace("»", r"\fg{}")
return output
class RessourceDocx(Docx):
@ -284,6 +292,7 @@ class RessourceDocx(Docx):
# Remet en forme le descriptif
self.split_description()
self.nettoie_contenu()
print(f"{self.code} {self.semestre}")
def to_yaml(self):
"""Exporte la ressource en yaml"""