8
8
9
9
import re
10
10
from pathlib import Path
11
+
11
12
MULTIMEDIA_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
16
33
)
17
34
35
+
18
36
def mini_ez_links (link , base , end , url_whitespace , url_case ):
19
37
base_data , url_blog , md_link_path = base
20
38
url_blog_path = [x for x in url_blog .split ("/" ) if x ]
21
39
url_blog_path = url_blog_path [- 1 ]
22
40
23
41
# 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 ):
25
43
internal_link = Path (md_link_path , link [2 ]).resolve ()
26
- if internal_link .is_file () :
44
+ if internal_link .is_file ():
27
45
return create_url (internal_link , link [2 ], base , url_blog_path , True )
28
- else :
46
+ else :
29
47
# Retourne simplement le chemin brut pour les fichiers multimédias non trouvés
30
48
return link [2 ]
31
49
@@ -37,6 +55,7 @@ def mini_ez_links(link, base, end, url_whitespace, url_case):
37
55
# Si le fichier Markdown n'est pas trouvé, marque avec "notfound::"
38
56
return f"notfound::{ create_url (internal_link , link [2 ], base , url_blog_path , True )} "
39
57
58
+
40
59
def convert_links_if_markdown (quote_str , base ):
41
60
"""Convert links if the file is a markdown file."""
42
61
# Search for links
@@ -55,40 +74,44 @@ def convert_links_if_markdown(quote_str, base):
55
74
return quote_str
56
75
57
76
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 ):
59
78
base , url_blog , md_link_path = base
60
79
internal_path = Path (internal_link )
61
80
# 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 ):
63
82
# Normalise le chemin des images sans les transformer en URLs Markdown
64
83
image_path = Path (url_blog ) / link .replace ("\\ " , "/" )
65
84
final_url = str (image_path ).replace ("\\ " , "/" )
66
85
return final_url
67
86
68
87
# Vérifie si le chemin est un fichier Markdown valide
69
- if internal_path .is_file () :
88
+ if internal_path .is_file ():
70
89
internal_link = str (internal_path ).replace (str (base ), "" )
71
- else :
90
+ else :
72
91
resolved = search_file_in_documentation (link , md_link_path .parent , base )
73
92
74
93
# 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" ):
76
95
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 :
82
105
internal_link = str (resolved ).replace (str (base ), "" )
83
106
84
107
# Normalisation du chemin final pour les fichiers Markdown
85
108
filepath = internal_link .replace ("\\ " , "/" ).replace (".md" , "" )
86
109
url = re .sub (r"/+$" , "" , str (url_blog )) + "/" + quote (filepath )
87
110
88
111
# Ajout du protocole si manquant
89
- if not url .startswith ("http" ) :
112
+ if not url .startswith ("http" ):
90
113
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 ):
92
115
url += "/"
93
116
94
117
return url
0 commit comments