88
99import re
1010from pathlib import Path
11+
1112MULTIMEDIA_EXTENSIONS = (
12- ".png" , ".jpg" , ".jpeg" , ".gif" , ".webp" , ".svg" , # Images
13- ".mp4" , ".avi" , ".mov" , ".mkv" , # Vidéos
14- ".mp3" , ".wav" , ".flac" , # Audio
15- ".pdf" , ".doc" , ".docx" , ".xls" , ".xlsx" , ".ppt" , ".pptx" , # Documents
13+ ".png" ,
14+ ".jpg" ,
15+ ".jpeg" ,
16+ ".gif" ,
17+ ".webp" ,
18+ ".svg" , # Images
19+ ".mp4" ,
20+ ".avi" ,
21+ ".mov" ,
22+ ".mkv" , # Vidéos
23+ ".mp3" ,
24+ ".wav" ,
25+ ".flac" , # Audio
26+ ".pdf" ,
27+ ".doc" ,
28+ ".docx" ,
29+ ".xls" ,
30+ ".xlsx" ,
31+ ".ppt" ,
32+ ".pptx" , # Documents
1633)
1734
35+
1836def mini_ez_links (link , base , end , url_whitespace , url_case ):
1937 base_data , url_blog , md_link_path = base
2038 url_blog_path = [x for x in url_blog .split ("/" ) if x ]
2139 url_blog_path = url_blog_path [- 1 ]
2240
2341 # Vérifie si c'est une image (ne pas ajouter notfound:: pour les images)
24- if any (link [2 ].lower ().endswith (ext ) for ext in MULTIMEDIA_EXTENSIONS ) :
42+ if any (link [2 ].lower ().endswith (ext ) for ext in MULTIMEDIA_EXTENSIONS ):
2543 internal_link = Path (md_link_path , link [2 ]).resolve ()
26- if internal_link .is_file () :
44+ if internal_link .is_file ():
2745 return create_url (internal_link , link [2 ], base , url_blog_path , True )
28- else :
46+ else :
2947 # Retourne simplement le chemin brut pour les fichiers multimédias non trouvés
3048 return link [2 ]
3149
@@ -37,6 +55,7 @@ def mini_ez_links(link, base, end, url_whitespace, url_case):
3755 # Si le fichier Markdown n'est pas trouvé, marque avec "notfound::"
3856 return f"notfound::{ create_url (internal_link , link [2 ], base , url_blog_path , True )} "
3957
58+
4059def convert_links_if_markdown (quote_str , base ):
4160 """Convert links if the file is a markdown file."""
4261 # Search for links
@@ -55,40 +74,44 @@ def convert_links_if_markdown(quote_str, base):
5574 return quote_str
5675
5776
58- def create_url (internal_link , link , base , url_blog_path , wikilinks = False ) :
77+ def create_url (internal_link , link , base , url_blog_path , wikilinks = False ):
5978 base , url_blog , md_link_path = base
6079 internal_path = Path (internal_link )
6180 # Vérifie si le lien est une image ou un fichier multimédia
62- if any (link .lower ().endswith (ext ) for ext in MULTIMEDIA_EXTENSIONS ) :
81+ if any (link .lower ().endswith (ext ) for ext in MULTIMEDIA_EXTENSIONS ):
6382 # Normalise le chemin des images sans les transformer en URLs Markdown
6483 image_path = Path (url_blog ) / link .replace ("\\ " , "/" )
6584 final_url = str (image_path ).replace ("\\ " , "/" )
6685 return final_url
6786
6887 # Vérifie si le chemin est un fichier Markdown valide
69- if internal_path .is_file () :
88+ if internal_path .is_file ():
7089 internal_link = str (internal_path ).replace (str (base ), "" )
71- else :
90+ else :
7291 resolved = search_file_in_documentation (link , md_link_path .parent , base )
7392
7493 # Fallback explicite pour `/index.md` via dossier parent
75- if resolved == 0 and not link .endswith ("index.md" ) :
94+ if resolved == 0 and not link .endswith ("index.md" ):
7695 folder_name = os .path .splitext (link )[0 ]
77- resolved = search_file_in_documentation (f"{ folder_name } /index.md" , md_link_path .parent , base )
78-
79- if resolved == 0 :
80- internal_link = str (link ).replace ("../" , "" ).replace ("./" , "" ).replace (".md" , "" )
81- else :
96+ resolved = search_file_in_documentation (
97+ f"{ folder_name } /index.md" , md_link_path .parent , base
98+ )
99+
100+ if resolved == 0 :
101+ internal_link = (
102+ str (link ).replace ("../" , "" ).replace ("./" , "" ).replace (".md" , "" )
103+ )
104+ else :
82105 internal_link = str (resolved ).replace (str (base ), "" )
83106
84107 # Normalisation du chemin final pour les fichiers Markdown
85108 filepath = internal_link .replace ("\\ " , "/" ).replace (".md" , "" )
86109 url = re .sub (r"/+$" , "" , str (url_blog )) + "/" + quote (filepath )
87110
88111 # Ajout du protocole si manquant
89- if not url .startswith ("http" ) :
112+ if not url .startswith ("http" ):
90113 url = "https://" + url
91- if not url .endswith ("/" ) and not re .search (r"\\.(.*)$" , url ) :
114+ if not url .endswith ("/" ) and not re .search (r"\\.(.*)$" , url ):
92115 url += "/"
93116
94117 return url
0 commit comments