Skip to content

Commit da48cd8

Browse files
committed
style(lint): ruff
1 parent b93f8c9 commit da48cd8

File tree

5 files changed

+61
-30
lines changed

5 files changed

+61
-30
lines changed

mkdocs_embed_file_plugins/plugin.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,19 @@
1313
import logging
1414

1515
from mkdocs_embed_file_plugins.src.links_correction import (
16-
MULTIMEDIA_EXTENSIONS, convert_links_if_markdown,
16+
MULTIMEDIA_EXTENSIONS,
17+
convert_links_if_markdown,
1718
mini_ez_links,
18-
)
19+
)
1920
from mkdocs_embed_file_plugins.src.search_quote import (
2021
search_file_in_documentation,
2122
search_in_file,
2223
)
23-
from mkdocs_embed_file_plugins.src.utils import add_not_found_class, create_link, strip_comments
24+
from mkdocs_embed_file_plugins.src.utils import (
25+
add_not_found_class,
26+
create_link,
27+
strip_comments,
28+
)
2429

2530

2631
def cite(

mkdocs_embed_file_plugins/src/links_correction.py

Lines changed: 42 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,42 @@
88

99
import re
1010
from pathlib import Path
11+
1112
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
1633
)
1734

35+
1836
def 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+
4059
def 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

mkdocs_embed_file_plugins/src/search_quote.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,9 @@ def search_in_file(citation_part: str, contents: str) -> str:
4545
return ""
4646

4747

48-
def search_file_in_documentation(link: Union[Path, str], config_dir: Path, base: Path) -> Union[Path, int]:
48+
def search_file_in_documentation(
49+
link: Union[Path, str], config_dir: Path, base: Path
50+
) -> Union[Path, int]:
4951
"""
5052
Recherche un fichier spécifique dans la documentation.
5153
"""

mkdocs_embed_file_plugins/src/utils.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import re
22
from bs4 import BeautifulSoup
33

4+
45
def strip_comments(markdown):
56
file_content = markdown.split("\n")
67
markdown = ""
@@ -22,21 +23,21 @@ def create_link(link):
2223
return link + ".md"
2324

2425

25-
def add_not_found_class(html) :
26+
def add_not_found_class(html):
2627
soup = BeautifulSoup(html, "html.parser")
2728

28-
for a_tag in soup.find_all("a") :
29+
for a_tag in soup.find_all("a"):
2930
href = a_tag.get("href", "")
30-
if href.startswith("notfound::") :
31+
if href.startswith("notfound::"):
3132
clean_href = href.replace("notfound::", "")
3233
a_tag["href"] = clean_href
3334
a_tag["class"] = a_tag.get("class", []) + ["ezlinks_not_found"]
3435
new_tag = soup.new_tag("span")
3536
new_tag.string = a_tag.string
36-
for attr in a_tag.attrs :
37-
if attr != "href" :
37+
for attr in a_tag.attrs:
38+
if attr != "href":
3839
new_tag[attr] = a_tag[attr]
3940
new_tag["src"] = clean_href
4041
a_tag.replaceWith(new_tag)
4142

42-
return str(soup)
43+
return str(soup)

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ python-frontmatter
66
mdx-wikilink-plus
77
mkdocs-callouts
88
mkdocs-custom-tags-attributes
9-
pymdown-extensions
9+
pymdown-extensions

0 commit comments

Comments
 (0)