push
This commit is contained in:
commit
62fef0ec81
17
README.md
Normal file
17
README.md
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
# PYTHON MARKDOWN TO PDF
|
||||||
|
|
||||||
|
## PRE-REQUIS
|
||||||
|
|
||||||
|
- Python 3.10
|
||||||
|
|
||||||
|
## UTILISATION
|
||||||
|
|
||||||
|
```bash
|
||||||
|
python3.10 md-to-pdf.py
|
||||||
|
```
|
||||||
|
|
||||||
|
> Choisir dans le menu pour convertir un fichier seulement ou tous les fichiers contenus dans le répertoire courant (qui sont en .md)
|
||||||
|
|
||||||
|
## TO DO
|
||||||
|
|
||||||
|
- [ ] Dossier input et dossier output pour les batchs
|
42
md-to-pdf.py
Normal file
42
md-to-pdf.py
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
import md2pdf, os
|
||||||
|
|
||||||
|
def convert():
|
||||||
|
|
||||||
|
markdown = input("Saisir le nom du fichier markdown à convertir (sans l'extension .md): ")
|
||||||
|
pdf = input("Saisir le nom du fichier de sorti (sans l'extension .pdf): ")
|
||||||
|
|
||||||
|
try:
|
||||||
|
md2pdf.md2pdf(pdf + ".pdf", "", "./" + markdown + ".md" , "", "")
|
||||||
|
except:
|
||||||
|
print("Erreur sur le nom de fichier saisi...")
|
||||||
|
|
||||||
|
print("conversion réussie")
|
||||||
|
|
||||||
|
def convert_all():
|
||||||
|
|
||||||
|
try:
|
||||||
|
files = os.listdir("./")
|
||||||
|
for file in files:
|
||||||
|
if file.endswith(".md"):
|
||||||
|
pdf = str(file.split(".md")[0])
|
||||||
|
markdown = file
|
||||||
|
md2pdf.md2pdf(pdf + ".pdf", "", "./" + markdown, "", "")
|
||||||
|
except:
|
||||||
|
print("Un fichier a posé problème: " + file)
|
||||||
|
continue
|
||||||
|
|
||||||
|
print("conversion réussie")
|
||||||
|
|
||||||
|
def main():
|
||||||
|
|
||||||
|
choix = input("Que voulez-vous faire? \n 1) convertir un fichier markdown ?\n 2) convertir plusieurs fichiers markdown ?")
|
||||||
|
|
||||||
|
match choix:
|
||||||
|
case "1":
|
||||||
|
convert()
|
||||||
|
case "2":
|
||||||
|
convert_all()
|
||||||
|
case _:
|
||||||
|
print("choix incorrect, veuillez saisir 1 ou 2")
|
||||||
|
|
||||||
|
main()
|
1
requirements.txt
Normal file
1
requirements.txt
Normal file
@ -0,0 +1 @@
|
|||||||
|
md2pdf
|
Loading…
x
Reference in New Issue
Block a user